master/fsm.c
author Florian Pose <fp@igh-essen.com>
Fri, 01 Sep 2006 12:35:41 +0000
branchstable-1.1
changeset 1719 42ed27ae6785
parent 1717 cc1ee18207d3
child 1731 60b2aad9d40b
permissions -rw-r--r--
MERGE trunk -r516:527 -> branches/stable-1.1 (jiffies, bugfixes, pdo defines)
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"
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    44
#include "mailbox.h"
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
void ec_fsm_master_start(ec_fsm_t *);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    49
void ec_fsm_master_broadcast(ec_fsm_t *);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    50
void ec_fsm_master_read_states(ec_fsm_t *);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    51
void ec_fsm_master_validate_vendor(ec_fsm_t *);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    52
void ec_fsm_master_validate_product(ec_fsm_t *);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    53
void ec_fsm_master_rewrite_addresses(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    54
void ec_fsm_master_configure_slave(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    55
void ec_fsm_master_scan_slaves(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    56
void ec_fsm_master_write_eeprom(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    57
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    58
void ec_fsm_startup_start(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    59
void ec_fsm_startup_broadcast(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    60
void ec_fsm_startup_scan(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    61
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    62
void ec_fsm_configuration_start(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    63
void ec_fsm_configuration_conf(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    64
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    65
void ec_fsm_slavescan_start(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    66
void ec_fsm_slavescan_address(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    67
void ec_fsm_slavescan_state(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    68
void ec_fsm_slavescan_base(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    69
void ec_fsm_slavescan_datalink(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    70
void ec_fsm_slavescan_eeprom_size(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    71
void ec_fsm_slavescan_eeprom_data(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    72
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    73
void ec_fsm_slaveconf_init(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    74
void ec_fsm_slaveconf_sync(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    75
void ec_fsm_slaveconf_preop(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    76
void ec_fsm_slaveconf_fmmu(ec_fsm_t *);
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    77
void ec_fsm_slaveconf_sdoconf(ec_fsm_t *);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    78
void ec_fsm_slaveconf_saveop(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    79
void ec_fsm_slaveconf_op(ec_fsm_t *);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
void ec_fsm_sii_start_reading(ec_fsm_t *);
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
    82
void ec_fsm_sii_read_check(ec_fsm_t *);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
    83
void ec_fsm_sii_read_fetch(ec_fsm_t *);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
    84
void ec_fsm_sii_start_writing(ec_fsm_t *);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
    85
void ec_fsm_sii_write_check(ec_fsm_t *);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
    86
void ec_fsm_sii_write_check2(ec_fsm_t *);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    88
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
    89
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
    90
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
    91
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
    92
void ec_fsm_change_ack(ec_fsm_t *);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    93
void ec_fsm_change_check_ack(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    94
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    95
void ec_fsm_coe_down_start(ec_fsm_t *);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    96
void ec_fsm_coe_down_request(ec_fsm_t *);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    97
void ec_fsm_coe_down_check(ec_fsm_t *);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    98
void ec_fsm_coe_down_response(ec_fsm_t *);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    99
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   100
void ec_fsm_end(ec_fsm_t *);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   101
void ec_fsm_error(ec_fsm_t *);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   102
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   103
void ec_canopen_abort_msg(uint32_t);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   104
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
260
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
   Constructor.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   109
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   110
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   111
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
   112
                ec_master_t *master /**< EtherCAT master */
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   113
                )
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    fsm->master = master;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
    fsm->master_slaves_responding = 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    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
   119
    fsm->master_validation = 0;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   121
    ec_datagram_init(&fsm->datagram);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   122
    if (ec_datagram_prealloc(&fsm->datagram, EC_MAX_DATA_SIZE)) {
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   123
        EC_ERR("Failed to allocate FSM datagram.\n");
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
        return -1;
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
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    return 0;
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
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   132
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   133
   Destructor.
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
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   136
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
   137
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   138
    ec_datagram_clear(&fsm->datagram);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
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
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   156
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   157
   Executes the current state of the state machine.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   158
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   159
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   160
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
   161
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    fsm->master_state(fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   165
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   166
1717
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   167
/**
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   168
   Initializes the master startup state machine.
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   169
*/
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   170
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   171
void ec_fsm_startup(ec_fsm_t *fsm)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   172
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   173
    fsm->master_state = ec_fsm_startup_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   174
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   175
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   176
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   177
1717
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   178
/**
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   179
   Returns the running state of the master startup state machine.
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   180
   \return non-zero if not terminated yet.
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   181
*/
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   182
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   183
int ec_fsm_startup_running(ec_fsm_t *fsm /**< Finite state machine */)
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   184
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   185
    return fsm->master_state != ec_fsm_end &&
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   186
        fsm->master_state != ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   187
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   188
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   189
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   190
1717
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   191
/**
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   192
   Returns, if the master startup state machine terminated with success.
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   193
   \return non-zero if successful.
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   194
*/
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   195
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   196
int ec_fsm_startup_success(ec_fsm_t *fsm /**< Finite state machine */)
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   197
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   198
    return fsm->master_state == ec_fsm_end;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   199
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   200
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   201
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   202
1717
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   203
/**
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   204
   Initializes the master configuration state machine.
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   205
*/
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   206
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   207
void ec_fsm_configuration(ec_fsm_t *fsm)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   208
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   209
    fsm->master_state = ec_fsm_configuration_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   210
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   211
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   212
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   213
1717
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   214
/**
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   215
   Returns the running state of the master configuration state machine.
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   216
   \return non-zero if not terminated yet.
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   217
*/
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   218
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   219
int ec_fsm_configuration_running(ec_fsm_t *fsm /**< Finite state machine */)
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   220
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   221
    return fsm->master_state != ec_fsm_end &&
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   222
        fsm->master_state != ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   223
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   224
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   225
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   226
1717
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   227
/**
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   228
   Returns, if the master confuguration state machine terminated with success.
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   229
   \return non-zero if successful.
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   230
*/
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   231
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   232
int ec_fsm_configuration_success(ec_fsm_t *fsm /**< Finite state machine */)
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   233
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   234
    return fsm->master_state == ec_fsm_end;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   235
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   236
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
/******************************************************************************
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   238
 *  master startup state machine
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   239
 *****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   240
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   241
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   242
   Master state: START.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   243
   Starts with getting slave count and slave states.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   244
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   245
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   246
void ec_fsm_startup_start(ec_fsm_t *fsm)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   247
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   248
    ec_datagram_brd(&fsm->datagram, 0x0130, 2);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   249
    ec_master_queue_datagram(fsm->master, &fsm->datagram);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   250
    fsm->master_state = ec_fsm_startup_broadcast;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   251
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   252
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   253
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   254
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   255
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   256
   Master state: BROADCAST.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   257
   Processes the broadcast read slave count and slaves states.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   258
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   259
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   260
void ec_fsm_startup_broadcast(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   261
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   262
    ec_datagram_t *datagram = &fsm->datagram;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   263
    unsigned int i;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   264
    ec_slave_t *slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   265
    ec_master_t *master = fsm->master;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   266
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   267
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   268
        EC_ERR("Failed tor receive broadcast datagram.\n");
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   269
        fsm->master_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   270
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   271
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   272
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   273
    EC_INFO("Scanning bus.\n");
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   274
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   275
    ec_master_clear_slaves(master);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   276
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   277
    master->slave_count = datagram->working_counter;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   278
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   279
    if (!master->slave_count) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   280
        // no slaves present -> finish state machine.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   281
        fsm->master_state = ec_fsm_end;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   282
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   283
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   284
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   285
    // init slaves
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   286
    for (i = 0; i < master->slave_count; i++) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   287
        if (!(slave = (ec_slave_t *) kmalloc(sizeof(ec_slave_t),
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   288
                                             GFP_KERNEL))) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   289
            EC_ERR("Failed to allocate slave %i!\n", i);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   290
            fsm->master_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   291
            return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   292
        }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   293
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   294
        if (ec_slave_init(slave, master, i, i + 1)) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   295
            fsm->master_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   296
            return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   297
        }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   298
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   299
        if (kobject_add(&slave->kobj)) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   300
            EC_ERR("Failed to add kobject.\n");
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   301
            kobject_put(&slave->kobj); // free
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   302
            fsm->master_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   303
            return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   304
        }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   305
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   306
        list_add_tail(&slave->list, &master->slaves);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   307
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   308
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   309
    // begin scanning of slaves
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   310
    fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   311
    fsm->slave_state = ec_fsm_slavescan_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   312
    fsm->master_state = ec_fsm_startup_scan;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   313
    fsm->master_state(fsm); // execute immediately
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   314
    return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   315
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   316
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   317
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   318
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   319
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   320
   Master state: SCAN.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   321
   Executes the sub-statemachine for the scanning of a slave.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   322
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   323
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   324
void ec_fsm_startup_scan(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   325
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   326
    ec_master_t *master = fsm->master;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   327
    ec_slave_t *slave = fsm->slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   328
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   329
    fsm->slave_state(fsm); // execute slave state machine
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   330
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   331
    if (fsm->slave_state == ec_fsm_error) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   332
        EC_ERR("Slave scanning failed.\n");
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   333
        fsm->master_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   334
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   335
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   336
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   337
    if (fsm->slave_state != ec_fsm_end) return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   338
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   339
    // another slave to scan?
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   340
    if (slave->list.next != &master->slaves) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   341
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   342
        fsm->slave_state = ec_fsm_slavescan_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   343
        fsm->slave_state(fsm); // execute immediately
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   344
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   345
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   346
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   347
    EC_INFO("Bus scanning completed.\n");
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   348
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   349
    ec_master_calc_addressing(master);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   350
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   351
    fsm->master_state = ec_fsm_end;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   352
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   353
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   354
/******************************************************************************
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   355
 *  master configuration state machine
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   356
 *****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   357
1717
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   358
/**
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   359
   Master configuration state machine: START.
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   360
*/
cc1ee18207d3 MERGE trunk -r513:515 -> branches/stable-1.1 (Missing code docs)
Florian Pose <fp@igh-essen.com>
parents: 1716
diff changeset
   361
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   362
void ec_fsm_configuration_start(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   363
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   364
    ec_master_t *master = fsm->master;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   365
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   366
    if (list_empty(&master->slaves)) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   367
        fsm->master_state = ec_fsm_end;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   368
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   369
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   370
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   371
    // begin configuring slaves
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   372
    fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   373
    fsm->slave_state = ec_fsm_slaveconf_init;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   374
    fsm->change_new = EC_SLAVE_STATE_INIT;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   375
    fsm->change_state = ec_fsm_change_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   376
    fsm->master_state = ec_fsm_configuration_conf;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   377
    fsm->master_state(fsm); // execute immediately
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   378
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   379
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   380
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   381
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   382
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   383
   Master state: CONF.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   384
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   385
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   386
void ec_fsm_configuration_conf(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   387
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   388
    ec_master_t *master = fsm->master;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   389
    ec_slave_t *slave = fsm->slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   390
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   391
    fsm->slave_state(fsm); // execute slave's state machine
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   392
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   393
    if (fsm->slave_state == ec_fsm_error) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   394
        fsm->master_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   395
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   396
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   397
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   398
    if (fsm->slave_state != ec_fsm_end) return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   399
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   400
    // another slave to configure?
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   401
    if (slave->list.next != &master->slaves) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   402
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   403
        fsm->slave_state = ec_fsm_slaveconf_init;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   404
        fsm->change_new = EC_SLAVE_STATE_INIT;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   405
        fsm->change_state = ec_fsm_change_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   406
        fsm->master_state(fsm); // execute immediately
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   407
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   408
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   409
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   410
    fsm->master_state = ec_fsm_end;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   411
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   412
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   413
/******************************************************************************
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   414
 *  operation / idle state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   415
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   416
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   417
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   418
   Master state: START.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   419
   Starts with getting slave count and slave states.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   420
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   421
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   422
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
   423
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   424
    ec_datagram_brd(&fsm->datagram, 0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   425
    ec_master_queue_datagram(fsm->master, &fsm->datagram);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   426
    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
   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: BROADCAST.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   433
   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
   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_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
   437
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   438
    ec_datagram_t *datagram = &fsm->datagram;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   439
    unsigned int topology_change, states_change, i;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   440
    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
   441
    ec_master_t *master = fsm->master;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   442
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   443
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   444
        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
   445
            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
   446
            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
   447
                slave->online = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   448
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   449
        }
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   450
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   451
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   452
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   453
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   455
    topology_change = (datagram->working_counter !=
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   456
                       fsm->master_slaves_responding);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   457
    states_change = (EC_READ_U8(datagram->data) != fsm->master_slave_states);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   458
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   459
    fsm->master_slave_states = EC_READ_U8(datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   460
    fsm->master_slaves_responding = datagram->working_counter;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   461
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   462
    if (topology_change) {
262
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   463
        EC_INFO("%i slave%s responding.\n",
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   464
                fsm->master_slaves_responding,
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   465
                fsm->master_slaves_responding == 1 ? "" : "s");
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   466
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   467
        if (master->mode == EC_MASTER_MODE_OPERATION) {
262
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   468
            if (fsm->master_slaves_responding == master->slave_count) {
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   469
                fsm->master_validation = 1; // start validation later
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   470
            }
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   471
            else {
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   472
                EC_WARN("Invalid slave count. Bus in tainted state.\n");
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   473
            }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   474
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   475
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   476
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   477
    if (states_change) {
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   478
        char states[25];
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   479
        ec_state_string(fsm->master_slave_states, states);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   480
        EC_INFO("Slave states: %s.\n", states);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   481
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   482
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   483
    // topology change in idle mode: clear all slaves and scan the bus
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   484
    if (topology_change && master->mode == EC_MASTER_MODE_IDLE) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   485
        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
   486
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   487
        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
   488
        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
   489
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   490
        master->slave_count = datagram->working_counter;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   491
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   492
        if (!master->slave_count) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   493
            // 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
   494
            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
   495
            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
   496
            return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   497
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   498
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   499
        // init slaves
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   500
        for (i = 0; i < master->slave_count; i++) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   501
            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
   502
                                                 GFP_ATOMIC))) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   503
                EC_ERR("Failed to allocate slave %i!\n", i);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   504
                ec_master_clear_slaves(master);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   505
                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
   506
                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
   507
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   508
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   509
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   510
            if (ec_slave_init(slave, master, i, i + 1)) {
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   511
                // freeing of "slave" already done
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   512
                ec_master_clear_slaves(master);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   513
                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
   514
                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
   515
                return;
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
            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
   519
                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
   520
                kobject_put(&slave->kobj); // free
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   521
                ec_master_clear_slaves(master);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   522
                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
   523
                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
   524
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   525
            }
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
            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
   528
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   529
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   530
        // begin scanning of slaves
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   531
        fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   532
        fsm->slave_state = ec_fsm_slavescan_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   533
        fsm->master_state = ec_fsm_master_scan_slaves;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   534
        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
   535
        return;
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
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   538
    // 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
   539
    fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   540
    ec_datagram_nprd(&fsm->datagram, fsm->slave->station_address, 0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   541
    ec_master_queue_datagram(master, &fsm->datagram);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   542
    fsm->master_state = ec_fsm_master_read_states;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   543
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   544
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   545
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   546
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   547
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   548
   Master action: PROC_STATES.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   549
   Processes the slave states.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   550
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   551
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   552
void ec_fsm_master_action_process_states(ec_fsm_t *fsm
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   553
                                         /**< finite state machine */
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   554
                                         )
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   555
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   556
    ec_master_t *master = fsm->master;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   557
    ec_slave_t *slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   558
    char old_state[25], new_state[25];
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   559
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   560
    // check if any slaves are not in the state, they're supposed to be
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   561
    list_for_each_entry(slave, &master->slaves, list) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   562
        if (slave->error_flag ||
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   563
            !slave->online ||
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   564
            slave->requested_state == EC_SLAVE_STATE_UNKNOWN ||
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   565
            slave->current_state == slave->requested_state) continue;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   566
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   567
        ec_state_string(slave->current_state, old_state);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   568
        ec_state_string(slave->requested_state, new_state);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   569
        EC_INFO("Changing state of slave %i from %s to %s.\n",
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   570
                slave->ring_position, old_state, new_state);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   571
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   572
        fsm->slave = slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   573
        fsm->slave_state = ec_fsm_slaveconf_init;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   574
        fsm->change_new = EC_SLAVE_STATE_INIT;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   575
        fsm->change_state = ec_fsm_change_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   576
        fsm->master_state = ec_fsm_master_configure_slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   577
        fsm->master_state(fsm); // execute immediately
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   578
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   579
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   580
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   581
    // Check, if EoE processing has to be started
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   582
    ec_master_eoe_start(master);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   583
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   584
    if (master->mode == EC_MASTER_MODE_IDLE) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   585
        // nothing to configure. check for pending EEPROM write operations.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   586
        list_for_each_entry(slave, &master->slaves, list) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   587
            if (!slave->new_eeprom_data) continue;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   588
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   589
            if (!slave->online || slave->error_flag) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   590
                kfree(slave->new_eeprom_data);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   591
                slave->new_eeprom_data = NULL;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   592
                EC_ERR("Discarding EEPROM data, slave %i not ready.\n",
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   593
                       slave->ring_position);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   594
                continue;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   595
            }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   596
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   597
            // found pending EEPROM write operation. execute it!
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   598
            EC_INFO("Writing EEPROM of slave %i...\n", slave->ring_position);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   599
            fsm->sii_offset = 0x0000;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   600
            memcpy(fsm->sii_value, slave->new_eeprom_data, 2);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   601
            fsm->sii_mode = 1;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   602
            fsm->sii_state = ec_fsm_sii_start_writing;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   603
            fsm->slave = slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   604
            fsm->master_state = ec_fsm_master_write_eeprom;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   605
            fsm->master_state(fsm); // execute immediately
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   606
            return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   607
        }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   608
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   609
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   610
    // nothing to do. restart master state machine.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   611
    fsm->master_state = ec_fsm_master_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   612
    fsm->master_state(fsm); // execute immediately
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   613
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   614
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   615
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   616
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   617
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   618
   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
   619
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   620
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   621
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
   622
                                           /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   623
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   624
    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
   625
    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
   626
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   627
    // is there another slave to query?
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   628
    if (slave->list.next != &master->slaves) {
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   629
        // process next slave
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   630
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   631
        ec_datagram_nprd(&fsm->datagram, fsm->slave->station_address,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   632
                         0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   633
        ec_master_queue_datagram(master, &fsm->datagram);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   634
        fsm->master_state = ec_fsm_master_read_states;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   635
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   636
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   637
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   638
    // all slave states read
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   639
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   640
    // check, if a bus validation has to be done
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   641
    if (fsm->master_validation) {
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   642
        fsm->master_validation = 0;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   643
        list_for_each_entry(slave, &master->slaves, list) {
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   644
            if (slave->online) continue;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   645
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   646
            // At least one slave is offline. validate!
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   647
            EC_INFO("Validating bus.\n");
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   648
            fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   649
            fsm->master_state = ec_fsm_master_validate_vendor;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   650
            fsm->sii_offset = 0x0008; // vendor ID
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   651
            fsm->sii_mode = 0;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   652
            fsm->sii_state = ec_fsm_sii_start_reading;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   653
            fsm->sii_state(fsm); // execute immediately
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   654
            return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   655
        }
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   656
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   657
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   658
    ec_fsm_master_action_process_states(fsm);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   659
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   660
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   661
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   662
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   663
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   664
   Master state: STATES.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   665
   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
   666
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   667
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   668
void ec_fsm_master_read_states(ec_fsm_t *fsm /**< finite state machine */)
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   669
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   670
    ec_slave_t *slave = fsm->slave;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   671
    ec_datagram_t *datagram = &fsm->datagram;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   672
    uint8_t new_state;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   673
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   674
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   675
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   676
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   677
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   678
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   679
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   680
    // did the slave not respond to its station address?
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   681
    if (datagram->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   682
        if (slave->online) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   683
            slave->online = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   684
            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
   685
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   686
        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
   687
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   688
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   689
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   690
    // slave responded
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   691
    new_state = EC_READ_U8(datagram->data);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   692
    if (!slave->online) { // slave was offline before
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   693
        char cur_state[25];
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   694
        slave->online = 1;
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
   695
        slave->error_flag = 0; // clear error flag
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   696
        slave->current_state = new_state;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   697
        ec_state_string(slave->current_state, cur_state);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   698
        EC_INFO("Slave %i: online (%s).\n", slave->ring_position, cur_state);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   699
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   700
    else if (new_state != slave->current_state) {
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   701
        char old_state[25], cur_state[25];
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   702
        ec_state_string(slave->current_state, old_state);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   703
        ec_state_string(new_state, cur_state);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   704
        EC_INFO("Slave %i: %s -> %s.\n",
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   705
                slave->ring_position, old_state, cur_state);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   706
        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
   707
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   708
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   709
    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
   710
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   711
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   712
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   713
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   714
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   715
   Master state: VALIDATE_VENDOR.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   716
   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
   717
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   718
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   719
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
   720
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   721
    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
   722
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   723
    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
   724
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   725
    if (fsm->sii_state == ec_fsm_error) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   726
        fsm->slave->error_flag = 1;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   727
        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
   728
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   729
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   730
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   731
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   732
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   733
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   734
    if (fsm->sii_state != ec_fsm_end) return;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   735
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   736
    if (EC_READ_U32(fsm->sii_value) != slave->sii_vendor_id) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   737
        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
   738
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   739
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   740
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   741
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   742
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   743
    // 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
   744
    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
   745
    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
   746
    fsm->sii_mode = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   747
    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
   748
    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
   749
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   750
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   751
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   752
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   753
/**
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   754
   Master action: ADDRESS.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   755
   Looks for slave, that have lost their configuration and writes
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   756
   their station address, so that they can be reconfigured later.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   757
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   758
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   759
void ec_fsm_master_action_addresses(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   760
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   761
    ec_datagram_t *datagram = &fsm->datagram;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   762
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   763
    while (fsm->slave->online) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   764
        if (fsm->slave->list.next == &fsm->master->slaves) { // last slave?
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   765
            fsm->master_state = ec_fsm_master_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   766
            fsm->master_state(fsm); // execute immediately
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   767
            return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   768
        }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   769
        // check next slave
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   770
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   771
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   772
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   773
    EC_INFO("Reinitializing slave %i.\n", fsm->slave->ring_position);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   774
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   775
    // write station address
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   776
    ec_datagram_apwr(datagram, fsm->slave->ring_position, 0x0010, 2);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   777
    EC_WRITE_U16(datagram->data, fsm->slave->station_address);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   778
    ec_master_queue_datagram(fsm->master, datagram);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   779
    fsm->master_state = ec_fsm_master_rewrite_addresses;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   780
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   781
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   782
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   783
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   784
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   785
   Master state: VALIDATE_PRODUCT.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   786
   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
   787
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   788
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   789
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
   790
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   791
    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
   792
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   793
    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
   794
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   795
    if (fsm->sii_state == ec_fsm_error) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   796
        fsm->slave->error_flag = 1;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   797
        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
   798
               slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   799
        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
   800
        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
   801
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   802
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   803
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   804
    if (fsm->sii_state != ec_fsm_end) return;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   805
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   806
    if (EC_READ_U32(fsm->sii_value) != slave->sii_product_code) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   807
        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
   808
        EC_ERR("expected 0x%08X, got 0x%08X.\n", slave->sii_product_code,
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   809
               EC_READ_U32(fsm->sii_value));
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   810
        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
   811
        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
   812
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   813
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   814
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   815
    // 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
   816
    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
   817
        fsm->slave = list_entry(fsm->master->slaves.next, ec_slave_t, list);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   818
        // start writing addresses to offline slaves
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   819
        ec_fsm_master_action_addresses(fsm);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   820
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   821
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   822
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   823
    // validate next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   824
    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
   825
    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
   826
    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
   827
    fsm->sii_mode = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   828
    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
   829
    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
   830
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   831
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
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   835
   Master state: ADDRESS.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   836
   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
   837
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   838
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   839
void ec_fsm_master_rewrite_addresses(ec_fsm_t *fsm
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   840
                                     /**< finite state machine */
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   841
                                     )
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   842
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   843
    ec_slave_t *slave = fsm->slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   844
    ec_datagram_t *datagram = &fsm->datagram;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   845
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   846
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   847
        || datagram->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   848
        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
   849
               slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   850
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   851
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   852
    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
   853
        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
   854
        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
   855
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   856
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   857
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   858
    // check next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   859
    fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   860
    // Write new station address to slave
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   861
    ec_fsm_master_action_addresses(fsm);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   862
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   863
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   864
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   865
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   866
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   867
   Master state: SCAN.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   868
   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
   869
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   870
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   871
void ec_fsm_master_scan_slaves(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   872
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   873
    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
   874
    ec_slave_t *slave = fsm->slave;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   875
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   876
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   877
    fsm->slave_state(fsm); // execute slave state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   878
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   879
    if (fsm->slave_state != ec_fsm_end
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   880
        && fsm->slave_state != ec_fsm_error) return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   881
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   882
    // another slave to fetch?
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   883
    if (slave->list.next != &master->slaves) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   884
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   885
        fsm->slave_state = ec_fsm_slavescan_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   886
        fsm->slave_state(fsm); // execute immediately
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   887
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   888
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   889
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   890
    EC_INFO("Bus scanning completed.\n");
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   891
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   892
    ec_master_calc_addressing(master);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   893
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   894
    // determine initial states.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   895
    list_for_each_entry(slave, &master->slaves, list) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   896
        if (ec_slave_is_coupler(slave)) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   897
            slave->requested_state = EC_SLAVE_STATE_OP;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   898
        }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   899
        else {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   900
            if (master->mode == EC_MASTER_MODE_OPERATION)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   901
                slave->requested_state = EC_SLAVE_STATE_PREOP;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   902
            else
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   903
                slave->requested_state = EC_SLAVE_STATE_INIT;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   904
        }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   905
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   906
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   907
    fsm->master_state = ec_fsm_master_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   908
    fsm->master_state(fsm); // execute immediately
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   909
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   910
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
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   914
   Master state: CONF.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   915
   Starts configuring a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   916
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   917
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   918
void ec_fsm_master_configure_slave(ec_fsm_t *fsm
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   919
                                   /**< finite state machine */
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   920
                                   )
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   921
{
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   922
    fsm->slave_state(fsm); // execute slave's state machine
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   923
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   924
    if (fsm->slave_state != ec_fsm_end
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   925
        && fsm->slave_state != ec_fsm_error) return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   926
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   927
    ec_fsm_master_action_process_states(fsm);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   928
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   929
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   930
/*****************************************************************************/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   931
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   932
/**
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   933
   Master state: EEPROM.
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   934
*/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   935
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   936
void ec_fsm_master_write_eeprom(ec_fsm_t *fsm /**< finite state machine */)
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   937
{
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   938
    ec_slave_t *slave = fsm->slave;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   939
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   940
    fsm->sii_state(fsm); // execute SII state machine
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   941
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   942
    if (fsm->sii_state == ec_fsm_error) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   943
        fsm->slave->error_flag = 1;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   944
        EC_ERR("Failed to write EEPROM contents to slave %i.\n",
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   945
               slave->ring_position);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   946
        kfree(slave->new_eeprom_data);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   947
        slave->new_eeprom_data = NULL;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   948
        fsm->master_state = ec_fsm_master_start;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   949
        fsm->master_state(fsm); // execute immediately
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   950
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   951
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   952
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   953
    if (fsm->sii_state != ec_fsm_end) return;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   954
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   955
    fsm->sii_offset++;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   956
    if (fsm->sii_offset < slave->new_eeprom_size) {
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   957
        memcpy(fsm->sii_value, slave->new_eeprom_data + fsm->sii_offset, 2);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   958
        fsm->sii_state = ec_fsm_sii_start_writing;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   959
        fsm->sii_state(fsm); // execute immediately
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   960
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   961
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   962
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   963
    // finished writing EEPROM
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   964
    EC_INFO("Finished writing EEPROM of slave %i.\n", slave->ring_position);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   965
    kfree(slave->new_eeprom_data);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   966
    slave->new_eeprom_data = NULL;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   967
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   968
    // TODO: Evaluate new EEPROM contents!
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   969
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   970
    // restart master state machine.
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   971
    fsm->master_state = ec_fsm_master_start;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   972
    fsm->master_state(fsm); // execute immediately
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   973
    return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   974
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   975
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   976
/******************************************************************************
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   977
 *  slave scan state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   978
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   979
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   980
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   981
   Slave state: START_READING.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   982
   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
   983
   slave, according to its ring position.
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
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   986
void ec_fsm_slavescan_start(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   987
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   988
    ec_datagram_t *datagram = &fsm->datagram;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   989
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   990
    // write station address
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   991
    ec_datagram_apwr(datagram, fsm->slave->ring_position, 0x0010, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   992
    EC_WRITE_U16(datagram->data, fsm->slave->station_address);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   993
    ec_master_queue_datagram(fsm->master, datagram);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   994
    fsm->slave_state = ec_fsm_slavescan_address;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   995
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   996
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   997
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   998
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   999
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1000
   Slave state: ADDRESS.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1001
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1002
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1003
void ec_fsm_slavescan_address(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1004
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1005
    ec_datagram_t *datagram = &fsm->datagram;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1006
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1007
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1008
        || datagram->working_counter != 1) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1009
        fsm->slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1010
        fsm->slave_state = ec_fsm_error;
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1011
        EC_ERR("Failed to write station address of slave %i.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1012
               fsm->slave->ring_position);
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1013
        return;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1014
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1015
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1016
    // Read AL state
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1017
    ec_datagram_nprd(datagram, fsm->slave->station_address, 0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1018
    ec_master_queue_datagram(fsm->master, datagram);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1019
    fsm->slave_state = ec_fsm_slavescan_state;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1020
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1021
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1022
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1023
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1024
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1025
   Slave state: STATE.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1026
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1027
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1028
void ec_fsm_slavescan_state(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1029
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1030
    ec_datagram_t *datagram = &fsm->datagram;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1031
    ec_slave_t *slave = fsm->slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1032
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1033
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1034
        || datagram->working_counter != 1) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
  1035
        fsm->slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1036
        fsm->slave_state = ec_fsm_error;
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1037
        EC_ERR("Failed to read AL state of slave %i.\n",
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1038
               fsm->slave->ring_position);
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1039
        return;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1040
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1041
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1042
    slave->current_state = EC_READ_U8(datagram->data);
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1043
    if (slave->current_state & EC_ACK) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1044
        EC_WARN("Slave %i has state error bit set (0x%02X)!\n",
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1045
                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
  1046
        slave->current_state &= 0x0F;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1047
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1048
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1049
    // read base data
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1050
    ec_datagram_nprd(datagram, fsm->slave->station_address, 0x0000, 6);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1051
    ec_master_queue_datagram(fsm->master, datagram);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1052
    fsm->slave_state = ec_fsm_slavescan_base;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1053
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1054
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1055
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1056
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1057
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1058
   Slave state: BASE.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1059
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1060
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1061
void ec_fsm_slavescan_base(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1062
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1063
    ec_datagram_t *datagram = &fsm->datagram;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1064
    ec_slave_t *slave = fsm->slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1065
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1066
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1067
        || datagram->working_counter != 1) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
  1068
        fsm->slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1069
        fsm->slave_state = ec_fsm_error;
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1070
        EC_ERR("Failed to read base data of slave %i.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1071
               slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1072
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1073
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1074
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1075
    slave->base_type       = EC_READ_U8 (datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1076
    slave->base_revision   = EC_READ_U8 (datagram->data + 1);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1077
    slave->base_build      = EC_READ_U16(datagram->data + 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1078
    slave->base_fmmu_count = EC_READ_U8 (datagram->data + 4);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1079
    slave->base_sync_count = EC_READ_U8 (datagram->data + 5);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1080
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1081
    if (slave->base_fmmu_count > EC_MAX_FMMUS)
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1082
        slave->base_fmmu_count = EC_MAX_FMMUS;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1083
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1084
    // read data link status
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1085
    ec_datagram_nprd(datagram, slave->station_address, 0x0110, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1086
    ec_master_queue_datagram(slave->master, datagram);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1087
    fsm->slave_state = ec_fsm_slavescan_datalink;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1088
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1089
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1090
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1091
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1092
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1093
   Slave state: DATALINK.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1094
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1095
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1096
void ec_fsm_slavescan_datalink(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1097
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1098
    ec_datagram_t *datagram = &fsm->datagram;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1099
    ec_slave_t *slave = fsm->slave;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1100
    uint16_t dl_status;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1101
    unsigned int i;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1102
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1103
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1104
        || datagram->working_counter != 1) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
  1105
        fsm->slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1106
        fsm->slave_state = ec_fsm_error;
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1107
        EC_ERR("Failed to read DL status of slave %i.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1108
               slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1109
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1110
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1111
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1112
    dl_status = EC_READ_U16(datagram->data);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1113
    for (i = 0; i < 4; i++) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1114
        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
  1115
        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
  1116
        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
  1117
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1118
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1119
    // Start fetching EEPROM size
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1120
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1121
    fsm->sii_offset = 0x0040; // first category header
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1122
    fsm->sii_mode = 1;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1123
    fsm->sii_state = ec_fsm_sii_start_reading;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1124
    fsm->slave_state = ec_fsm_slavescan_eeprom_size;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1125
    fsm->slave_state(fsm); // execute state immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1126
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1127
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1128
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1129
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1130
/**
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1131
   Slave state: EEPROM_SIZE.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1132
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1133
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1134
void ec_fsm_slavescan_eeprom_size(ec_fsm_t *fsm /**< finite state machine */)
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1135
{
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1136
    ec_slave_t *slave = fsm->slave;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1137
    uint16_t cat_type, cat_size;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1138
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1139
    // execute SII state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1140
    fsm->sii_state(fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1141
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1142
    if (fsm->sii_state == ec_fsm_error) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1143
        fsm->slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1144
        fsm->slave_state = ec_fsm_error;
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1145
        EC_ERR("Failed to read EEPROM size of slave %i.\n",
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1146
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1147
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1148
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1149
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1150
    if (fsm->sii_state != ec_fsm_end) return;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1151
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1152
    cat_type = EC_READ_U16(fsm->sii_value);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1153
    cat_size = EC_READ_U16(fsm->sii_value + 2);
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1154
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1155
    if (cat_type != 0xFFFF) { // not the last category
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1156
        fsm->sii_offset += cat_size + 2;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1157
        fsm->sii_state = ec_fsm_sii_start_reading;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1158
        fsm->sii_state(fsm); // execute state immediately
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1159
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1160
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1161
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1162
    slave->eeprom_size = (fsm->sii_offset + 1) * 2;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1163
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1164
    if (slave->eeprom_data) {
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1165
        EC_INFO("Freeing old EEPROM data on slave %i...\n",
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1166
                slave->ring_position);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1167
        kfree(slave->eeprom_data);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1168
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1169
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1170
    if (!(slave->eeprom_data =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1171
          (uint8_t *) kmalloc(slave->eeprom_size, GFP_ATOMIC))) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
  1172
        fsm->slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1173
        fsm->slave_state = ec_fsm_error;
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1174
        EC_ERR("Failed to allocate EEPROM data on slave %i.\n",
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1175
               slave->ring_position);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1176
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1177
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1178
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1179
    // Start fetching EEPROM contents
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1180
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1181
    fsm->sii_offset = 0x0000;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1182
    fsm->sii_mode = 1;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1183
    fsm->sii_state = ec_fsm_sii_start_reading;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1184
    fsm->slave_state = ec_fsm_slavescan_eeprom_data;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1185
    fsm->slave_state(fsm); // execute state immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1186
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1187
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1188
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1189
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1190
/**
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1191
   Slave state: EEPROM_DATA.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1192
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1193
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1194
void ec_fsm_slavescan_eeprom_data(ec_fsm_t *fsm /**< finite state machine */)
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1195
{
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1196
    ec_slave_t *slave = fsm->slave;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1197
    uint16_t *cat_word, cat_type, cat_size;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1198
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1199
    // execute SII state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1200
    fsm->sii_state(fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1201
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1202
    if (fsm->sii_state == ec_fsm_error) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1203
        fsm->slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1204
        fsm->slave_state = ec_fsm_error;
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1205
        EC_ERR("Failed to fetch EEPROM contents of slave %i.\n",
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1206
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1207
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1208
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1209
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1210
    if (fsm->sii_state != ec_fsm_end) return;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1211
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1212
    // 2 words fetched
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1213
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1214
    if (fsm->sii_offset + 2 <= slave->eeprom_size / 2) { // 2 words fit
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1215
        memcpy(slave->eeprom_data + fsm->sii_offset * 2, fsm->sii_value, 4);
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1216
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1217
    else { // copy the last word
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1218
        memcpy(slave->eeprom_data + fsm->sii_offset * 2, fsm->sii_value, 2);
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1219
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1220
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1221
    if (fsm->sii_offset + 2 < slave->eeprom_size / 2) {
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1222
        // fetch the next 2 words
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1223
        fsm->sii_offset += 2;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1224
        fsm->sii_state = ec_fsm_sii_start_reading;
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1225
        fsm->sii_state(fsm); // execute state immediately
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1226
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1227
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1228
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1229
    // Evaluate EEPROM contents
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1230
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1231
    slave->sii_alias =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1232
        EC_READ_U16(slave->eeprom_data + 2 * 0x0004);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1233
    slave->sii_vendor_id =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1234
        EC_READ_U32(slave->eeprom_data + 2 * 0x0008);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1235
    slave->sii_product_code =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1236
        EC_READ_U32(slave->eeprom_data + 2 * 0x000A);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1237
    slave->sii_revision_number =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1238
        EC_READ_U32(slave->eeprom_data + 2 * 0x000C);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1239
    slave->sii_serial_number =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1240
        EC_READ_U32(slave->eeprom_data + 2 * 0x000E);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1241
    slave->sii_rx_mailbox_offset =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1242
        EC_READ_U16(slave->eeprom_data + 2 * 0x0018);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1243
    slave->sii_rx_mailbox_size =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1244
        EC_READ_U16(slave->eeprom_data + 2 * 0x0019);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1245
    slave->sii_tx_mailbox_offset =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1246
        EC_READ_U16(slave->eeprom_data + 2 * 0x001A);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1247
    slave->sii_tx_mailbox_size =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1248
        EC_READ_U16(slave->eeprom_data + 2 * 0x001B);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1249
    slave->sii_mailbox_protocols =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1250
        EC_READ_U16(slave->eeprom_data + 2 * 0x001C);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1251
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1252
    // evaluate category data
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1253
    cat_word = (uint16_t *) slave->eeprom_data + 0x0040;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1254
    while (EC_READ_U16(cat_word) != 0xFFFF) {
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1255
        cat_type = EC_READ_U16(cat_word) & 0x7FFF;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1256
        cat_size = EC_READ_U16(cat_word + 1);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1257
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1258
        switch (cat_type) {
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1259
            case 0x000A:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1260
                if (ec_slave_fetch_strings(slave, (uint8_t *) (cat_word + 2)))
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1261
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1262
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1263
            case 0x001E:
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1264
                ec_slave_fetch_general(slave, (uint8_t *) (cat_word + 2));
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1265
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1266
            case 0x0028:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1267
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1268
            case 0x0029:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1269
                if (ec_slave_fetch_sync(slave, (uint8_t *) (cat_word + 2),
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1270
                                        cat_size))
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1271
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1272
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1273
            case 0x0032:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1274
                if (ec_slave_fetch_pdo(slave, (uint8_t *) (cat_word + 2),
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1275
                                       cat_size, EC_TX_PDO))
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1276
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1277
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1278
            case 0x0033:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1279
                if (ec_slave_fetch_pdo(slave, (uint8_t *) (cat_word + 2),
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1280
                                       cat_size, EC_RX_PDO))
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1281
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1282
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1283
            default:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1284
                EC_WARN("Unknown category type 0x%04X in slave %i.\n",
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1285
                        cat_type, slave->ring_position);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1286
        }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1287
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1288
        cat_word += cat_size + 2;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1289
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1290
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1291
    fsm->slave_state = ec_fsm_end;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1292
    return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1293
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1294
end:
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1295
    EC_ERR("Failed to analyze category data.\n");
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
  1296
    fsm->slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1297
    fsm->slave_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1298
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1299
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1300
/******************************************************************************
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1301
 *  slave configuration state machine
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1302
 *****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1303
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1304
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1305
   Slave state: INIT.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1306
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1307
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1308
void ec_fsm_slaveconf_init(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1309
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1310
    ec_slave_t *slave = fsm->slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1311
    ec_datagram_t *datagram = &fsm->datagram;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1312
    const ec_sii_sync_t *sync;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1313
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1314
    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
  1315
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1316
    if (fsm->change_state == ec_fsm_error) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1317
        slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1318
        fsm->slave_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1319
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1320
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1321
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1322
    if (fsm->change_state != ec_fsm_end) return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1323
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1324
    // 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
  1325
    if (slave->current_state == slave->requested_state) {
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1326
        fsm->slave_state = ec_fsm_end; // successful
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1327
        return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1328
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1329
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1330
    // 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
  1331
    //ec_slave_check_crc(slave);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1332
    // TODO: Implement state machine for CRC checking.
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1333
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1334
    if (!slave->base_sync_count) { // no sync managers
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1335
        fsm->slave_state = ec_fsm_slaveconf_preop;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1336
        fsm->change_new = EC_SLAVE_STATE_PREOP;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1337
        fsm->change_state = ec_fsm_change_start;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1338
        fsm->change_state(fsm); // execute immediately
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1339
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1340
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1341
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1342
    // configure sync managers
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1343
    ec_datagram_npwr(datagram, slave->station_address, 0x0800,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1344
                     EC_SYNC_SIZE * slave->base_sync_count);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1345
    memset(datagram->data, 0x00, EC_SYNC_SIZE * slave->base_sync_count);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1346
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1347
    list_for_each_entry(sync, &slave->sii_syncs, list) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1348
        if (sync->index >= slave->base_sync_count) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1349
            EC_ERR("Invalid sync manager configuration found!");
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1350
            fsm->slave->error_flag = 1;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1351
            fsm->slave_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1352
            return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1353
        }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1354
        ec_sync_config(sync, slave,
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1355
                       datagram->data + EC_SYNC_SIZE * sync->index);
251
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
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1358
    ec_master_queue_datagram(fsm->master, datagram);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1359
    fsm->slave_state = ec_fsm_slaveconf_sync;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1360
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1361
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1362
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1363
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1364
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1365
   Slave state: SYNC.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1366
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1367
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1368
void ec_fsm_slaveconf_sync(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1369
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1370
    ec_datagram_t *datagram = &fsm->datagram;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1371
    ec_slave_t *slave = fsm->slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1372
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1373
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1374
        || datagram->working_counter != 1) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1375
        slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1376
        fsm->slave_state = ec_fsm_error;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1377
        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
  1378
               slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1379
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1380
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1381
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1382
    fsm->slave_state = ec_fsm_slaveconf_preop;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1383
    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
  1384
    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
  1385
    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
  1386
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1387
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1388
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1389
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1390
/**
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1391
   Slave state: PREOP.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1392
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1393
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1394
void ec_fsm_slaveconf_preop(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1395
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1396
    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
  1397
    ec_master_t *master = fsm->master;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1398
    ec_datagram_t *datagram = &fsm->datagram;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1399
    unsigned int j;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1400
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1401
    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
  1402
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1403
    if (fsm->change_state == ec_fsm_error) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1404
        slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1405
        fsm->slave_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1406
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1407
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1408
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1409
    if (fsm->change_state != ec_fsm_end) return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1410
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1411
    // 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
  1412
    if (slave->current_state == slave->requested_state) {
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1413
        fsm->slave_state = ec_fsm_end; // successful
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1414
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1415
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1416
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1417
    if (!slave->base_fmmu_count) { // skip FMMU configuration
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1418
        if (list_empty(&slave->sdo_confs)) { // skip SDO configuration
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1419
            fsm->slave_state = ec_fsm_slaveconf_saveop;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1420
            fsm->change_new = EC_SLAVE_STATE_SAVEOP;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1421
            fsm->change_state = ec_fsm_change_start;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1422
            fsm->change_state(fsm); // execute immediately
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1423
            return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1424
        }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1425
        fsm->slave_state = ec_fsm_slaveconf_sdoconf;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1426
        fsm->sdodata = list_entry(slave->sdo_confs.next, ec_sdo_data_t, list);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1427
        fsm->coe_state = ec_fsm_coe_down_start;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1428
        fsm->coe_state(fsm); // execute immediately
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1429
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1430
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1431
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1432
    // configure FMMUs
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1433
    ec_datagram_npwr(datagram, slave->station_address,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1434
                     0x0600, EC_FMMU_SIZE * slave->base_fmmu_count);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1435
    memset(datagram->data, 0x00, EC_FMMU_SIZE * slave->base_fmmu_count);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1436
    for (j = 0; j < slave->fmmu_count; j++) {
275
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 269
diff changeset
  1437
        ec_fmmu_config(&slave->fmmus[j], slave,
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1438
                       datagram->data + EC_FMMU_SIZE * j);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1439
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1440
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1441
    ec_master_queue_datagram(master, datagram);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1442
    fsm->slave_state = ec_fsm_slaveconf_fmmu;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1443
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1444
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1445
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1446
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1447
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1448
   Slave state: FMMU.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1449
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1450
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1451
void ec_fsm_slaveconf_fmmu(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1452
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1453
    ec_datagram_t *datagram = &fsm->datagram;
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1454
    ec_slave_t *slave = fsm->slave;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1455
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1456
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1457
        || datagram->working_counter != 1) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
  1458
        fsm->slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1459
        fsm->slave_state = ec_fsm_error;
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1460
        EC_ERR("Failed to set FMMUs on slave %i.\n",
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1461
               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
  1462
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1463
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1464
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1465
    // No CoE configuration to be applied? Jump to SAVEOP state.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1466
    if (list_empty(&slave->sdo_confs)) { // skip SDO configuration
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1467
        // set state to SAVEOP
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1468
        fsm->slave_state = ec_fsm_slaveconf_saveop;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1469
        fsm->change_new = EC_SLAVE_STATE_SAVEOP;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1470
        fsm->change_state = ec_fsm_change_start;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1471
        fsm->change_state(fsm); // execute immediately
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1472
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1473
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1474
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1475
    fsm->slave_state = ec_fsm_slaveconf_sdoconf;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1476
    fsm->sdodata = list_entry(slave->sdo_confs.next, ec_sdo_data_t, list);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1477
    fsm->coe_state = ec_fsm_coe_down_start;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1478
    fsm->coe_state(fsm); // execute immediately
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1479
}
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1480
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1481
/*****************************************************************************/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1482
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1483
/**
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1484
   Slave state: SDOCONF.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1485
*/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1486
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1487
void ec_fsm_slaveconf_sdoconf(ec_fsm_t *fsm /**< finite state machine */)
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1488
{
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1489
    fsm->coe_state(fsm); // execute CoE state machine
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1490
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1491
    if (fsm->coe_state == ec_fsm_error) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1492
        fsm->slave->error_flag = 1;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1493
        fsm->slave_state = ec_fsm_error;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1494
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1495
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1496
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1497
    if (fsm->coe_state != ec_fsm_end) return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1498
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1499
    // Another SDO to configure?
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1500
    if (fsm->sdodata->list.next != &fsm->slave->sdo_confs) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1501
        fsm->sdodata = list_entry(fsm->sdodata->list.next,
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1502
                                  ec_sdo_data_t, list);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1503
        fsm->coe_state = ec_fsm_coe_down_start;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1504
        fsm->coe_state(fsm); // execute immediately
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1505
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1506
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1507
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1508
    // All SDOs are now configured.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  1509
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1510
    // set state to SAVEOP
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1511
    fsm->slave_state = ec_fsm_slaveconf_saveop;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1512
    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
  1513
    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
  1514
    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
  1515
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1516
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
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1519
/**
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1520
   Slave state: SAVEOP.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1521
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1522
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1523
void ec_fsm_slaveconf_saveop(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1524
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1525
    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
  1526
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1527
    if (fsm->change_state == ec_fsm_error) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1528
        fsm->slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1529
        fsm->slave_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1530
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1531
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1532
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1533
    if (fsm->change_state != ec_fsm_end) return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1534
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1535
    // 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
  1536
    if (fsm->slave->current_state == fsm->slave->requested_state) {
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1537
        fsm->slave_state = ec_fsm_end; // successful
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1538
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1539
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1540
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1541
    // set state to OP
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1542
    fsm->slave_state = ec_fsm_slaveconf_op;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1543
    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
  1544
    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
  1545
    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
  1546
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1547
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1548
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1549
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1550
/**
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1551
   Slave state: OP
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1552
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1553
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1554
void ec_fsm_slaveconf_op(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1555
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1556
    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
  1557
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1558
    if (fsm->change_state == ec_fsm_error) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1559
        fsm->slave->error_flag = 1;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1560
        fsm->slave_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1561
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1562
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1563
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1564
    if (fsm->change_state != ec_fsm_end) return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1565
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1566
    // slave is now in OP
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1567
    fsm->slave_state = ec_fsm_end; // successful
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1568
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1569
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1570
/******************************************************************************
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1571
 *  SII state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1572
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1573
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1574
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1575
   SII state: START_READING.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1576
   Starts reading the slave information interface.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1577
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1578
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1579
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
  1580
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1581
    ec_datagram_t *datagram = &fsm->datagram;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1582
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1583
    // initiate read operation
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1584
    if (fsm->sii_mode) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1585
        ec_datagram_npwr(datagram, fsm->slave->station_address, 0x502, 4);
260
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
    else {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1588
        ec_datagram_apwr(datagram, fsm->slave->ring_position, 0x502, 4);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1589
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1590
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1591
    EC_WRITE_U8 (datagram->data,     0x00); // read-only access
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1592
    EC_WRITE_U8 (datagram->data + 1, 0x01); // request read operation
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1593
    EC_WRITE_U16(datagram->data + 2, fsm->sii_offset);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1594
    ec_master_queue_datagram(fsm->master, datagram);
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1595
    fsm->sii_state = ec_fsm_sii_read_check;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1596
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1597
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1598
/*****************************************************************************/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1599
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1600
/**
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1601
   SII state: READ_CHECK.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1602
   Checks, if the SII-read-datagram has been sent and issues a fetch datagram.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1603
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1604
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1605
void ec_fsm_sii_read_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
  1606
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1607
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1608
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1609
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1610
        || datagram->working_counter != 1) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1611
        EC_ERR("SII: Reception of read datagram failed.\n");
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1612
        fsm->sii_state = ec_fsm_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1613
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1614
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1615
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1616
    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
  1617
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1618
    // issue check/fetch datagram
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1619
    if (fsm->sii_mode) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1620
        ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 10);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1621
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1622
    else {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1623
        ec_datagram_aprd(datagram, fsm->slave->ring_position, 0x502, 10);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1624
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1625
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1626
    ec_master_queue_datagram(fsm->master, datagram);
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1627
    fsm->sii_state = ec_fsm_sii_read_fetch;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1628
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1629
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1630
/*****************************************************************************/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1631
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1632
/**
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1633
   SII state: READ_FETCH.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1634
   Fetches the result of an SII-read datagram.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1635
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1636
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1637
void ec_fsm_sii_read_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
  1638
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1639
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1640
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1641
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1642
        || datagram->working_counter != 1) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1643
        EC_ERR("SII: Reception of check/fetch datagram failed.\n");
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1644
        fsm->sii_state = ec_fsm_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1645
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1646
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1647
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1648
    // check "busy bit"
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1649
    if (EC_READ_U8(datagram->data + 1) & 0x81) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1650
        // still busy... timeout?
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1651
        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
  1652
            EC_ERR("SII: Timeout.\n");
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1653
            fsm->sii_state = ec_fsm_error;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1654
#if 0
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1655
            EC_DBG("SII busy: %02X %02X %02X %02X\n",
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1656
                   EC_READ_U8(datagram->data + 0),
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1657
                   EC_READ_U8(datagram->data + 1),
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1658
                   EC_READ_U8(datagram->data + 2),
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1659
                   EC_READ_U8(datagram->data + 3));
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1660
#endif
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1661
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1662
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1663
        // issue check/fetch datagram again
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1664
        if (fsm->sii_mode) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1665
            ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 10);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1666
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1667
        else {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1668
            ec_datagram_aprd(datagram, fsm->slave->ring_position, 0x502, 10);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1669
        }
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1670
        ec_master_queue_datagram(fsm->master, datagram);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1671
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1672
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1673
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1674
#if 0
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1675
    EC_DBG("SII rec: %02X %02X %02X %02X - %02X %02X %02X %02X\n",
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1676
           EC_READ_U8(datagram->data + 0), EC_READ_U8(datagram->data + 1),
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1677
           EC_READ_U8(datagram->data + 2), EC_READ_U8(datagram->data + 3),
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1678
           EC_READ_U8(datagram->data + 6), EC_READ_U8(datagram->data + 7),
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1679
           EC_READ_U8(datagram->data + 8), EC_READ_U8(datagram->data + 9));
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1680
#endif
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
    // SII value received.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1683
    memcpy(fsm->sii_value, datagram->data + 6, 4);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1684
    fsm->sii_state = ec_fsm_end;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1685
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1686
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1687
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1688
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1689
/**
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1690
   SII state: START_WRITING.
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1691
   Starts reading the slave information interface.
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1692
*/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1693
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1694
void ec_fsm_sii_start_writing(ec_fsm_t *fsm /**< finite state machine */)
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1695
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1696
    ec_datagram_t *datagram = &fsm->datagram;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1697
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1698
    // initiate write operation
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1699
    ec_datagram_npwr(datagram, fsm->slave->station_address, 0x502, 8);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1700
    EC_WRITE_U8 (datagram->data,     0x01); // enable write access
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1701
    EC_WRITE_U8 (datagram->data + 1, 0x02); // request write operation
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1702
    EC_WRITE_U32(datagram->data + 2, fsm->sii_offset);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1703
    memcpy(datagram->data + 6, fsm->sii_value, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1704
    ec_master_queue_datagram(fsm->master, datagram);
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1705
    fsm->sii_state = ec_fsm_sii_write_check;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1706
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1707
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1708
/*****************************************************************************/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1709
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1710
/**
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1711
   SII state: WRITE_CHECK.
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1712
*/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1713
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1714
void ec_fsm_sii_write_check(ec_fsm_t *fsm /**< finite state machine */)
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1715
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1716
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1717
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1718
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1719
        || datagram->working_counter != 1) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1720
        EC_ERR("SII: Reception of write datagram failed.\n");
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1721
        fsm->sii_state = ec_fsm_error;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1722
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1723
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1724
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1725
    fsm->sii_start = get_cycles();
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1726
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1727
    // issue check/fetch datagram
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1728
    ec_datagram_nprd(datagram, fsm->slave->station_address, 0x502, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1729
    ec_master_queue_datagram(fsm->master, datagram);
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1730
    fsm->sii_state = ec_fsm_sii_write_check2;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1731
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1732
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1733
/*****************************************************************************/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1734
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1735
/**
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1736
   SII state: WRITE_CHECK2.
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1737
*/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1738
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1739
void ec_fsm_sii_write_check2(ec_fsm_t *fsm /**< finite state machine */)
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1740
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1741
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1742
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1743
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1744
        || datagram->working_counter != 1) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1745
        EC_ERR("SII: Reception of write check datagram failed.\n");
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1746
        fsm->sii_state = ec_fsm_error;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1747
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1748
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1749
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1750
    if (EC_READ_U8(datagram->data + 1) & 0x82) {
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1751
        // still busy... timeout?
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1752
        if (get_cycles() - fsm->sii_start >= (cycles_t) 10 * cpu_khz) {
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1753
            EC_ERR("SII: Write timeout.\n");
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1754
            fsm->sii_state = ec_fsm_error;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1755
        }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1756
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1757
        // issue check/fetch datagram again
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1758
        ec_master_queue_datagram(fsm->master, datagram);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1759
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1760
    else if (EC_READ_U8(datagram->data + 1) & 0x40) {
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1761
        EC_ERR("SII: Write operation failed!\n");
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1762
        fsm->sii_state = ec_fsm_error;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1763
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1764
    else { // success
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1765
        fsm->sii_state = ec_fsm_end;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1766
    }
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1767
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1768
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1769
/******************************************************************************
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1770
 *  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
  1771
 *****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1772
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1773
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1774
   Change state: START.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1775
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1776
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1777
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
  1778
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1779
    ec_datagram_t *datagram = &fsm->datagram;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1780
    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
  1781
1719
42ed27ae6785 MERGE trunk -r516:527 -> branches/stable-1.1 (jiffies, bugfixes, pdo defines)
Florian Pose <fp@igh-essen.com>
parents: 1717
diff changeset
  1782
    fsm->change_jiffies = jiffies;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1783
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1784
    // write new state to slave
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1785
    ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1786
    EC_WRITE_U16(datagram->data, fsm->change_new);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1787
    ec_master_queue_datagram(fsm->master, datagram);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1788
    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
  1789
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1790
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1791
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1792
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1793
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1794
   Change state: CHECK.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1795
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1796
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1797
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
  1798
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1799
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1800
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1801
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1802
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1803
        fsm->change_state = ec_fsm_error;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1804
        EC_ERR("Failed to send state datagram to slave %i!\n",
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1805
               fsm->slave->ring_position);
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1806
        return;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1807
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1808
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1809
    if (datagram->working_counter != 1) {
1719
42ed27ae6785 MERGE trunk -r516:527 -> branches/stable-1.1 (jiffies, bugfixes, pdo defines)
Florian Pose <fp@igh-essen.com>
parents: 1717
diff changeset
  1810
        if (jiffies - fsm->change_jiffies >= 3 * HZ) {
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1811
            fsm->change_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1812
            EC_ERR("Failed to set state 0x%02X on slave %i: Slave did not"
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1813
                   " respond.\n", fsm->change_new, fsm->slave->ring_position);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1814
            return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1815
        }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1816
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1817
        // repeat writing new state to slave
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1818
        ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1819
        EC_WRITE_U16(datagram->data, fsm->change_new);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1820
        ec_master_queue_datagram(fsm->master, datagram);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1821
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1822
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1823
1719
42ed27ae6785 MERGE trunk -r516:527 -> branches/stable-1.1 (jiffies, bugfixes, pdo defines)
Florian Pose <fp@igh-essen.com>
parents: 1717
diff changeset
  1824
    fsm->change_jiffies = jiffies;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1825
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1826
    // read AL status from slave
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1827
    ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1828
    ec_master_queue_datagram(fsm->master, datagram);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1829
    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
  1830
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1831
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1832
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1833
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1834
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1835
   Change state: STATUS.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1836
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1837
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1838
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
  1839
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1840
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1841
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1842
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1843
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1844
        || datagram->working_counter != 1) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1845
        fsm->change_state = ec_fsm_error;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1846
        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
  1847
               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
  1848
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1849
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1850
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1851
    slave->current_state = EC_READ_U8(datagram->data);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1852
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1853
    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
  1854
        // state has been set successfully
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1855
        fsm->change_state = ec_fsm_end;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1856
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1857
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1858
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1859
    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
  1860
        // state change error
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1861
        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
  1862
        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
  1863
               " (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
  1864
               slave->current_state);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1865
        // fetch AL status error code
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1866
        ec_datagram_nprd(datagram, slave->station_address, 0x0134, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1867
        ec_master_queue_datagram(fsm->master, datagram);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1868
        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
  1869
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1870
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1871
1719
42ed27ae6785 MERGE trunk -r516:527 -> branches/stable-1.1 (jiffies, bugfixes, pdo defines)
Florian Pose <fp@igh-essen.com>
parents: 1717
diff changeset
  1872
    if (jiffies - fsm->change_jiffies >= 100 * HZ / 1000) { // 100ms
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1873
        // timeout while checking
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1874
        fsm->change_state = ec_fsm_error;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1875
        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
  1876
               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
  1877
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1878
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1879
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1880
    // still old state: check again
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1881
    ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1882
    ec_master_queue_datagram(fsm->master, datagram);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1883
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1884
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1885
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1886
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1887
/**
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1888
   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
  1889
*/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1890
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1891
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
  1892
    {0x0001, "Unspecified error"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1893
    {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
  1894
    {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
  1895
    {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
  1896
    {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
  1897
    {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
  1898
    {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
  1899
    {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
  1900
    {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
  1901
    {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
  1902
    {0x001A, "Synchronisation error"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1903
    {0x001B, "Sync manager watchdog"},
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1904
    {0x001C, "Invalid sync manager types"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1905
    {0x001D, "Invalid output configuration"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1906
    {0x001E, "Invalid input configuration"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1907
    {0x001F, "Invalid watchdog configuration"},
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1908
    {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
  1909
    {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
  1910
    {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
  1911
    {0x0023, "Slave needs SAVEOP"},
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1912
    {0x0030, "Invalid DC SYNCH configuration"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1913
    {0x0031, "Invalid DC latch configuration"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1914
    {0x0032, "PLL error"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1915
    {0x0033, "Invalid DC IO error"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1916
    {0x0034, "Invalid DC timeout error"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1917
    {0x0042, "MBOX EOE"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1918
    {0x0043, "MBOX COE"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1919
    {0x0044, "MBOX FOE"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1920
    {0x0045, "MBOX SOE"},
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1921
    {0x004F, "MBOX VOE"},
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1922
    {}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1923
};
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1924
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1925
/*****************************************************************************/
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1926
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1927
/**
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1928
   Change state: CODE.
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1929
*/
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1930
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1931
void ec_fsm_change_code(ec_fsm_t *fsm /**< finite state machine */)
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1932
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1933
    ec_datagram_t *datagram = &fsm->datagram;
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1934
    ec_slave_t *slave = fsm->slave;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1935
    uint32_t code;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1936
    const ec_code_msg_t *al_msg;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1937
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1938
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1939
        || datagram->working_counter != 1) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1940
        fsm->change_state = ec_fsm_error;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1941
        EC_ERR("Reception of AL status code datagram failed.\n");
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1942
        return;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1943
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1944
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1945
    if ((code = EC_READ_U16(datagram->data))) {
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1946
        for (al_msg = al_status_messages; al_msg->code; al_msg++) {
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1947
            if (al_msg->code != code) continue;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1948
            EC_ERR("AL status message 0x%04X: \"%s\".\n",
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1949
                   al_msg->code, al_msg->message);
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1950
            break;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1951
        }
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1952
        if (!al_msg->code)
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1953
            EC_ERR("Unknown AL status code 0x%04X.\n", code);
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1954
    }
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1955
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1956
    // acknowledge "old" slave state
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1957
    ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1958
    EC_WRITE_U16(datagram->data, slave->current_state);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1959
    ec_master_queue_datagram(fsm->master, datagram);
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1960
    fsm->change_state = ec_fsm_change_ack;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1961
}
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1962
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1963
/*****************************************************************************/
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1964
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1965
/**
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1966
   Change state: ACK.
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1967
*/
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1968
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1969
void ec_fsm_change_ack(ec_fsm_t *fsm /**< finite state machine */)
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1970
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1971
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1972
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1973
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1974
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1975
        || datagram->working_counter != 1) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1976
        fsm->change_state = ec_fsm_error;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1977
        EC_ERR("Reception of state ack datagram failed.\n");
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1978
        return;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1979
    }
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1980
1719
42ed27ae6785 MERGE trunk -r516:527 -> branches/stable-1.1 (jiffies, bugfixes, pdo defines)
Florian Pose <fp@igh-essen.com>
parents: 1717
diff changeset
  1981
    fsm->change_jiffies = jiffies;
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1982
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1983
    // read new AL status
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1984
    ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1985
    ec_master_queue_datagram(fsm->master, datagram);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1986
    fsm->change_state = ec_fsm_change_check_ack;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1987
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1988
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1989
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1990
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1991
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1992
   Change state: CHECK ACK.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1993
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1994
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1995
void ec_fsm_change_check_ack(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1996
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1997
    ec_datagram_t *datagram = &fsm->datagram;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1998
    ec_slave_t *slave = fsm->slave;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  1999
    ec_slave_state_t ack_state;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2000
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2001
    if (datagram->state != EC_DATAGRAM_RECEIVED
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2002
        || datagram->working_counter != 1) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2003
        fsm->change_state = ec_fsm_error;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2004
        EC_ERR("Reception of state ack check datagram failed.\n");
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2005
        return;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2006
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2007
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2008
    ack_state = EC_READ_U8(datagram->data);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2009
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2010
    if (ack_state == slave->current_state) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2011
        fsm->change_state = ec_fsm_error;
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2012
        EC_INFO("Acknowleged state 0x%02X on slave %i.\n",
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2013
                slave->current_state, slave->ring_position);
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  2014
        return;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  2015
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  2016
1719
42ed27ae6785 MERGE trunk -r516:527 -> branches/stable-1.1 (jiffies, bugfixes, pdo defines)
Florian Pose <fp@igh-essen.com>
parents: 1717
diff changeset
  2017
    if (jiffies - fsm->change_jiffies >= 100 * HZ / 1000) { // 100ms
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2018
        // timeout while checking
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2019
        slave->current_state = EC_SLAVE_STATE_UNKNOWN;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2020
        fsm->change_state = ec_fsm_error;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2021
        EC_ERR("Timeout while acknowleging state 0x%02X on slave %i.\n",
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2022
               fsm->change_new, slave->ring_position);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2023
        return;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2024
    }
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2025
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2026
    // reread new AL status
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2027
    ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2028
    ec_master_queue_datagram(fsm->master, datagram);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2029
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2030
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2031
/******************************************************************************
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2032
 *  CoE state machine
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2033
 *****************************************************************************/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2034
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2035
/**
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2036
   CoE state: DOWN_START.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2037
*/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2038
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2039
void ec_fsm_coe_down_start(ec_fsm_t *fsm /**< finite state machine */)
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2040
{
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2041
    ec_datagram_t *datagram = &fsm->datagram;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2042
    ec_slave_t *slave = fsm->slave;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2043
    ec_sdo_data_t *sdodata = fsm->sdodata;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2044
    uint8_t *data;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2045
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2046
    EC_INFO("Downloading SDO 0x%04X:%i to slave %i.\n",
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2047
            sdodata->index, sdodata->subindex, slave->ring_position);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2048
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2049
    if (slave->sii_rx_mailbox_size < 6 + 10 + sdodata->size) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2050
        EC_ERR("SDO fragmenting not supported yet!\n");
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2051
        fsm->coe_state = ec_fsm_error;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2052
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2053
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2054
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2055
    if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03,
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2056
                                            sdodata->size + 10))) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2057
        fsm->coe_state = ec_fsm_error;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2058
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2059
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2060
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2061
    EC_WRITE_U16(data, 0x2 << 12); // SDO request
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2062
    EC_WRITE_U8 (data + 2, (0x1 // size specified
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2063
                            | 0x1 << 5)); // Download request
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2064
    EC_WRITE_U16(data + 3, sdodata->index);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2065
    EC_WRITE_U8 (data + 5, sdodata->subindex);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2066
    EC_WRITE_U32(data + 6, sdodata->size);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2067
    memcpy(data + 6, sdodata->data, sdodata->size);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2068
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2069
    ec_master_queue_datagram(fsm->master, datagram);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2070
    fsm->coe_state = ec_fsm_coe_down_request;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2071
}
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2072
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2073
/*****************************************************************************/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2074
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2075
/**
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2076
   CoE state: DOWN_REQUEST.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2077
*/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2078
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2079
void ec_fsm_coe_down_request(ec_fsm_t *fsm /**< finite state machine */)
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2080
{
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2081
    ec_datagram_t *datagram = &fsm->datagram;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2082
    ec_slave_t *slave = fsm->slave;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2083
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2084
    if (datagram->state != EC_DATAGRAM_RECEIVED
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2085
        || datagram->working_counter != 1) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2086
        fsm->coe_state = ec_fsm_error;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2087
        EC_ERR("Reception of CoE download request failed.\n");
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2088
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2089
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2090
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2091
    fsm->coe_start = get_cycles();
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2092
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2093
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2094
    ec_master_queue_datagram(fsm->master, datagram);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2095
    fsm->coe_state = ec_fsm_coe_down_check;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2096
}
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2097
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2098
/*****************************************************************************/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2099
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2100
/**
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2101
   CoE state: DOWN_CHECK.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2102
*/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2103
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2104
void ec_fsm_coe_down_check(ec_fsm_t *fsm /**< finite state machine */)
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2105
{
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2106
    ec_datagram_t *datagram = &fsm->datagram;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2107
    ec_slave_t *slave = fsm->slave;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2108
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2109
    if (datagram->state != EC_DATAGRAM_RECEIVED
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2110
        || datagram->working_counter != 1) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2111
        fsm->coe_state = ec_fsm_error;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2112
        EC_ERR("Reception of CoE mailbox check datagram failed.\n");
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2113
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2114
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2115
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2116
    if (!ec_slave_mbox_check(datagram)) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2117
        if (get_cycles() - fsm->coe_start >= (cycles_t) 100 * cpu_khz) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2118
            fsm->coe_state = ec_fsm_error;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2119
            EC_ERR("Timeout while checking SDO configuration on slave %i.\n",
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2120
                   slave->ring_position);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2121
            return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2122
        }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2123
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2124
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2125
        ec_master_queue_datagram(fsm->master, datagram);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2126
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2127
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2128
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2129
    // Fetch response
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2130
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2131
    ec_master_queue_datagram(fsm->master, datagram);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2132
    fsm->coe_state = ec_fsm_coe_down_response;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2133
}
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2134
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2135
/*****************************************************************************/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2136
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2137
/**
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2138
   CoE state: DOWN_RESPONSE.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2139
*/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2140
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2141
void ec_fsm_coe_down_response(ec_fsm_t *fsm /**< finite state machine */)
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2142
{
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2143
    ec_datagram_t *datagram = &fsm->datagram;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2144
    ec_slave_t *slave = fsm->slave;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2145
    uint8_t *data;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2146
    size_t rec_size;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2147
    ec_sdo_data_t *sdodata = fsm->sdodata;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2148
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2149
    if (datagram->state != EC_DATAGRAM_RECEIVED
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2150
        || datagram->working_counter != 1) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2151
        fsm->coe_state = ec_fsm_error;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2152
        EC_ERR("Reception of CoE download response failed.\n");
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2153
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2154
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2155
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2156
    if (!(data = ec_slave_mbox_fetch(slave, datagram, 0x03, &rec_size))) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2157
        fsm->coe_state = ec_fsm_error;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2158
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2159
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2160
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2161
    if (rec_size < 6) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2162
        fsm->coe_state = ec_fsm_error;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2163
        EC_ERR("Received data is too small (%i bytes):\n", rec_size);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2164
        ec_print_data(data, rec_size);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2165
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2166
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2167
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2168
    if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2169
        EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2170
        fsm->coe_state = ec_fsm_error;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2171
        EC_ERR("SDO download 0x%04X:%X (%i bytes) aborted on slave %i.\n",
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2172
               sdodata->index, sdodata->subindex, sdodata->size,
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2173
               slave->ring_position);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2174
        if (rec_size < 10) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2175
            EC_ERR("Incomplete Abort command:\n");
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2176
            ec_print_data(data, rec_size);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2177
        }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2178
        else
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2179
            ec_canopen_abort_msg(EC_READ_U32(data + 6));
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2180
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2181
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2182
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2183
    if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2184
        EC_READ_U8 (data + 2) >> 5 != 0x3 || // Download response
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2185
        EC_READ_U16(data + 3) != sdodata->index || // index
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2186
        EC_READ_U8 (data + 5) != sdodata->subindex) { // subindex
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2187
        fsm->coe_state = ec_fsm_error;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2188
        EC_ERR("SDO download 0x%04X:%X (%i bytes) failed:\n",
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2189
               sdodata->index, sdodata->subindex, sdodata->size);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2190
        EC_ERR("Invalid SDO download response at slave %i!\n",
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2191
               slave->ring_position);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2192
        ec_print_data(data, rec_size);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2193
        return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2194
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2195
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2196
    fsm->coe_state = ec_fsm_end; // success
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2197
}
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2198
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2199
/*****************************************************************************/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2200
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2201
/**
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2202
   SDO abort messages.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2203
   The "abort SDO transfer request" supplies an abort code,
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2204
   which can be translated to clear text. This table does
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2205
   the mapping of the codes and messages.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2206
*/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2207
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2208
const ec_code_msg_t sdo_abort_messages[] = {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2209
    {0x05030000, "Toggle bit not changed"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2210
    {0x05040000, "SDO protocol timeout"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2211
    {0x05040001, "Client/Server command specifier not valid or unknown"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2212
    {0x05040005, "Out of memory"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2213
    {0x06010000, "Unsupported access to an object"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2214
    {0x06010001, "Attempt to read a write-only object"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2215
    {0x06010002, "Attempt to write a read-only object"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2216
    {0x06020000, "This object does not exist in the object directory"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2217
    {0x06040041, "The object cannot be mapped into the PDO"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2218
    {0x06040042, "The number and length of the objects to be mapped would"
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2219
     " exceed the PDO length"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2220
    {0x06040043, "General parameter incompatibility reason"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2221
    {0x06040047, "Gerneral internal incompatibility in device"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2222
    {0x06060000, "Access failure due to a hardware error"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2223
    {0x06070010, "Data type does not match, length of service parameter does"
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2224
     " not match"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2225
    {0x06070012, "Data type does not match, length of service parameter too"
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2226
     " high"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2227
    {0x06070013, "Data type does not match, length of service parameter too"
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2228
     " low"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2229
    {0x06090011, "Subindex does not exist"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2230
    {0x06090030, "Value range of parameter exceeded"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2231
    {0x06090031, "Value of parameter written too high"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2232
    {0x06090032, "Value of parameter written too low"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2233
    {0x06090036, "Maximum value is less than minimum value"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2234
    {0x08000000, "General error"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2235
    {0x08000020, "Data cannot be transferred or stored to the application"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2236
    {0x08000021, "Data cannot be transferred or stored to the application"
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2237
     " because of local control"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2238
    {0x08000022, "Data cannot be transferred or stored to the application"
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2239
     " because of the present device state"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2240
    {0x08000023, "Object dictionary dynamic generation fails or no object"
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2241
     " dictionary is present"},
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2242
    {}
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2243
};
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2244
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2245
/*****************************************************************************/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2246
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2247
/**
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2248
   Outputs an SDO abort message.
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2249
*/
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2250
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2251
void ec_canopen_abort_msg(uint32_t abort_code)
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2252
{
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2253
    const ec_code_msg_t *abort_msg;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2254
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2255
    for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2256
        if (abort_msg->code == abort_code) {
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2257
            EC_ERR("SDO abort message 0x%08X: \"%s\".\n",
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2258
                   abort_msg->code, abort_msg->message);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2259
            return;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2260
        }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2261
    }
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2262
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2263
    EC_ERR("Unknown SDO abort code 0x%08X.\n", abort_code);
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2264
}
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2265
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2266
/******************************************************************************
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2267
 *  Common state functions
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
  2268
 *****************************************************************************/
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2269
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2270
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2271
   State: ERROR.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2272
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2273
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2274
void ec_fsm_error(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2275
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2276
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2277
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2278
/*****************************************************************************/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2279
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2280
/**
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2281
   State: END.
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2282
*/
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2283
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2284
void ec_fsm_end(ec_fsm_t *fsm /**< finite state machine */)
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2285
{
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2286
}
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2287
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2288
/*****************************************************************************/