master/fsm_slave.c
author Florian Pose <fp@igh-essen.com>
Wed, 25 Jul 2007 07:46:09 +0000
changeset 669 884a5b5b0163
parent 637 d5d04c868e0e
child 696 24fac09b5b26
permissions -rw-r--r--
Updated TODO and NEWS.
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
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    36
   EtherCAT slave state machines.
238
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 "master.h"
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    43
#include "mailbox.h"
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    44
#include "fsm_slave.h"
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
    45
#include "fsm_mapping.h"
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    46
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    47
/*****************************************************************************/
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    48
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    49
void ec_fsm_slave_scan_state_start(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    50
void ec_fsm_slave_scan_state_address(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    51
void ec_fsm_slave_scan_state_state(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    52
void ec_fsm_slave_scan_state_base(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    53
void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    54
void ec_fsm_slave_scan_state_eeprom_size(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    55
void ec_fsm_slave_scan_state_eeprom_data(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    56
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    57
void ec_fsm_slave_conf_state_start(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    58
void ec_fsm_slave_conf_state_init(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    59
void ec_fsm_slave_conf_state_clear_fmmus(ec_fsm_slave_t *);
623
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
    60
void ec_fsm_slave_conf_state_mbox_sync(ec_fsm_slave_t *);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    61
void ec_fsm_slave_conf_state_preop(ec_fsm_slave_t *);
623
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
    62
void ec_fsm_slave_conf_state_pdo_sync(ec_fsm_slave_t *);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    63
void ec_fsm_slave_conf_state_fmmu(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    64
void ec_fsm_slave_conf_state_sdoconf(ec_fsm_slave_t *);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
    65
void ec_fsm_slave_conf_state_mapconf(ec_fsm_slave_t *);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    66
void ec_fsm_slave_conf_state_saveop(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    67
void ec_fsm_slave_conf_state_op(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    68
623
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
    69
void ec_fsm_slave_conf_enter_mbox_sync(ec_fsm_slave_t *);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    70
void ec_fsm_slave_conf_enter_preop(ec_fsm_slave_t *);
623
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
    71
void ec_fsm_slave_conf_enter_pdo_sync(ec_fsm_slave_t *);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    72
void ec_fsm_slave_conf_enter_fmmu(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    73
void ec_fsm_slave_conf_enter_sdoconf(ec_fsm_slave_t *);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
    74
void ec_fsm_slave_conf_enter_mapconf(ec_fsm_slave_t *);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    75
void ec_fsm_slave_conf_enter_saveop(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    76
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    77
void ec_fsm_slave_state_end(ec_fsm_slave_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    78
void ec_fsm_slave_state_error(ec_fsm_slave_t *);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    79
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    82
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    83
   Constructor.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    84
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    85
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    86
void ec_fsm_slave_init(ec_fsm_slave_t *fsm, /**< slave state machine */
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    87
        ec_datagram_t *datagram /**< datagram structure to use */
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    88
        )
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    89
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    90
    fsm->datagram = datagram;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    91
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    92
    // init sub state machines
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    93
    ec_fsm_sii_init(&fsm->fsm_sii, fsm->datagram);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    94
    ec_fsm_change_init(&fsm->fsm_change, fsm->datagram);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    95
    ec_fsm_coe_init(&fsm->fsm_coe, fsm->datagram);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
    96
    ec_fsm_mapping_init(&fsm->fsm_map, &fsm->fsm_coe);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   101
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   102
   Destructor.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   103
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   104
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   105
void ec_fsm_slave_clear(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   106
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   107
    // clear sub state machines
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   108
    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
   109
    ec_fsm_change_clear(&fsm->fsm_change);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   110
    ec_fsm_coe_clear(&fsm->fsm_coe);
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   111
    ec_fsm_mapping_clear(&fsm->fsm_map);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   112
}
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   113
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   114
/*****************************************************************************/
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   115
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   116
/**
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   117
 * Start slave scan state machine.
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   118
 */
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   119
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   120
void ec_fsm_slave_start_scan(ec_fsm_slave_t *fsm, /**< slave state machine */
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   121
        ec_slave_t *slave /**< slave to configure */
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   122
        )
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   123
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   124
    fsm->slave = slave;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   125
    fsm->state = ec_fsm_slave_scan_state_start;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   126
}
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   127
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   128
/*****************************************************************************/
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   129
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   130
/**
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   131
 * Start slave configuration state machine.
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   132
 */
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   133
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   134
void ec_fsm_slave_start_conf(ec_fsm_slave_t *fsm, /**< slave state machine */
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   135
        ec_slave_t *slave /**< slave to configure */
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   136
        )
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   137
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   138
    fsm->slave = slave;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   139
    fsm->state = ec_fsm_slave_conf_state_start;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   140
}
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   141
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   142
/*****************************************************************************/
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   143
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   144
/**
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   145
   \return false, if state machine has terminated
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   146
*/
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   147
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   148
int ec_fsm_slave_running(const ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   149
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   150
    return fsm->state != ec_fsm_slave_state_end
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   151
        && fsm->state != ec_fsm_slave_state_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
}
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
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   156
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   157
   Executes the current state of the state machine.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   158
   If the state machine's datagram is not sent or received yet, the execution
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   159
   of the state machine is delayed to the next cycle.
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   160
   \return false, if state machine has terminated
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   161
*/
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   162
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   163
int ec_fsm_slave_exec(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   164
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   165
    if (fsm->datagram->state == EC_DATAGRAM_SENT
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   166
        || fsm->datagram->state == EC_DATAGRAM_QUEUED) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   167
        // datagram was not sent or received yet.
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   168
        return ec_fsm_slave_running(fsm);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   169
    }
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   170
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   171
    fsm->state(fsm);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   172
    return ec_fsm_slave_running(fsm);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   173
}
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   174
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   175
/*****************************************************************************/
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   176
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   177
/**
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   178
   \return true, if the state machine terminated gracefully
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   179
*/
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   180
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   181
int ec_fsm_slave_success(const ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   182
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   183
    return fsm->state == ec_fsm_slave_state_end;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   184
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   185
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
/******************************************************************************
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   187
 *  slave scan state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   191
   Slave scan state: START.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
   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
   193
   slave, according to its ring position.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   196
void ec_fsm_slave_scan_state_start(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   197
{
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    // write station address
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   199
    ec_datagram_apwr(fsm->datagram, fsm->slave->ring_position, 0x0010, 2);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   200
    EC_WRITE_U16(fsm->datagram->data, fsm->slave->station_address);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   201
    fsm->retries = EC_FSM_RETRIES;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   202
    fsm->state = ec_fsm_slave_scan_state_address;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   203
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   204
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   205
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   206
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   207
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   208
   Slave scan state: ADDRESS.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   209
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   210
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   211
void ec_fsm_slave_scan_state_address(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   212
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   213
    ec_datagram_t *datagram = fsm->datagram;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   214
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   215
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   216
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   217
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   218
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   219
        fsm->state = ec_fsm_slave_state_error;
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   220
        EC_ERR("Failed to receive station address datagram for slave %i"
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   221
                " (datagram state %i)\n",
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   222
                fsm->slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   223
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   224
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   225
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   226
    if (datagram->working_counter != 1) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   227
        fsm->slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   228
        fsm->state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   229
        EC_ERR("Failed to write station address - slave %i did not respond.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
               fsm->slave->ring_position);
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   231
        return;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   232
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   233
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   234
    // Read AL state
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   235
    ec_datagram_nprd(datagram, fsm->slave->station_address, 0x0130, 2);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   236
    fsm->retries = EC_FSM_RETRIES;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   237
    fsm->state = ec_fsm_slave_scan_state_state;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   238
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   239
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   240
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   241
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   242
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   243
   Slave scan state: STATE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   244
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   245
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   246
void ec_fsm_slave_scan_state_state(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   247
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   248
    ec_datagram_t *datagram = fsm->datagram;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   249
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   250
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   251
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   252
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   253
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   254
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   255
        fsm->state = ec_fsm_slave_state_error;
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   256
        EC_ERR("Failed to receive AL state datagram from slave %i"
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   257
                " (datagram state %i).\n",
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   258
               fsm->slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   259
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   260
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   261
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   262
    if (datagram->working_counter != 1) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
   263
        fsm->slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   264
        fsm->state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   265
        EC_ERR("Failed to read AL state - slave %i did not respond.\n",
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   266
               fsm->slave->ring_position);
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   267
        return;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   268
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   269
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   270
    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
   271
    if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   272
        char state_str[EC_STATE_STRING_SIZE];
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   273
        ec_state_string(slave->current_state, state_str);
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   274
        EC_WARN("Slave %i has state error bit set (%s)!\n",
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   275
                slave->ring_position, state_str);
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   276
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   277
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
    // read base data
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   279
    ec_datagram_nprd(datagram, fsm->slave->station_address, 0x0000, 6);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   280
    fsm->retries = EC_FSM_RETRIES;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   281
    fsm->state = ec_fsm_slave_scan_state_base;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   282
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   283
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   284
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   285
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   286
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   287
   Slave scan state: BASE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   288
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   289
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   290
void ec_fsm_slave_scan_state_base(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   291
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   292
    ec_datagram_t *datagram = fsm->datagram;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   293
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   294
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   295
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   296
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   297
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   298
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   299
        fsm->state = ec_fsm_slave_state_error;
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   300
        EC_ERR("Failed to receive base data datagram for slave %i"
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   301
                " (datagram state %i).\n",
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   302
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   303
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   304
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   305
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   306
    if (datagram->working_counter != 1) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
   307
        fsm->slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   308
        fsm->state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   309
        EC_ERR("Failed to read base data - slave %i did not respond.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
               slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   314
    slave->base_type       = EC_READ_U8 (datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   315
    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
   316
    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
   317
    slave->base_fmmu_count = EC_READ_U8 (datagram->data + 4);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
    if (slave->base_fmmu_count > EC_MAX_FMMUS)
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
        slave->base_fmmu_count = EC_MAX_FMMUS;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
    // read data link status
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   323
    ec_datagram_nprd(datagram, slave->station_address, 0x0110, 2);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   324
    fsm->retries = EC_FSM_RETRIES;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   325
    fsm->state = ec_fsm_slave_scan_state_datalink;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   326
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   327
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   328
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   329
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   330
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   331
   Slave scan state: DATALINK.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   332
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   333
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   334
void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   335
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   336
    ec_datagram_t *datagram = fsm->datagram;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
    ec_slave_t *slave = fsm->slave;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
    uint16_t dl_status;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
    unsigned int i;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   341
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   342
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   343
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   344
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   345
        fsm->state = ec_fsm_slave_state_error;
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   346
        EC_ERR("Failed to receive DL status datagram from slave %i"
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   347
                " (datagram state %i).\n",
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   348
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   349
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   350
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   351
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   352
    if (datagram->working_counter != 1) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
   353
        fsm->slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   354
        fsm->state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   355
        EC_ERR("Failed to read DL status - slave %i did not respond.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
               slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   360
    dl_status = EC_READ_U16(datagram->data);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   361
    for (i = 0; i < 4; i++) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   362
        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
   363
        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
   364
        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
   365
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   367
    // 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
   368
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   369
    fsm->sii_offset = 0x0040; // first category header
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   370
    ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset, EC_FSM_SII_NODE);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   371
    fsm->state = ec_fsm_slave_scan_state_eeprom_size;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   372
    fsm->state(fsm); // execute state immediately
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   374
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   376
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   377
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   378
   Slave scan state: EEPROM SIZE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   379
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   380
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   381
void ec_fsm_slave_scan_state_eeprom_size(ec_fsm_slave_t *fsm /**< slave 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
   382
{
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   383
    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
   384
    uint16_t cat_type, cat_size;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   385
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   386
    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
   387
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   388
    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
   389
        fsm->slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   390
        fsm->state = ec_fsm_slave_state_error;
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   391
        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
   392
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   393
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   394
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   395
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   396
    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
   397
    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
   398
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   399
    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
   400
        fsm->sii_offset += cat_size + 2;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   401
        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
   402
                        EC_FSM_SII_NODE);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   403
        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
   404
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   405
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   406
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   407
    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
   408
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   409
    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
   410
        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
   411
                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
   412
        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
   413
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   414
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   415
    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
   416
          (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
   417
        fsm->slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   418
        fsm->state = ec_fsm_slave_state_error;
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   419
        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
   420
               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
   421
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   422
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   423
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   424
    // 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
   425
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   426
    fsm->state = ec_fsm_slave_scan_state_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
   427
    fsm->sii_offset = 0x0000;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   428
    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
   429
    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
   430
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   432
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   435
   Slave scan state: EEPROM DATA.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   436
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   437
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   438
void ec_fsm_slave_scan_state_eeprom_data(ec_fsm_slave_t *fsm /**< slave 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
   439
{
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   440
    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
   441
    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
   442
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   443
    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
   444
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   445
    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
   446
        fsm->slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   447
        fsm->state = ec_fsm_slave_state_error;
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   448
        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
   449
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   450
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   451
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   452
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   453
    // 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
   454
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   455
    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
   456
        memcpy(slave->eeprom_data + fsm->sii_offset * 2,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   457
               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
   458
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   459
    else { // copy the last word
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   460
        memcpy(slave->eeprom_data + fsm->sii_offset * 2,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   461
               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
   462
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   463
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   464
    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
   465
        // 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
   466
        fsm->sii_offset += 2;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   467
        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
   468
                        EC_FSM_SII_NODE);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   469
        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
   470
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   471
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   472
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   473
    // 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
   474
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   475
    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
   476
        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
   477
    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
   478
        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
   479
    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
   480
        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
   481
    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
   482
        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
   483
    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
   484
        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
   485
    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
   486
        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
   487
    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
   488
        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
   489
    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
   490
        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
   491
    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
   492
        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
   493
    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
   494
        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
   495
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   496
    // 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
   497
    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
   498
    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
   499
        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
   500
        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
   501
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   502
        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
   503
            case 0x000A:
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   504
                if (ec_slave_fetch_sii_strings(
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   505
                            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
   506
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   507
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   508
            case 0x001E:
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   509
                ec_slave_fetch_sii_general(
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   510
                        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
   511
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   512
            case 0x0028:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   513
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   514
            case 0x0029:
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   515
                if (ec_slave_fetch_sii_syncs(
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   516
                            slave, (uint8_t *) (cat_word + 2), cat_size))
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   517
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   518
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   519
            case 0x0032:
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   520
                if (ec_slave_fetch_sii_pdos(
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   521
                            slave, (uint8_t *) (cat_word + 2),
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   522
                            cat_size, EC_TX_PDO))
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   523
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   524
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   525
            case 0x0033:
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   526
                if (ec_slave_fetch_sii_pdos(
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   527
                            slave, (uint8_t *) (cat_word + 2),
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   528
                            cat_size, EC_RX_PDO))
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   529
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   530
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   531
            default:
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   532
                if (fsm->slave->master->debug_level)
461
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
   533
                    EC_WARN("Unknown category type 0x%04X in slave %i.\n",
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
   534
                            cat_type, slave->ring_position);
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   535
        }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   536
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   537
        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
   538
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
   539
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   540
    fsm->state = ec_fsm_slave_state_end;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   541
    return;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   542
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   543
end:
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   544
    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
   545
    fsm->slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   546
    fsm->state = ec_fsm_slave_state_error;
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
   547
}
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
   548
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
   549
/******************************************************************************
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   550
 *  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
   551
 *****************************************************************************/
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   552
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   553
/**
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   554
   Slave configuration state: START.
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   555
*/
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   556
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   557
void ec_fsm_slave_conf_state_start(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   558
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   559
    if (fsm->slave->master->debug_level) {
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   560
        EC_DBG("Configuring slave %i...\n", fsm->slave->ring_position);
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   561
    }
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   562
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   563
    ec_fsm_change_start(&fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_INIT);
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   564
    ec_fsm_change_exec(&fsm->fsm_change);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   565
    fsm->state = ec_fsm_slave_conf_state_init;
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   566
}
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   567
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   568
/*****************************************************************************/
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   569
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   570
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   571
   Slave configuration state: INIT.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   572
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   573
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   574
void ec_fsm_slave_conf_state_init(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   575
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   576
    ec_master_t *master = fsm->slave->master;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   577
    ec_slave_t *slave = fsm->slave;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   578
    ec_datagram_t *datagram = fsm->datagram;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   579
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   580
    if (ec_fsm_change_exec(&fsm->fsm_change)) return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   581
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   582
    if (!ec_fsm_change_success(&fsm->fsm_change)) {
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   583
        slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   584
        fsm->state = ec_fsm_slave_state_error;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   585
        return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   586
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   587
523
584a4f60b067 Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents: 522
diff changeset
   588
    slave->self_configured = 1;
584a4f60b067 Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents: 522
diff changeset
   589
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   590
    if (master->debug_level) {
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   591
        EC_DBG("Slave %i is now in INIT.\n", slave->ring_position);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   592
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   593
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   594
    // check and reset CRC fault counters
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   595
    //ec_slave_check_crc(slave);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   596
    // TODO: Implement state machine for CRC checking.
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   597
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   598
    if (!slave->base_fmmu_count) { // skip FMMU configuration
623
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   599
        ec_fsm_slave_conf_enter_mbox_sync(fsm);
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   600
        return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   601
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   602
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   603
    if (master->debug_level)
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   604
        EC_DBG("Clearing FMMU configurations of slave %i...\n",
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   605
               slave->ring_position);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   606
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   607
    // clear FMMU configurations
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   608
    ec_datagram_npwr(datagram, slave->station_address,
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   609
                     0x0600, EC_FMMU_SIZE * slave->base_fmmu_count);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   610
    memset(datagram->data, 0x00, EC_FMMU_SIZE * slave->base_fmmu_count);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   611
    fsm->retries = EC_FSM_RETRIES;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   612
    fsm->state = ec_fsm_slave_conf_state_clear_fmmus;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   613
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   614
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   615
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   616
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   617
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   618
   Slave configuration state: CLEAR FMMU.
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   619
*/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   620
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   621
void ec_fsm_slave_conf_state_clear_fmmus(ec_fsm_slave_t *fsm
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   622
                                        /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   623
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   624
    ec_datagram_t *datagram = fsm->datagram;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   625
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   626
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   627
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   628
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   629
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   630
        fsm->state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   631
        EC_ERR("Failed receive FMMU clearing datagram for slave %i.\n",
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   632
               fsm->slave->ring_position);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   633
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   634
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   635
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   636
    if (datagram->working_counter != 1) {
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   637
        fsm->slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   638
        fsm->state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   639
        EC_ERR("Failed to clear FMMUs - slave %i did not respond.\n",
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   640
               fsm->slave->ring_position);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   641
        return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   642
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   643
623
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   644
    ec_fsm_slave_conf_enter_mbox_sync(fsm);
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   645
}
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   646
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   647
/*****************************************************************************/
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   648
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   649
/**
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   650
 */
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   651
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   652
void ec_fsm_slave_conf_enter_mbox_sync(
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   653
        ec_fsm_slave_t *fsm /**< slave state machine */
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   654
        )
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   655
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   656
    ec_master_t *master = fsm->slave->master;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   657
    ec_slave_t *slave = fsm->slave;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   658
    ec_datagram_t *datagram = fsm->datagram;
618
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   659
    unsigned int i;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   660
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   661
    // 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
   662
    if (slave->current_state == slave->requested_state) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   663
        fsm->state = ec_fsm_slave_state_end; // successful
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   664
        if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   665
            EC_DBG("Finished configuration of slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   666
                   slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   667
        }
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   668
        return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   669
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   670
618
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   671
    if (!slave->sii_mailbox_protocols || slave->sii_sync_count < 2) {
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   672
        // no mailbox sync managers to be configured
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   673
        ec_fsm_slave_conf_enter_preop(fsm);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   674
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   675
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   676
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   677
    if (master->debug_level) {
618
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   678
        EC_DBG("Configuring mailbox sync managers of slave %i.\n",
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   679
               slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   680
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   681
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   682
    // configure sync managers
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   683
    ec_datagram_npwr(datagram, slave->station_address, 0x0800,
618
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   684
                     EC_SYNC_SIZE * slave->sii_sync_count);
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   685
    memset(datagram->data, 0x00, EC_SYNC_SIZE * slave->sii_sync_count);
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   686
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   687
    for (i = 0; i < 2; i++) {
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   688
        ec_sync_config(&slave->sii_syncs[i],
618
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   689
                datagram->data + EC_SYNC_SIZE * i);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   690
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   691
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   692
    fsm->retries = EC_FSM_RETRIES;
623
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   693
    fsm->state = ec_fsm_slave_conf_state_mbox_sync;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   694
}
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   695
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   696
/*****************************************************************************/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   697
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   698
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   699
   Slave configuration state: SYNC.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   700
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   701
623
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   702
void ec_fsm_slave_conf_state_mbox_sync(ec_fsm_slave_t *fsm /**< slave state machine */)
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   703
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   704
    ec_datagram_t *datagram = fsm->datagram;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   705
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   706
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   707
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   708
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   709
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   710
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   711
        fsm->state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   712
        EC_ERR("Failed to receive sync manager configuration datagram for"
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   713
               " slave %i (datagram state %i).\n",
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   714
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   715
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   716
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   717
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   718
    if (datagram->working_counter != 1) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   719
        slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   720
        fsm->state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   721
        EC_ERR("Failed to set sync managers - slave %i did not respond.\n",
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   722
               slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   723
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   724
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   725
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   726
    ec_fsm_slave_conf_enter_preop(fsm);
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   727
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   728
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   729
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   730
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   731
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   732
 */
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   733
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   734
void ec_fsm_slave_conf_enter_preop(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   735
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   736
    fsm->state = ec_fsm_slave_conf_state_preop;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   737
    ec_fsm_change_start(&fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_PREOP);
434
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   738
    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
   739
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   740
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   741
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   742
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   743
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   744
   Slave configuration state: PREOP.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   745
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   746
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   747
void ec_fsm_slave_conf_state_preop(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   748
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   749
    ec_slave_t *slave = fsm->slave;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   750
    ec_master_t *master = fsm->slave->master;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   751
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   752
    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
   753
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   754
    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
   755
        slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   756
        fsm->state = ec_fsm_slave_state_error;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   757
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   758
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   759
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   760
    // slave is now in PREOP
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   761
    slave->jiffies_preop = fsm->datagram->jiffies_received;
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   762
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   763
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   764
        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
   765
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   766
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   767
    if (slave->current_state == slave->requested_state) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   768
        fsm->state = ec_fsm_slave_state_end; // successful
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   769
        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
   770
            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
   771
                   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
   772
        }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   773
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   774
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   775
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   776
    ec_fsm_slave_conf_enter_sdoconf(fsm);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   777
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   778
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   779
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   780
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   781
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   782
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   783
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   784
void ec_fsm_slave_conf_enter_sdoconf(ec_fsm_slave_t *fsm /**< slave state machine */)
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   785
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   786
    ec_slave_t *slave = fsm->slave;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   787
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   788
    // No CoE configuration to be applied?
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   789
    if (list_empty(&slave->sdo_confs)) { // skip SDO configuration
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   790
        ec_fsm_slave_conf_enter_mapconf(fsm);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   791
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   792
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   793
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   794
    // start SDO configuration
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   795
    fsm->state = ec_fsm_slave_conf_state_sdoconf;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   796
    fsm->sdodata = list_entry(fsm->slave->sdo_confs.next, ec_sdo_data_t, list);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   797
    ec_fsm_coe_download(&fsm->fsm_coe, fsm->slave, fsm->sdodata);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   798
    ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   799
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   800
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   801
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   802
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   803
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   804
   Slave configuration state: SDOCONF.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   805
*/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   806
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   807
void ec_fsm_slave_conf_state_sdoconf(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   808
        ec_fsm_slave_t *fsm /**< slave state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   809
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   810
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   811
    if (ec_fsm_coe_exec(&fsm->fsm_coe)) return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   812
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   813
    if (!ec_fsm_coe_success(&fsm->fsm_coe)) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   814
        EC_ERR("SDO configuration failed for slave %u.\n",
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   815
                fsm->slave->ring_position);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   816
        fsm->slave->error_flag = 1;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   817
        fsm->state = ec_fsm_slave_state_error;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   818
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   819
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   820
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   821
    // Another SDO to configure?
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   822
    if (fsm->sdodata->list.next != &fsm->slave->sdo_confs) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   823
        fsm->sdodata = list_entry(fsm->sdodata->list.next,
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   824
                                  ec_sdo_data_t, list);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   825
        ec_fsm_coe_download(&fsm->fsm_coe, fsm->slave, fsm->sdodata);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   826
        ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   827
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   828
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   829
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   830
    // All SDOs are now configured.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   831
    ec_fsm_slave_conf_enter_mapconf(fsm);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   832
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   833
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   834
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   835
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   836
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   837
 */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   838
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   839
void ec_fsm_slave_conf_enter_mapconf(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   840
        ec_fsm_slave_t *fsm /**< slave state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   841
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   842
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   843
    ec_slave_t *slave = fsm->slave;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   844
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   845
    if (!(slave->sii_mailbox_protocols & EC_MBOX_COE)) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   846
        // Slave does not support CoE: no configuration of PDO mapping.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   847
        ec_fsm_slave_conf_enter_pdo_sync(fsm);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   848
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   849
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   850
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   851
    // start configuring PDO mapping
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   852
    fsm->state = ec_fsm_slave_conf_state_mapconf;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   853
    ec_fsm_mapping_start(&fsm->fsm_map, fsm->slave);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   854
    ec_fsm_mapping_exec(&fsm->fsm_map); // execute immediately
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   855
}
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   856
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   857
/*****************************************************************************/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   858
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   859
/**
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   860
   Slave configuration state: MAPCONF.
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   861
*/
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   862
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   863
void ec_fsm_slave_conf_state_mapconf(
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   864
        ec_fsm_slave_t *fsm /**< slave state machine */
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   865
        )
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   866
{
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   867
    if (ec_fsm_mapping_exec(&fsm->fsm_map)) return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   868
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   869
    if (!ec_fsm_mapping_success(&fsm->fsm_map)) {
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   870
        EC_ERR("PDO mapping configuration failed for slave %u.\n",
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   871
                fsm->slave->ring_position);
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   872
        fsm->slave->error_flag = 1;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   873
        fsm->state = ec_fsm_slave_state_error;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   874
        return;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   875
    }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   876
623
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   877
    ec_fsm_slave_conf_enter_pdo_sync(fsm);
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   878
}
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   879
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   880
/*****************************************************************************/
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   881
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   882
/**
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   883
 */
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   884
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   885
void ec_fsm_slave_conf_enter_pdo_sync(
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   886
        ec_fsm_slave_t *fsm /**< slave state machine */
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   887
        )
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   888
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   889
    ec_slave_t *slave = fsm->slave;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   890
    ec_datagram_t *datagram = fsm->datagram;
618
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   891
    unsigned int i;
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   892
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   893
    if (!slave->sii_sync_count) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   894
        ec_fsm_slave_conf_enter_fmmu(fsm);
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   895
        return;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   896
    }
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   897
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   898
    // configure sync managers for process data
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   899
    ec_datagram_npwr(datagram, slave->station_address, 0x0800,
618
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   900
                     EC_SYNC_SIZE * slave->sii_sync_count);
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   901
    memset(datagram->data, 0x00, EC_SYNC_SIZE * slave->sii_sync_count);
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   902
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   903
    for (i = 0; i < slave->sii_sync_count; i++) {
628
e94a16bc52ce Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents: 623
diff changeset
   904
        ec_sync_config(&slave->sii_syncs[i],
618
e4b89c862c43 SII sync managers as array instead of list, removed sync manager
Florian Pose <fp@igh-essen.com>
parents: 615
diff changeset
   905
                datagram->data + EC_SYNC_SIZE * i);
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   906
    }
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   907
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   908
    fsm->retries = EC_FSM_RETRIES;
623
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   909
    fsm->state = ec_fsm_slave_conf_state_pdo_sync;
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   910
}
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   911
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   912
/*****************************************************************************/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   913
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   914
/**
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   915
 */
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   916
623
4d64368f3a1e Renamed slave configuration states "sync" to "mbox_sync" and "sync2" to
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   917
void ec_fsm_slave_conf_state_pdo_sync(ec_fsm_slave_t *fsm /**< slave state machine */)
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   918
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   919
    ec_datagram_t *datagram = fsm->datagram;
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   920
    ec_slave_t *slave = fsm->slave;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   921
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   922
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   923
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   924
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   925
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   926
        fsm->state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   927
        EC_ERR("Failed to receive process data sync manager configuration"
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   928
               " datagram for slave %i (datagram state %i).\n",
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   929
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   930
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   931
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   932
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   933
    if (datagram->working_counter != 1) {
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   934
        slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   935
        fsm->state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   936
        EC_ERR("Failed to set process data sync managers - slave %i did not"
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   937
               " respond.\n", slave->ring_position);
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   938
        return;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   939
    }
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   940
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   941
    ec_fsm_slave_conf_enter_fmmu(fsm);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   942
}
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   943
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   944
/*****************************************************************************/
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   945
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   946
/**
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   947
*/
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   948
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   949
void ec_fsm_slave_conf_enter_fmmu(ec_fsm_slave_t *fsm /**< slave state machine */)
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   950
{
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   951
    ec_slave_t *slave = fsm->slave;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   952
    ec_datagram_t *datagram = fsm->datagram;
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   953
    unsigned int j;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
   954
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   955
    if (!slave->base_fmmu_count) { // skip FMMU configuration
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 630
diff changeset
   956
        ec_fsm_slave_conf_enter_saveop(fsm);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   957
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   958
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   959
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   960
    // configure FMMUs
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   961
    ec_datagram_npwr(datagram, slave->station_address,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   962
                     0x0600, EC_FMMU_SIZE * slave->base_fmmu_count);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   963
    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
   964
    for (j = 0; j < slave->fmmu_count; j++) {
630
1b755b7342eb Layed out FMMU structure and methods to own files.
Florian Pose <fp@igh-essen.com>
parents: 628
diff changeset
   965
        ec_fmmu_config(&slave->fmmus[j], datagram->data + EC_FMMU_SIZE * j);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   966
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   967
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   968
    fsm->retries = EC_FSM_RETRIES;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   969
    fsm->state = ec_fsm_slave_conf_state_fmmu;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   970
}
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   971
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   972
/*****************************************************************************/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   973
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   974
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   975
   Slave configuration state: FMMU.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   976
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   977
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   978
void ec_fsm_slave_conf_state_fmmu(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   979
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   980
    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
   981
    ec_slave_t *slave = fsm->slave;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   982
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   983
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 635
diff changeset
   984
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   985
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   986
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   987
        fsm->state = ec_fsm_slave_state_error;
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   988
        EC_ERR("Failed to receive FMMUs datagram for slave %i"
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 556
diff changeset
   989
                " (datagram state %i).\n",
615
cde783147040 Removed unnecessary edge in slave configuration FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   990
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   991
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   992
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   993
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   994
    if (datagram->working_counter != 1) {
615
cde783147040 Removed unnecessary edge in slave configuration FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   995
        slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   996
        fsm->state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   997
        EC_ERR("Failed to set FMMUs - slave %i did not respond.\n",
615
cde783147040 Removed unnecessary edge in slave configuration FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   998
               slave->ring_position);
cde783147040 Removed unnecessary edge in slave configuration FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   999
        return;
cde783147040 Removed unnecessary edge in slave configuration FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1000
    }
cde783147040 Removed unnecessary edge in slave configuration FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1001
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1002
    ec_fsm_slave_conf_enter_saveop(fsm);
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1003
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1004
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1005
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1006
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1007
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1008
 */
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1009
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1010
void ec_fsm_slave_conf_enter_saveop(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1011
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1012
    fsm->state = ec_fsm_slave_conf_state_saveop;
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
  1013
    ec_fsm_change_start(&fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_SAVEOP);
434
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1014
    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
  1015
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1016
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1017
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1018
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1019
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1020
   Slave configuration state: SAVEOP.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1021
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1022
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1023
void ec_fsm_slave_conf_state_saveop(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1024
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1025
    ec_master_t *master = fsm->slave->master;
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1026
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1027
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1028
    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
  1029
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1030
    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
  1031
        fsm->slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1032
        fsm->state = ec_fsm_slave_state_error;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1033
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1034
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1035
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1036
    // slave is now in SAVEOP
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1037
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1038
    if (master->debug_level) {
411
42d239bab6ae Fixed typo.
Florian Pose <fp@igh-essen.com>
parents: 409
diff changeset
  1039
        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
  1040
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1041
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1042
    if (fsm->slave->current_state == fsm->slave->requested_state) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1043
        fsm->state = ec_fsm_slave_state_end; // successful
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1044
        if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1045
            EC_DBG("Finished configuration of slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1046
                   slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1047
        }
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1048
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1049
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1050
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1051
    // set state to OP
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1052
    fsm->state = ec_fsm_slave_conf_state_op;
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
  1053
    ec_fsm_change_start(&fsm->fsm_change, slave, EC_SLAVE_STATE_OP);
434
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1054
    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
  1055
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1056
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1057
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1058
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1059
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1060
   Slave configuration state: OP
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1061
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1062
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1063
void ec_fsm_slave_conf_state_op(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1064
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1065
    ec_master_t *master = fsm->slave->master;
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1066
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1067
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1068
    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
  1069
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1070
    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
  1071
        slave->error_flag = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1072
        fsm->state = ec_fsm_slave_state_error;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1073
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1074
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1075
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1076
    // slave is now in OP
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1077
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1078
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1079
        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
  1080
        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
  1081
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1082
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1083
    fsm->state = ec_fsm_slave_state_end; // successful
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1084
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1085
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1086
/******************************************************************************
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  1087
 *  Common state functions
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  1088
 *****************************************************************************/
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1089
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1090
/**
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1091
   State: ERROR.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1092
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1093
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1094
void ec_fsm_slave_state_error(ec_fsm_slave_t *fsm /**< slave state machine */)
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1095
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1096
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1097
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1098
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1099
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1100
/**
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1101
   State: END.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1102
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1103
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1104
void ec_fsm_slave_state_end(ec_fsm_slave_t *fsm /**< slave state machine */)
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1105
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1106
}
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1107
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
  1108
/*****************************************************************************/