master/fsm.c
author Florian Pose <fp@igh-essen.com>
Fri, 26 May 2006 14:28:49 +0000
changeset 261 44a3a5833c49
parent 260 5fe7df7f2433
child 262 636d43737371
permissions -rw-r--r--
Better state-dependent behaviour for EoE-capable slaves.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    12
 *  License, or (at your option) any later version.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    31
 *
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/**
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
   \file
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT finite state machines.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "globals.h"
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "fsm.h"
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "master.h"
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
259
87b20532872b Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 255
diff changeset
    47
/**
87b20532872b Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 255
diff changeset
    48
   Size of memory to allocate while reading categories.
87b20532872b Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 255
diff changeset
    49
*/
87b20532872b Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 255
diff changeset
    50
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
#define EC_CAT_MEM 0x100
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    55
const ec_code_msg_t al_status_messages[];
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    56
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    57
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    58
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
void ec_fsm_master_start(ec_fsm_t *);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    60
void ec_fsm_master_broadcast(ec_fsm_t *);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    61
void ec_fsm_master_proc_states(ec_fsm_t *);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    62
void ec_fsm_master_scan(ec_fsm_t *);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    63
void ec_fsm_master_states(ec_fsm_t *);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    64
void ec_fsm_master_validate_vendor(ec_fsm_t *);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    65
void ec_fsm_master_validate_product(ec_fsm_t *);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    66
void ec_fsm_master_reconfigure(ec_fsm_t *);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    67
void ec_fsm_master_address(ec_fsm_t *);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    68
void ec_fsm_master_conf(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    69
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    70
void ec_fsm_slave_start_reading(ec_fsm_t *);
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
    71
void ec_fsm_slave_read_status(ec_fsm_t *);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
void ec_fsm_slave_read_base(ec_fsm_t *);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
void ec_fsm_slave_read_dl(ec_fsm_t *);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
void ec_fsm_slave_prepare_sii(ec_fsm_t *);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
void ec_fsm_slave_read_sii(ec_fsm_t *);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
void ec_fsm_slave_category_header(ec_fsm_t *);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
void ec_fsm_slave_category_data(ec_fsm_t *);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    78
void ec_fsm_slave_end(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    79
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    80
void ec_fsm_slave_conf(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    81
void ec_fsm_slave_sync(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    82
void ec_fsm_slave_preop(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    83
void ec_fsm_slave_fmmu(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    84
void ec_fsm_slave_saveop(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    85
void ec_fsm_slave_op(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    86
void ec_fsm_slave_op2(ec_fsm_t *);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
void ec_fsm_sii_start_reading(ec_fsm_t *);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
void ec_fsm_sii_check(ec_fsm_t *);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
void ec_fsm_sii_fetch(ec_fsm_t *);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    91
void ec_fsm_sii_end(ec_fsm_t *);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
void ec_fsm_sii_error(ec_fsm_t *);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    94
void ec_fsm_change_start(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    95
void ec_fsm_change_check(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    96
void ec_fsm_change_status(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    97
void ec_fsm_change_code(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    98
void ec_fsm_change_ack(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    99
void ec_fsm_change_ack2(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   100
void ec_fsm_change_end(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   101
void ec_fsm_change_error(ec_fsm_t *);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   102
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   105
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   106
   Constructor.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   107
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   108
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   109
int ec_fsm_init(ec_fsm_t *fsm, /**< finite state machine */
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   110
                ec_master_t *master /**< EtherCAT master */
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   111
                )
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    fsm->master = master;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
    fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    fsm->master_slaves_responding = 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    fsm->master_slave_states = EC_SLAVE_STATE_UNKNOWN;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   117
    fsm->master_validation = 0;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    fsm->slave_cat_data = NULL;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
    ec_command_init(&fsm->command);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
    if (ec_command_prealloc(&fsm->command, EC_MAX_DATA_SIZE)) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
        EC_ERR("FSM failed to allocate FSM command.\n");
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
        return -1;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    return 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   131
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   132
   Destructor.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   133
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   134
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   135
void ec_fsm_clear(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    if (fsm->slave_cat_data) kfree(fsm->slave_cat_data);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
    ec_command_clear(&fsm->command);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   143
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   144
   Resets the state machine.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   145
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   146
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   147
void ec_fsm_reset(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
    fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    fsm->master_slaves_responding = 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    fsm->master_slave_states = EC_SLAVE_STATE_UNKNOWN;
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
    if (fsm->slave_cat_data) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
        kfree(fsm->slave_cat_data);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
        fsm->slave_cat_data = NULL;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   161
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   162
   Executes the current state of the state machine.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   163
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   164
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   165
void ec_fsm_execute(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    fsm->master_state(fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
/******************************************************************************
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
 *  master state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   175
   Master state: START.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
   Starts with getting slave count and slave states.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
void ec_fsm_master_start(ec_fsm_t *fsm)
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
    ec_command_brd(&fsm->command, 0x0130, 2);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
    ec_master_queue_command(fsm->master, &fsm->command);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   183
    fsm->master_state = ec_fsm_master_broadcast;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   184
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   185
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   186
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   187
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   188
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   189
   Master state: BROADCAST.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   190
   Processes the broadcast read slave count and slaves states.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   191
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   192
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   193
void ec_fsm_master_broadcast(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   194
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   195
    ec_command_t *command = &fsm->command;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   196
    unsigned int topology_change, states_change, i;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
    ec_slave_t *slave;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   198
    ec_master_t *master = fsm->master;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
    if (command->state != EC_CMD_RECEIVED) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   201
        if (!master->device->link_state) {
254
986afccca9ea Link down treated as topology change in state machine.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
   202
            fsm->master_slaves_responding = 0;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   203
            list_for_each_entry(slave, &master->slaves, list) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   204
                slave->online = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   205
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   206
        }
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   212
    topology_change = (command->working_counter !=
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   213
                       fsm->master_slaves_responding);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   214
    states_change = (EC_READ_U8(command->data) != fsm->master_slave_states);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   215
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   216
    fsm->master_slave_states = EC_READ_U8(command->data);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   217
    fsm->master_slaves_responding = command->working_counter;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   218
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   219
    if (topology_change) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   220
        if (fsm->master_slaves_responding == master->slave_count) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   221
            EC_INFO("%i slave%s responding (VALID).\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   222
                    fsm->master_slaves_responding,
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   223
                    fsm->master_slaves_responding == 1 ? "" : "s");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   224
            fsm->master_validation = 1; // start validation later
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   225
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   226
        else {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   227
            EC_WARN("%i slave%s responding. Invalid slave count!\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   228
                    fsm->master_slaves_responding,
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   229
                    fsm->master_slaves_responding == 1 ? "" : "s");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   230
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   231
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   232
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   233
    if (states_change) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   234
        EC_INFO("Slave states: ");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   235
        ec_print_states(fsm->master_slave_states);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   236
        printk(".\n");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   237
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   238
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   239
    // topology change in free-run mode: clear all slaves and scan the bus
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   240
    if (topology_change && master->mode == EC_MASTER_MODE_FREERUN) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   241
        EC_INFO("Scanning bus.\n");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   242
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   243
        ec_master_eoe_stop(master);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   244
        ec_master_clear_slaves(master);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   245
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   246
        if (!fsm->master_slaves_responding) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   247
            // no slaves present -> finish state machine.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   248
            fsm->master_state = ec_fsm_master_start;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   249
            fsm->master_state(fsm); // execute immediately
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   250
            return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   251
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   252
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   253
        // init slaves
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   254
        for (i = 0; i < fsm->master_slaves_responding; i++) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   255
            if (!(slave = (ec_slave_t *) kmalloc(sizeof(ec_slave_t),
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   256
                                                 GFP_ATOMIC))) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   257
                EC_ERR("Failed to allocate slave %i!\n", i);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   258
                fsm->master_state = ec_fsm_master_start;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   259
                fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   260
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   261
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   262
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   263
            if (ec_slave_init(slave, master, i, i + 1)) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   264
                fsm->master_state = ec_fsm_master_start;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   265
                fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   266
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   267
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   268
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   269
            if (kobject_add(&slave->kobj)) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   270
                EC_ERR("Failed to add kobject.\n");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   271
                kobject_put(&slave->kobj); // free
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   272
                fsm->master_state = ec_fsm_master_start;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   273
                fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   274
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   275
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   276
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   277
            list_add_tail(&slave->list, &master->slaves);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   278
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   279
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   280
        // begin scanning of slaves
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   281
        fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   282
        fsm->slave_state = ec_fsm_slave_start_reading;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   283
        fsm->master_state = ec_fsm_master_scan;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   284
        fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   285
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   286
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   287
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   288
    // fetch state from each slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   289
    fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   290
    ec_command_nprd(&fsm->command, fsm->slave->station_address, 0x0130, 2);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   291
    ec_master_queue_command(master, &fsm->command);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   292
    fsm->master_state = ec_fsm_master_states;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   293
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   294
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   295
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   296
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   297
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   298
   Master action: Get state of next slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   299
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   300
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   301
void ec_fsm_master_action_next_slave_state(ec_fsm_t *fsm
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   302
                                           /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   303
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   304
    ec_master_t *master = fsm->master;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   305
    ec_slave_t *slave = fsm->slave;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   306
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   307
    // have all states been read?
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   308
    if (slave->list.next == &master->slaves) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   309
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   310
        // check, if a bus validation has to be done
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   311
        if (fsm->master_validation) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   312
            fsm->master_validation = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   313
            list_for_each_entry(slave, &master->slaves, list) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   314
                if (slave->online) continue;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   315
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   316
                // At least one slave is offline. validate!
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   317
                EC_INFO("Validating bus.\n");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   318
                fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   319
                fsm->master_state = ec_fsm_master_validate_vendor;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   320
                fsm->sii_offset = 0x0008; // vendor ID
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   321
                fsm->sii_mode = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   322
                fsm->sii_state = ec_fsm_sii_start_reading;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   323
                fsm->sii_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   324
                return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   325
            }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   326
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   327
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   328
        fsm->master_state = ec_fsm_master_proc_states;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   329
        fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   330
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   331
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   332
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   333
    // process next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   334
    fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   335
    ec_command_nprd(&fsm->command, fsm->slave->station_address, 0x0130, 2);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   336
    ec_master_queue_command(master, &fsm->command);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   337
    fsm->master_state = ec_fsm_master_states;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   338
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   339
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   340
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   341
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   342
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   343
   Master state: STATES.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   344
   Fetches the AL- and online state of a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   345
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   346
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   347
void ec_fsm_master_states(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   348
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   349
    ec_slave_t *slave = fsm->slave;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   350
    ec_command_t *command = &fsm->command;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   351
    uint8_t new_state;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   352
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   353
    if (command->state != EC_CMD_RECEIVED) {
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   359
    // did the slave not respond to its station address?
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   360
    if (command->working_counter != 1) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   361
        if (slave->online) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   362
            slave->online = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   363
            EC_INFO("Slave %i: offline.\n", slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   364
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   365
        ec_fsm_master_action_next_slave_state(fsm);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   366
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   367
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   368
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   369
    // slave responded
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   370
    new_state = EC_READ_U8(command->data);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   371
    if (!slave->online) { // slave was offline before
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   372
        slave->online = 1;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   373
        slave->state_error = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   374
        slave->current_state = new_state;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   375
        EC_INFO("Slave %i: online (", slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   376
        ec_print_states(new_state);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   377
        printk(").\n");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   378
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   379
    else if (new_state != slave->current_state) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   380
        EC_INFO("Slave %i: ", slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   381
        ec_print_states(slave->current_state);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   382
        printk(" -> ");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   383
        ec_print_states(new_state);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   384
        printk(".\n");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   385
        slave->current_state = new_state;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   386
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   387
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   388
    ec_fsm_master_action_next_slave_state(fsm);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   389
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   390
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   391
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   392
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   393
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   394
   Master state: PROC_STATES.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   395
   Processes the slave states.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   396
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   397
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   398
void ec_fsm_master_proc_states(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   399
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   400
    ec_master_t *master = fsm->master;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   401
    ec_slave_t *slave;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   402
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   403
    // check if any slaves are not in the state, they're supposed to be
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   404
    list_for_each_entry(slave, &master->slaves, list) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   405
        if (slave->state_error || !slave->online ||
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   406
            slave->requested_state == EC_SLAVE_STATE_UNKNOWN ||
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   407
            slave->current_state == slave->requested_state) continue;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   408
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   409
        EC_INFO("Changing state of slave %i from ", slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   410
        ec_print_states(slave->current_state);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   411
        printk(" to ");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   412
        ec_print_states(slave->requested_state);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   413
        printk(".\n");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   414
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   415
        fsm->slave = slave;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   416
        fsm->slave_state = ec_fsm_slave_conf;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   417
        fsm->change_new = EC_SLAVE_STATE_INIT;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   418
        fsm->change_state = ec_fsm_change_start;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   419
        fsm->master_state = ec_fsm_master_conf;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   420
        fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   421
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   422
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   423
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   424
    // nothing to configure. restart master state machine.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   425
    fsm->master_state = ec_fsm_master_start;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   426
    fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   427
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   428
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   429
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   430
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   431
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   432
   Master state: VALIDATE_VENDOR.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   433
   Validates the vendor ID of a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   434
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   435
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   436
void ec_fsm_master_validate_vendor(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   437
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   438
    ec_slave_t *slave = fsm->slave;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   439
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   440
    fsm->sii_state(fsm); // execute SII state machine
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   441
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   442
    if (fsm->sii_state == ec_fsm_sii_error) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   443
        EC_ERR("Failed to validate vendor ID of slave %i.\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   444
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   445
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   446
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   447
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   448
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   449
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   450
    if (fsm->sii_state != ec_fsm_sii_end) return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   451
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   452
    if (fsm->sii_result != slave->sii_vendor_id) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   453
        EC_ERR("Slave %i: invalid vendor ID!\n", slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   457
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   458
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   459
    // vendor ID is ok. check product code.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   460
    fsm->master_state = ec_fsm_master_validate_product;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   461
    fsm->sii_offset = 0x000A; // product code
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   462
    fsm->sii_mode = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   463
    fsm->sii_state = ec_fsm_sii_start_reading;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   464
    fsm->sii_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   465
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   466
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   467
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   468
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   469
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   470
   Master state: VALIDATE_PRODUCT.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   471
   Validates the product ID of a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   472
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   473
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   474
void ec_fsm_master_validate_product(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   475
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   476
    ec_slave_t *slave = fsm->slave;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   477
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   478
    fsm->sii_state(fsm); // execute SII state machine
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   479
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   480
    if (fsm->sii_state == ec_fsm_sii_error) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   481
        EC_ERR("Failed to validate product code of slave %i.\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   482
               slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   483
        fsm->master_state = ec_fsm_master_start;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   484
        fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   485
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   486
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   487
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   488
    if (fsm->sii_state != ec_fsm_sii_end) return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   489
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   490
    if (fsm->sii_result != slave->sii_product_code) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   491
        EC_ERR("Slave %i: invalid product code!\n", slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   492
        EC_ERR("expected 0x%08X, got 0x%08X.\n", slave->sii_product_code,
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   493
               fsm->sii_result);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   494
        fsm->master_state = ec_fsm_master_start;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   495
        fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   496
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   497
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   498
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   499
    // have all states been validated?
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   500
    if (slave->list.next == &fsm->master->slaves) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   501
        fsm->slave = list_entry(fsm->master->slaves.next, ec_slave_t, list);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   502
        fsm->master_state = ec_fsm_master_reconfigure;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   503
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   504
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   505
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   506
    // validate next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   507
    fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   508
    fsm->master_state = ec_fsm_master_validate_vendor;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   509
    fsm->sii_offset = 0x0008; // vendor ID
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   510
    fsm->sii_mode = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   511
    fsm->sii_state = ec_fsm_sii_start_reading;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   512
    fsm->sii_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   513
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   514
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   515
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   516
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   517
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   518
   Master state: RECONFIGURE.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   519
   Looks for slave, that have lost their configuration and writes
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   520
   their station address, so that they can be reconfigured later.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   521
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   522
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   523
void ec_fsm_master_reconfigure(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   524
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   525
    ec_command_t *command = &fsm->command;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   526
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   527
    while (fsm->slave->online) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   528
        if (fsm->slave->list.next == &fsm->master->slaves) { // last slave?
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   529
            fsm->master_state = ec_fsm_master_start;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   530
            fsm->master_state(fsm); // execute immediately
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   531
            return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   532
        }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   533
        // check next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   534
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   535
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   536
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   537
    EC_INFO("Reinitializing slave %i.\n", fsm->slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   538
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   539
    // write station address
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   540
    ec_command_apwr(command, fsm->slave->ring_position, 0x0010, 2);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   541
    EC_WRITE_U16(command->data, fsm->slave->station_address);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   542
    ec_master_queue_command(fsm->master, command);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   543
    fsm->master_state = ec_fsm_master_address;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   544
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   545
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   546
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   547
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   548
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   549
   Master state: ADDRESS.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   550
   Checks, if the new station address has been written to the slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   551
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   552
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   553
void ec_fsm_master_address(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   554
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   555
    ec_slave_t *slave = fsm->slave;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   556
    ec_command_t *command = &fsm->command;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   557
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   558
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   559
        EC_ERR("Failed to write station address on slave %i.\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   560
               slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   561
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   562
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   563
    if (fsm->slave->list.next == &fsm->master->slaves) { // last slave?
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   564
        fsm->master_state = ec_fsm_master_start;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   565
        fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   566
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   567
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   568
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   569
    // check next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   570
    fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   571
    fsm->master_state = ec_fsm_master_reconfigure;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   572
    fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   573
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   574
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   575
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   576
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   577
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   578
   Master state: SCAN.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   579
   Executes the sub-statemachine for the scanning of a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   580
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   581
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   582
void ec_fsm_master_scan(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   583
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   584
    ec_master_t *master = fsm->master;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   585
    ec_slave_t *slave = fsm->slave;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   586
    uint16_t coupler_index, coupler_subindex;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   587
    uint16_t reverse_coupler_index, current_coupler_index;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   588
    ec_slave_ident_t *ident;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   589
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   590
    fsm->slave_state(fsm); // execute slave state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   591
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   592
    if (fsm->slave_state != ec_fsm_slave_end) return;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   593
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   594
    // have all slaves been fetched?
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   595
    if (slave->list.next == &master->slaves) {
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   596
        EC_INFO("Bus scanning completed.\n");
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   597
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   598
        // identify all slaves and calculate coupler addressing
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   599
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   600
        coupler_index = 0;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   601
        reverse_coupler_index = 0xFFFF;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   602
        current_coupler_index = 0x3FFF;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   603
        coupler_subindex = 0;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   604
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   605
        list_for_each_entry(slave, &master->slaves, list)
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   606
        {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   607
            // search for identification in "database"
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   608
            ident = slave_idents;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   609
            while (ident->type) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   610
                if (ident->vendor_id == slave->sii_vendor_id
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   611
                    && ident->product_code == slave->sii_product_code) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   612
                    slave->type = ident->type;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   613
                    break;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   614
                }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   615
                ident++;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   616
            }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   617
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   618
            if (!slave->type) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   619
                EC_WARN("FSM: Unknown slave device (vendor 0x%08X,"
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   620
                        " code 0x%08X) at position %i.\n",
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   621
                        slave->sii_vendor_id, slave->sii_product_code,
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   622
                        slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   623
            }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   624
            else {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   625
                // if the slave is a bus coupler, change adressing base
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   626
                if (slave->type->special == EC_TYPE_BUS_COUPLER) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   627
                    if (slave->sii_alias)
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   628
                        current_coupler_index = reverse_coupler_index--;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   629
                    else
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   630
                        current_coupler_index = coupler_index++;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   631
                    coupler_subindex = 0;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   632
                }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   633
            }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   634
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   635
            // determine initial state.
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   636
            if ((slave->type && slave->type->special == EC_TYPE_BUS_COUPLER)) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   637
                slave->requested_state = EC_SLAVE_STATE_OP;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   638
            }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   639
            else {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   640
                if (master->mode == EC_MASTER_MODE_RUNNING)
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   641
                    slave->requested_state = EC_SLAVE_STATE_PREOP;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   642
                else
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   643
                    slave->requested_state = EC_SLAVE_STATE_INIT;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   644
            }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   645
            slave->state_error = 0;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   646
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   647
            // calculate coupler-based slave address
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   648
            slave->coupler_index = current_coupler_index;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   649
            slave->coupler_subindex = coupler_subindex;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   650
            coupler_subindex++;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   651
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   652
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   653
        if (master->mode == EC_MASTER_MODE_FREERUN) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   654
            // start EoE processing
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   655
            ec_master_eoe_start(master);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   656
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   657
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   658
        fsm->master_state = ec_fsm_master_start;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   659
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   660
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   661
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   662
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   663
    // process next slave
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   664
    fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   665
    fsm->slave_state = ec_fsm_slave_start_reading;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   666
    fsm->slave_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   667
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   668
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   669
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   670
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   671
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   672
   Master state: CONF.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   673
   Starts configuring a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   674
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   675
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   676
void ec_fsm_master_conf(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   677
{
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   678
    fsm->slave_state(fsm); // execute slave's state machine
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   679
    if (fsm->slave_state != ec_fsm_slave_end) return;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   680
    fsm->master_state = ec_fsm_master_proc_states;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   681
    fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   682
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   683
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   684
/******************************************************************************
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   685
 *  slave state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   686
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   687
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   688
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   689
   Slave state: START_READING.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   690
   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
   691
   slave, according to its ring position.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   692
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   693
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   694
void ec_fsm_slave_start_reading(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   695
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   696
    ec_command_t *command = &fsm->command;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   697
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   698
    // write station address
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   699
    ec_command_apwr(command, fsm->slave->ring_position, 0x0010, 2);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   700
    EC_WRITE_U16(command->data, fsm->slave->station_address);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   701
    ec_master_queue_command(fsm->master, command);
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   702
    fsm->slave_state = ec_fsm_slave_read_status;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   703
}
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   704
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   705
/*****************************************************************************/
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   706
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   707
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   708
   Slave state: READ_STATUS.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   709
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   710
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   711
void ec_fsm_slave_read_status(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   712
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   713
    ec_command_t *command = &fsm->command;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   714
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   715
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   716
        EC_ERR("FSM failed to write station address of slave %i.\n",
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   717
               fsm->slave->ring_position);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   718
        fsm->slave_state = ec_fsm_slave_end;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   719
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   720
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   721
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   722
    // read AL status
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   723
    ec_command_nprd(command, fsm->slave->station_address, 0x0130, 2);
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   724
    ec_master_queue_command(fsm->master, command);
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   725
    fsm->slave_state = ec_fsm_slave_read_base;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   726
}
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   727
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   728
/*****************************************************************************/
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   729
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   730
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   731
   Slave state: READ_BASE.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   732
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   733
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   734
void ec_fsm_slave_read_base(ec_fsm_t *fsm /**< finite state machine */)
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   735
{
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   736
    ec_command_t *command = &fsm->command;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   737
    ec_slave_t *slave = fsm->slave;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   738
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   739
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   740
        EC_ERR("FSM failed to read AL status of slave %i.\n",
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   741
               fsm->slave->ring_position);
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   742
        fsm->slave_state = ec_fsm_slave_end;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   743
        return;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   744
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   745
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   746
    slave->current_state = EC_READ_U8(command->data);
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   747
    if (slave->current_state & EC_ACK) {
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   748
        EC_WARN("Slave %i has status error bit set (0x%02X)!\n",
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   749
                slave->ring_position, slave->current_state);
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   750
        slave->current_state &= 0x0F;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   751
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   752
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   753
    // read base data
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   754
    ec_command_nprd(command, fsm->slave->station_address, 0x0000, 6);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   755
    ec_master_queue_command(fsm->master, command);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   756
    fsm->slave_state = ec_fsm_slave_read_dl;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   757
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   758
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   759
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   760
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   761
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   762
   Slave state: READ_DL.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   763
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   764
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   765
void ec_fsm_slave_read_dl(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   766
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   767
    ec_command_t *command = &fsm->command;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   768
    ec_slave_t *slave = fsm->slave;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   769
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   770
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   771
        EC_ERR("FSM failed to read base data of slave %i.\n",
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   772
               slave->ring_position);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   773
        fsm->slave_state = ec_fsm_slave_end;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   774
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   775
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   776
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   777
    slave->base_type       = EC_READ_U8 (command->data);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   778
    slave->base_revision   = EC_READ_U8 (command->data + 1);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   779
    slave->base_build      = EC_READ_U16(command->data + 2);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   780
    slave->base_fmmu_count = EC_READ_U8 (command->data + 4);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   781
    slave->base_sync_count = EC_READ_U8 (command->data + 5);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   782
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   783
    if (slave->base_fmmu_count > EC_MAX_FMMUS)
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   784
        slave->base_fmmu_count = EC_MAX_FMMUS;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   785
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   786
    // read data link status
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   787
    ec_command_nprd(command, slave->station_address, 0x0110, 2);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   788
    ec_master_queue_command(slave->master, command);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   789
    fsm->slave_state = ec_fsm_slave_prepare_sii;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   790
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   791
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   792
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   793
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   794
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   795
   Slave state: PREPARE_SII.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   796
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   797
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   798
void ec_fsm_slave_prepare_sii(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   799
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   800
    ec_command_t *command = &fsm->command;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   801
    ec_slave_t *slave = fsm->slave;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   802
    uint16_t dl_status;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   803
    unsigned int i;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   804
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   805
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   806
        EC_ERR("FSM failed to read DL status of slave %i.\n",
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   807
               slave->ring_position);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   808
        fsm->slave_state = ec_fsm_slave_end;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   809
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   810
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   811
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   812
    dl_status = EC_READ_U16(command->data);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   813
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   814
    for (i = 0; i < 4; i++) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   815
        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
   816
        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
   817
        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
   818
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   819
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   820
    fsm->sii_offset = 0x0004;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   821
    fsm->sii_mode = 1;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   822
    fsm->sii_state = ec_fsm_sii_start_reading;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   823
    fsm->slave_sii_num = 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   824
    fsm->slave_state = ec_fsm_slave_read_sii;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   825
    fsm->slave_state(fsm); // execute state immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   826
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   827
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   828
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   829
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   830
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   831
   Slave state: READ_SII.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   832
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   833
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   834
void ec_fsm_slave_read_sii(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   835
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   836
    ec_slave_t *slave = fsm->slave;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   837
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   838
    // execute SII state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   839
    fsm->sii_state(fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   840
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   841
    if (fsm->sii_state == ec_fsm_sii_error) {
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   842
        fsm->slave_state = ec_fsm_slave_end;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   843
        EC_ERR("FSM failed to read SII data at 0x%04X on slave %i.\n",
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   844
               fsm->sii_offset, slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   845
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   846
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   847
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   848
    if (fsm->sii_state != ec_fsm_sii_end) return;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   849
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   850
    switch (fsm->slave_sii_num) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   851
        case 0:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   852
            slave->sii_alias = fsm->sii_result & 0xFFFF;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   853
            fsm->sii_offset = 0x0008;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   854
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   855
        case 1:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   856
            slave->sii_vendor_id = fsm->sii_result;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   857
            fsm->sii_offset = 0x000A;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   858
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   859
        case 2:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   860
            slave->sii_product_code = fsm->sii_result;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   861
            fsm->sii_offset = 0x000C;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   862
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   863
        case 3:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   864
            slave->sii_revision_number = fsm->sii_result;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   865
            fsm->sii_offset = 0x000E;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   866
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   867
        case 4:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   868
            slave->sii_serial_number = fsm->sii_result;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   869
            fsm->sii_offset = 0x0018;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   870
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   871
        case 5:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   872
            slave->sii_rx_mailbox_offset = fsm->sii_result & 0xFFFF;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   873
            slave->sii_rx_mailbox_size = fsm->sii_result >> 16;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   874
            fsm->sii_offset = 0x001A;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   875
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   876
        case 6:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   877
            slave->sii_tx_mailbox_offset = fsm->sii_result & 0xFFFF;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   878
            slave->sii_tx_mailbox_size = fsm->sii_result >> 16;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   879
            fsm->sii_offset = 0x001C;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   880
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   881
        case 7:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   882
            slave->sii_mailbox_protocols = fsm->sii_result & 0xFFFF;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   883
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   884
            fsm->slave_cat_offset = 0x0040;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   885
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   886
            if (fsm->slave_cat_data) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   887
                EC_INFO("FSM freeing old category data on slave %i...\n",
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   888
                        fsm->slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   889
                kfree(fsm->slave_cat_data);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   890
            }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   891
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   892
            if (!(fsm->slave_cat_data =
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   893
                  (uint8_t *) kmalloc(EC_CAT_MEM, GFP_ATOMIC))) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   894
                EC_ERR("FSM Failed to allocate category data.\n");
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   895
                fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   896
                return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   897
            }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   898
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   899
            // start reading first category header
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   900
            fsm->sii_offset = fsm->slave_cat_offset;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   901
            fsm->sii_state = ec_fsm_sii_start_reading;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   902
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   903
            fsm->slave_state = ec_fsm_slave_category_header;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   904
            fsm->slave_state(fsm); // execute state immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   905
            return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   906
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   907
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   908
    fsm->slave_sii_num++;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   909
    fsm->sii_state = ec_fsm_sii_start_reading;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   910
    fsm->slave_state(fsm); // execute state immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   911
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   912
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   913
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   914
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   915
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   916
   Slave state: CATEGORY_HEADER.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   917
   Start reading categories.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   918
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   919
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   920
void ec_fsm_slave_category_header(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   921
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   922
    // execute SII state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   923
    fsm->sii_state(fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   924
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   925
    if (fsm->sii_state == ec_fsm_sii_error) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   926
        kfree(fsm->slave_cat_data);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   927
        fsm->slave_cat_data = NULL;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   928
        fsm->slave_state = ec_fsm_slave_end;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   929
        EC_ERR("FSM failed to read category header at 0x%04X on slave %i.\n",
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   930
               fsm->slave_cat_offset, fsm->slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   931
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   932
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   933
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   934
    if (fsm->sii_state != ec_fsm_sii_end) return;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   935
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   936
    // last category?
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   937
    if ((fsm->sii_result & 0xFFFF) == 0xFFFF) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   938
        kfree(fsm->slave_cat_data);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   939
        fsm->slave_cat_data = NULL;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   940
        fsm->slave_state = ec_fsm_slave_end;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   941
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   942
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   943
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   944
    fsm->slave_cat_type = fsm->sii_result & 0x7FFF;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   945
    fsm->slave_cat_words = (fsm->sii_result >> 16) & 0xFFFF;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   946
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   947
    if (fsm->slave_cat_words > EC_CAT_MEM * 2) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   948
        EC_ERR("FSM category memory too small! %i words needed.\n",
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   949
               fsm->slave_cat_words);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   950
        fsm->slave_state = ec_fsm_slave_end;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   951
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   952
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   953
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   954
    // start reading category data
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   955
    fsm->slave_cat_data_offset = 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   956
    fsm->sii_offset = (fsm->slave_cat_offset + 2 +
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   957
                       fsm->slave_cat_data_offset);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   958
    fsm->sii_mode = 1;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   959
    fsm->sii_state = ec_fsm_sii_start_reading;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   960
    fsm->slave_state = ec_fsm_slave_category_data;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   961
    fsm->slave_state(fsm); // execute state immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   962
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   963
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   964
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   965
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   966
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   967
   Slave state: CATEGORY_DATA.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   968
   Reads category data.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   969
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   970
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   971
void ec_fsm_slave_category_data(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   972
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   973
    // execute SII state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   974
    fsm->sii_state(fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   975
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   976
    if (fsm->sii_state == ec_fsm_sii_error) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   977
        kfree(fsm->slave_cat_data);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   978
        fsm->slave_cat_data = NULL;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   979
        fsm->slave_state = ec_fsm_slave_end;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   980
        EC_ERR("FSM failed to read category 0x%02X data at 0x%04X"
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   981
               " on slave %i.\n", fsm->slave_cat_type, fsm->sii_offset,
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   982
               fsm->slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   983
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   984
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   985
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   986
    if (fsm->sii_state != ec_fsm_sii_end) return;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   987
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   988
    fsm->slave_cat_data[fsm->slave_cat_data_offset * 2] =
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   989
        fsm->sii_result & 0xFF;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   990
    fsm->slave_cat_data[fsm->slave_cat_data_offset * 2 + 1] =
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   991
        (fsm->sii_result >> 8) & 0xFF;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   992
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   993
    // read second word "on the fly"
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   994
    if (fsm->slave_cat_data_offset + 1 < fsm->slave_cat_words) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   995
        fsm->slave_cat_data_offset++;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   996
        fsm->slave_cat_data[fsm->slave_cat_data_offset * 2] =
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   997
            (fsm->sii_result >> 16) & 0xFF;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   998
        fsm->slave_cat_data[fsm->slave_cat_data_offset * 2 + 1] =
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   999
            (fsm->sii_result >> 24) & 0xFF;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1000
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1001
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1002
    fsm->slave_cat_data_offset++;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1003
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1004
    if (fsm->slave_cat_data_offset < fsm->slave_cat_words) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1005
        fsm->sii_offset = (fsm->slave_cat_offset + 2 +
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1006
                           fsm->slave_cat_data_offset);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1007
        fsm->sii_mode = 1;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1008
        fsm->sii_state = ec_fsm_sii_start_reading;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1009
        fsm->slave_state = ec_fsm_slave_category_data;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1010
        fsm->slave_state(fsm); // execute state immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1011
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1012
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1013
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1014
    // category data complete
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1015
    switch (fsm->slave_cat_type)
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1016
    {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1017
        case 0x000A:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1018
            if (ec_slave_fetch_strings(fsm->slave, fsm->slave_cat_data))
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1019
                goto out_free;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1020
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1021
        case 0x001E:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1022
            if (ec_slave_fetch_general(fsm->slave, fsm->slave_cat_data))
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1023
                goto out_free;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1024
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1025
        case 0x0028:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1026
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1027
        case 0x0029:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1028
            if (ec_slave_fetch_sync(fsm->slave, fsm->slave_cat_data,
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1029
                                    fsm->slave_cat_words))
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1030
                goto out_free;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1031
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1032
        case 0x0032:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1033
            if (ec_slave_fetch_pdo(fsm->slave, fsm->slave_cat_data,
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1034
                                   fsm->slave_cat_words,
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1035
                                   EC_TX_PDO))
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1036
                goto out_free;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1037
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1038
        case 0x0033:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1039
            if (ec_slave_fetch_pdo(fsm->slave, fsm->slave_cat_data,
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1040
                                   fsm->slave_cat_words,
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1041
                                   EC_RX_PDO))
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1042
                goto out_free;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1043
            break;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1044
        default:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1045
            EC_WARN("FSM: Unknown category type 0x%04X in slave %i.\n",
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1046
                    fsm->slave_cat_type, fsm->slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1047
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1048
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1049
    // start reading next category header
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1050
    fsm->slave_cat_offset += 2 + fsm->slave_cat_words;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1051
    fsm->sii_offset = fsm->slave_cat_offset;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1052
    fsm->sii_mode = 1;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1053
    fsm->sii_state = ec_fsm_sii_start_reading;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1054
    fsm->slave_state = ec_fsm_slave_category_header;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1055
    fsm->slave_state(fsm); // execute state immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1056
    return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1057
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1058
 out_free:
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1059
    kfree(fsm->slave_cat_data);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1060
    fsm->slave_cat_data = NULL;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1061
    fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1062
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1063
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1064
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1065
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1066
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1067
   Slave state: CONF.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1068
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1069
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1070
void ec_fsm_slave_conf(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1071
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1072
    ec_slave_t *slave = fsm->slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1073
    ec_master_t *master = fsm->master;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1074
    ec_command_t *command = &fsm->command;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1075
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1076
    fsm->change_state(fsm); // execute state change state machine
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1077
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1078
    if (fsm->change_state == ec_fsm_change_error) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1079
        fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1080
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1081
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1082
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1083
    if (fsm->change_state != ec_fsm_change_end) return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1084
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1085
    // 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
  1086
    if (slave->current_state == slave->requested_state) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1087
        fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1088
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1089
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1090
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1091
    // check for slave registration
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1092
    if (!slave->type) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1093
        EC_WARN("Slave %i has unknown type!\n", slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1094
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1095
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1096
    // check and reset CRC fault counters
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1097
    //ec_slave_check_crc(slave);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1098
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1099
    if (!slave->base_fmmu_count) { // no fmmus
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1100
        fsm->slave_state = ec_fsm_slave_sync;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1101
        fsm->slave_state(fsm); // execute immediately
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1102
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1103
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1104
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1105
    // reset FMMUs
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1106
    ec_command_npwr(command, slave->station_address, 0x0600,
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1107
                    EC_FMMU_SIZE * slave->base_fmmu_count);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1108
    memset(command->data, 0x00, EC_FMMU_SIZE * slave->base_fmmu_count);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1109
    ec_master_queue_command(master, command);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1110
    fsm->slave_state = ec_fsm_slave_sync;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1111
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1112
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1113
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1114
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1115
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1116
   Slave state: SYNC.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1117
   Configure sync managers.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1118
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1119
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1120
void ec_fsm_slave_sync(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1121
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1122
    ec_command_t *command = &fsm->command;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1123
    ec_slave_t *slave = fsm->slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1124
    unsigned int j;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1125
    const ec_sync_t *sync;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1126
    ec_eeprom_sync_t *eeprom_sync, mbox_sync;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1127
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1128
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1129
        EC_ERR("Failed to reset FMMUs of slave %i.\n",
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1130
               slave->ring_position);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1131
        slave->state_error = 1;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1132
        fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1133
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1134
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1135
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1136
    if (!slave->base_sync_count) { // no sync managers
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1137
        fsm->slave_state = ec_fsm_slave_preop;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1138
        fsm->slave_state(fsm); // execute immediately
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1139
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1140
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1141
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1142
    // configure sync managers
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1143
    ec_command_npwr(command, slave->station_address, 0x0800,
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1144
                    EC_SYNC_SIZE * slave->base_sync_count);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1145
    memset(command->data, 0x00, EC_SYNC_SIZE * slave->base_sync_count);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1146
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1147
    // known slave type, take type's SM information
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1148
    if (slave->type) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1149
        for (j = 0; slave->type->sync_managers[j] && j < EC_MAX_SYNC; j++) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1150
            sync = slave->type->sync_managers[j];
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1151
            ec_sync_config(sync, command->data + EC_SYNC_SIZE * j);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1152
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1153
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1154
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1155
    // unknown type, but slave has mailbox
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1156
    else if (slave->sii_mailbox_protocols)
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1157
    {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1158
        // does it supply sync manager configurations in its EEPROM?
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1159
        if (!list_empty(&slave->eeprom_syncs)) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1160
            list_for_each_entry(eeprom_sync, &slave->eeprom_syncs, list) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1161
                if (eeprom_sync->index >= slave->base_sync_count) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1162
                    EC_ERR("Invalid sync manager configuration found!");
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1163
                    fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1164
                    return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1165
                }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1166
                ec_eeprom_sync_config(eeprom_sync,
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1167
                                      command->data + EC_SYNC_SIZE
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1168
                                      * eeprom_sync->index);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1169
            }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1170
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1171
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1172
        // no sync manager information; guess mailbox settings
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1173
        else {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1174
            mbox_sync.physical_start_address =
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1175
                slave->sii_rx_mailbox_offset;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1176
            mbox_sync.length = slave->sii_rx_mailbox_size;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1177
            mbox_sync.control_register = 0x26;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1178
            mbox_sync.enable = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1179
            ec_eeprom_sync_config(&mbox_sync, command->data);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1180
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1181
            mbox_sync.physical_start_address =
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1182
                slave->sii_tx_mailbox_offset;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1183
            mbox_sync.length = slave->sii_tx_mailbox_size;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1184
            mbox_sync.control_register = 0x22;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1185
            mbox_sync.enable = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1186
            ec_eeprom_sync_config(&mbox_sync,
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1187
                                  command->data + EC_SYNC_SIZE);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1188
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1189
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1190
        EC_INFO("Mailbox configured for unknown slave %i\n",
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1191
                slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1192
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1193
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1194
    ec_master_queue_command(fsm->master, command);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1195
    fsm->slave_state = ec_fsm_slave_preop;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1196
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1197
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1198
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1199
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1200
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1201
   Slave state: PREOP.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1202
   Change slave state to PREOP.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1203
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1204
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1205
void ec_fsm_slave_preop(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1206
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1207
    ec_command_t *command = &fsm->command;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1208
    ec_slave_t *slave = fsm->slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1209
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1210
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1211
        EC_ERR("Failed to set sync managers on slave %i.\n",
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1212
               slave->ring_position);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1213
        slave->state_error = 1;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1214
        fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1215
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1216
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1217
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1218
    fsm->change_new = EC_SLAVE_STATE_PREOP;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1219
    fsm->change_state = ec_fsm_change_start;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1220
    fsm->slave_state = ec_fsm_slave_fmmu;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1221
    fsm->change_state(fsm); // execute immediately
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1222
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1223
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1224
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1225
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1226
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1227
   Slave state: FMMU.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1228
   Configure FMMUs.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1229
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1230
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1231
void ec_fsm_slave_fmmu(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1232
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1233
    ec_slave_t *slave = fsm->slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1234
    ec_master_t *master = fsm->master;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1235
    ec_command_t *command = &fsm->command;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1236
    unsigned int j;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1237
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1238
    fsm->change_state(fsm); // execute state change state machine
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1239
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1240
    if (fsm->change_state == ec_fsm_change_error) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1241
        fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1242
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1243
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1244
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1245
    if (fsm->change_state != ec_fsm_change_end) return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1246
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1247
    // slave is now in PREOP
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1248
    if (slave->current_state == slave->requested_state) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1249
        fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1250
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1251
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1252
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1253
    // stop activation here for slaves without type
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1254
    if (!slave->type) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1255
        fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1256
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1257
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1258
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1259
    if (!slave->base_fmmu_count) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1260
        fsm->slave_state = ec_fsm_slave_saveop;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1261
        fsm->slave_state(fsm); // execute immediately
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1262
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1263
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1264
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1265
    // configure FMMUs
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1266
    ec_command_npwr(command, slave->station_address,
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1267
                    0x0600, EC_FMMU_SIZE * slave->base_fmmu_count);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1268
    memset(command->data, 0x00, EC_FMMU_SIZE * slave->base_fmmu_count);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1269
    for (j = 0; j < slave->fmmu_count; j++) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1270
        ec_fmmu_config(&slave->fmmus[j], command->data + EC_FMMU_SIZE * j);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1271
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1272
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1273
    ec_master_queue_command(master, command);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1274
    fsm->slave_state = ec_fsm_slave_saveop;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1275
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1276
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1277
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1278
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1279
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1280
   Slave state: SAVEOP.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1281
   Set slave state to SAVEOP.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1282
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1283
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1284
void ec_fsm_slave_saveop(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1285
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1286
    ec_command_t *command = &fsm->command;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1287
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1288
    if (fsm->slave->base_fmmu_count && (command->state != EC_CMD_RECEIVED ||
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1289
                                        command->working_counter != 1)) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1290
        EC_ERR("FSM failed to set FMMUs on slave %i.\n",
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1291
               fsm->slave->ring_position);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1292
        fsm->slave->state_error = 1;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1293
        fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1294
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1295
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1296
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1297
    // set state to SAVEOP
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1298
    fsm->slave_state = ec_fsm_slave_op;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1299
    fsm->change_new = EC_SLAVE_STATE_SAVEOP;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1300
    fsm->change_state = ec_fsm_change_start;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1301
    fsm->change_state(fsm); // execute immediately
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1302
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1303
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1304
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1305
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1306
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1307
   Slave state: OP.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1308
   Set slave state to OP.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1309
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1310
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1311
void ec_fsm_slave_op(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1312
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1313
    fsm->change_state(fsm); // execute state change state machine
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1314
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1315
    if (fsm->change_state == ec_fsm_change_error) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1316
        fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1317
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1318
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1319
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1320
    if (fsm->change_state != ec_fsm_change_end) return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1321
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1322
    // slave is now in SAVEOP
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1323
    if (fsm->slave->current_state == fsm->slave->requested_state) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1324
        fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1325
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1326
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1327
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1328
    // set state to OP
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1329
    fsm->slave_state = ec_fsm_slave_op2;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1330
    fsm->change_new = EC_SLAVE_STATE_OP;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1331
    fsm->change_state = ec_fsm_change_start;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1332
    fsm->change_state(fsm); // execute immediately
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1333
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1334
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1335
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1336
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1337
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1338
   Slave state: OP2
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1339
   Executes the change state machine, until the OP state is set.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1340
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1341
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1342
void ec_fsm_slave_op2(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1343
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1344
    fsm->change_state(fsm); // execute state change state machine
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1345
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1346
    if (fsm->change_state == ec_fsm_change_error) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1347
        fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1348
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1349
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1350
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1351
    if (fsm->change_state != ec_fsm_change_end) return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1352
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1353
    // slave is now in OP
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1354
    fsm->slave_state = ec_fsm_slave_end;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1355
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1356
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1357
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1358
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1359
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1360
   Slave state: END.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1361
   End state of the slave state machine.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1362
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1363
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1364
void ec_fsm_slave_end(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1365
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1366
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1367
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1368
/******************************************************************************
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1369
 *  SII state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1370
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1371
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1372
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1373
   SII state: START_READING.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1374
   Starts reading the slave information interface.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1375
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1376
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1377
void ec_fsm_sii_start_reading(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1378
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1379
    ec_command_t *command = &fsm->command;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1380
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1381
    // initiate read operation
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1382
    if (fsm->sii_mode) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1383
        ec_command_npwr(command, fsm->slave->station_address, 0x502, 4);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1384
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1385
    else {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1386
        ec_command_apwr(command, fsm->slave->ring_position, 0x502, 4);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1387
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1388
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1389
    EC_WRITE_U8 (command->data,     0x00); // read-only access
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1390
    EC_WRITE_U8 (command->data + 1, 0x01); // request read operation
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1391
    EC_WRITE_U16(command->data + 2, fsm->sii_offset);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1392
    ec_master_queue_command(fsm->master, command);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1393
    fsm->sii_state = ec_fsm_sii_check;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1394
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1395
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1396
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1397
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1398
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1399
   SII state: CHECK.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1400
   Checks, if the SII-read-command has been sent and issues a fetch command.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1401
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1402
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1403
void ec_fsm_sii_check(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1404
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1405
    ec_command_t *command = &fsm->command;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1406
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1407
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1408
        EC_ERR("SII: Reception of read command failed.\n");
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1409
        fsm->sii_state = ec_fsm_sii_error;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1410
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1411
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1412
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1413
    fsm->sii_start = get_cycles();
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1414
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1415
    // issue check/fetch command
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1416
    if (fsm->sii_mode) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1417
        ec_command_nprd(command, fsm->slave->station_address, 0x502, 10);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1418
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1419
    else {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1420
        ec_command_aprd(command, fsm->slave->ring_position, 0x502, 10);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1421
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1422
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1423
    ec_master_queue_command(fsm->master, command);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1424
    fsm->sii_state = ec_fsm_sii_fetch;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1425
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1426
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1427
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1428
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1429
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1430
   SII state: FETCH.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1431
   Fetches the result of an SII-read command.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1432
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1433
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1434
void ec_fsm_sii_fetch(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1435
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1436
    ec_command_t *command = &fsm->command;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1437
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1438
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1439
        EC_ERR("SII: Reception of check/fetch command failed.\n");
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1440
        fsm->sii_state = ec_fsm_sii_error;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1441
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1442
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1443
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1444
    // check "busy bit"
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1445
    if (EC_READ_U8(command->data + 1) & 0x81) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1446
        // still busy... timeout?
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1447
        if (get_cycles() - fsm->sii_start >= (cycles_t) 10 * cpu_khz) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1448
            EC_ERR("SII: Timeout.\n");
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1449
            fsm->sii_state = ec_fsm_sii_error;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1450
#if 0
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1451
            EC_DBG("SII busy: %02X %02X %02X %02X\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1452
                   EC_READ_U8(command->data + 0),
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1453
                   EC_READ_U8(command->data + 1),
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1454
                   EC_READ_U8(command->data + 2),
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1455
                   EC_READ_U8(command->data + 3));
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1456
#endif
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1457
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1458
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1459
        // issue check/fetch command again
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1460
        if (fsm->sii_mode) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1461
            ec_command_nprd(command, fsm->slave->station_address, 0x502, 10);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1462
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1463
        else {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1464
            ec_command_aprd(command, fsm->slave->ring_position, 0x502, 10);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1465
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1466
        ec_master_queue_command(fsm->master, command);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1467
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1468
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1469
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1470
#if 0
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1471
    EC_DBG("SII rec: %02X %02X %02X %02X - %02X %02X %02X %02X\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1472
           EC_READ_U8(command->data + 0), EC_READ_U8(command->data + 1),
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1473
           EC_READ_U8(command->data + 2), EC_READ_U8(command->data + 3),
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1474
           EC_READ_U8(command->data + 6), EC_READ_U8(command->data + 7),
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1475
           EC_READ_U8(command->data + 8), EC_READ_U8(command->data + 9));
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1476
#endif
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1477
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1478
    // SII value received.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1479
    fsm->sii_result = EC_READ_U32(command->data + 6);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1480
    fsm->sii_state = ec_fsm_sii_end;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1481
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1482
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1483
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1484
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1485
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1486
   SII state: END.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1487
   End state of the slave SII state machine.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1488
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1489
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1490
void ec_fsm_sii_end(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1491
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1492
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1493
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1494
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1495
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1496
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1497
   SII state: ERROR.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1498
   End state of the slave SII state machine.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1499
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1500
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1501
void ec_fsm_sii_error(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1502
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1503
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1504
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1505
/******************************************************************************
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1506
 *  state change state machine
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1507
 *****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1508
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1509
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1510
   Change state: START.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1511
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1512
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1513
void ec_fsm_change_start(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1514
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1515
    ec_command_t *command = &fsm->command;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1516
    ec_slave_t *slave = fsm->slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1517
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1518
    // write new state to slave
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1519
    ec_command_npwr(command, slave->station_address, 0x0120, 2);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1520
    EC_WRITE_U16(command->data, fsm->change_new);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1521
    ec_master_queue_command(fsm->master, command);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1522
    fsm->change_state = ec_fsm_change_check;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1523
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1524
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1525
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1526
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1527
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1528
   Change state: CHECK.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1529
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1530
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1531
void ec_fsm_change_check(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1532
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1533
    ec_command_t *command = &fsm->command;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1534
    ec_slave_t *slave = fsm->slave;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1535
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1536
    if (command->state != EC_CMD_RECEIVED) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1537
        EC_ERR("Failed to send state command to slave %i!\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1538
               fsm->slave->ring_position);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1539
        slave->state_error = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1540
        fsm->change_state = ec_fsm_change_error;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1541
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1542
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1543
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1544
    if (command->working_counter != 1) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1545
        EC_ERR("Failed to set state 0x%02X on slave %i: Slave did not"
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1546
               " respond.\n", fsm->change_new, fsm->slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1547
        slave->state_error = 1;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1548
        fsm->change_state = ec_fsm_change_error;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1549
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1550
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1551
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1552
    fsm->change_start = get_cycles();
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1553
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1554
    // read AL status from slave
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1555
    ec_command_nprd(command, slave->station_address, 0x0130, 2);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1556
    ec_master_queue_command(fsm->master, command);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1557
    fsm->change_state = ec_fsm_change_status;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1558
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1559
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1560
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1561
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1562
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1563
   Change state: STATUS.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1564
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1565
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1566
void ec_fsm_change_status(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1567
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1568
    ec_command_t *command = &fsm->command;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1569
    ec_slave_t *slave = fsm->slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1570
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1571
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1572
        EC_ERR("Failed to check state 0x%02X on slave %i.\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1573
               fsm->change_new, slave->ring_position);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1574
        slave->state_error = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1575
        fsm->change_state = ec_fsm_change_error;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1576
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1577
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1578
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1579
    slave->current_state = EC_READ_U8(command->data);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1580
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1581
    if (slave->current_state == fsm->change_new) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1582
        // state has been set successfully
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1583
        fsm->change_state = ec_fsm_change_end;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1584
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1585
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1586
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1587
    if (slave->current_state & 0x10) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1588
        // state change error
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1589
        fsm->change_new = slave->current_state & 0x0F;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1590
        EC_ERR("Failed to set state 0x%02X - Slave %i refused state change"
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1591
               " (code 0x%02X)!\n", fsm->change_new, slave->ring_position,
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1592
               slave->current_state);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1593
        // fetch AL status error code
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1594
        ec_command_nprd(command, slave->station_address, 0x0134, 2);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1595
        ec_master_queue_command(fsm->master, command);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1596
        fsm->change_state = ec_fsm_change_code;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1597
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1598
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1599
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1600
    if (get_cycles() - fsm->change_start >= (cycles_t) 10 * cpu_khz) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1601
        // timeout while checking
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1602
        slave->state_error = 1;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1603
        fsm->change_state = ec_fsm_change_error;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1604
        EC_ERR("Timeout while setting state 0x%02X on slave %i.\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1605
               fsm->change_new, slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1606
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1607
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1608
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1609
    // still old state: check again
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1610
    ec_command_nprd(command, slave->station_address, 0x0130, 2);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1611
    ec_master_queue_command(fsm->master, command);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1612
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1613
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1614
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1615
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1616
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1617
   Change state: CODE.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1618
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1619
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1620
void ec_fsm_change_code(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1621
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1622
    ec_command_t *command = &fsm->command;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1623
    ec_slave_t *slave = fsm->slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1624
    uint32_t code;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1625
    const ec_code_msg_t *al_msg;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1626
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1627
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1628
        EC_ERR("Reception of AL status code command failed.\n");
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1629
        slave->state_error = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1630
        fsm->change_state = ec_fsm_change_error;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1631
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1632
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1633
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1634
    if ((code = EC_READ_U16(command->data))) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1635
        for (al_msg = al_status_messages; al_msg->code; al_msg++) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1636
            if (al_msg->code != code) continue;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1637
            EC_ERR("AL status message 0x%04X: \"%s\".\n",
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1638
                   al_msg->code, al_msg->message);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1639
            break;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1640
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1641
        if (!al_msg->code)
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1642
            EC_ERR("Unknown AL status code 0x%04X.\n", code);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1643
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1644
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1645
    // acknowledge "old" slave state
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1646
    ec_command_npwr(command, slave->station_address, 0x0120, 2);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1647
    EC_WRITE_U16(command->data, slave->current_state);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1648
    ec_master_queue_command(fsm->master, command);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1649
    fsm->change_state = ec_fsm_change_ack;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1650
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1651
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1652
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1653
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1654
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1655
   Change state: ACK.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1656
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1657
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1658
void ec_fsm_change_ack(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1659
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1660
    ec_command_t *command = &fsm->command;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1661
    ec_slave_t *slave = fsm->slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1662
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1663
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1664
        EC_ERR("Reception of state ack command failed.\n");
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1665
        slave->state_error = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1666
        fsm->change_state = ec_fsm_change_error;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1667
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1668
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1669
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1670
    // read new AL status
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1671
    ec_command_nprd(command, slave->station_address, 0x0130, 2);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1672
    ec_master_queue_command(fsm->master, command);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1673
    fsm->change_state = ec_fsm_change_ack2;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1674
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1675
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1676
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1677
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1678
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1679
   Change state: ACK.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1680
   Acknowledge 2.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1681
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1682
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1683
void ec_fsm_change_ack2(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1684
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1685
    ec_command_t *command = &fsm->command;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1686
    ec_slave_t *slave = fsm->slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1687
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1688
    if (command->state != EC_CMD_RECEIVED || command->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1689
        EC_ERR("Reception of state ack check command failed.\n");
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1690
        slave->state_error = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1691
        fsm->change_state = ec_fsm_change_error;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1692
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1693
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1694
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1695
    slave->current_state = EC_READ_U8(command->data);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1696
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1697
    if (slave->current_state == fsm->change_new) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1698
        EC_INFO("Acknowleged state 0x%02X on slave %i.\n",
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1699
                slave->current_state, slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1700
        slave->state_error = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1701
        fsm->change_state = ec_fsm_change_error;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1702
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1703
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1704
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1705
    EC_WARN("Failed to acknowledge state 0x%02X on slave %i"
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1706
            " - Timeout!\n", fsm->change_new, slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1707
    slave->state_error = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1708
    fsm->change_state = ec_fsm_change_error;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1709
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1710
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1711
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1712
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1713
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1714
   Change state: END.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1715
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1716
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1717
void ec_fsm_change_end(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1718
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1719
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1720
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1721
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1722
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1723
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1724
   Change state: ERROR.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1725
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1726
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1727
void ec_fsm_change_error(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1728
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1729
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1730
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1731
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1732
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1733
/**
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1734
   Application layer status messages.
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1735
*/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1736
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1737
const ec_code_msg_t al_status_messages[] = {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1738
    {0x0001, "Unspecified error"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1739
    {0x0011, "Invalud requested state change"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1740
    {0x0012, "Unknown requested state"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1741
    {0x0013, "Bootstrap not supported"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1742
    {0x0014, "No valid firmware"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1743
    {0x0015, "Invalid mailbox configuration"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1744
    {0x0016, "Invalid mailbox configuration"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1745
    {0x0017, "Invalid sync manager configuration"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1746
    {0x0018, "No valid inputs available"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1747
    {0x0019, "No valid outputs"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1748
    {0x001A, "Synchronisation error"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1749
    {0x001B, "Sync manager watchdog"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1750
    {0x0020, "Slave needs cold start"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1751
    {0x0021, "Slave needs INIT"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1752
    {0x0022, "Slave needs PREOP"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1753
    {0x0023, "Slave needs SAVEOP"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1754
    {}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1755
};
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1756
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1757
/*****************************************************************************/