master/fsm.c
author Florian Pose <fp@igh-essen.com>
Fri, 20 Oct 2006 12:41:22 +0000
changeset 424 b792665b2dba
parent 423 862ff892cf18
child 425 d36808888817
permissions -rw-r--r--
Display debug data on mailbox error.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    12
 *  License, or (at your option) any later version.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    31
 *
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/**
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
   \file
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT finite state machines.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "globals.h"
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "fsm.h"
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "master.h"
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    44
#include "mailbox.h"
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
void ec_fsm_master_start(ec_fsm_t *);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    49
void ec_fsm_master_broadcast(ec_fsm_t *);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
    50
void ec_fsm_master_read_states(ec_fsm_t *);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    51
void ec_fsm_master_validate_vendor(ec_fsm_t *);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    52
void ec_fsm_master_validate_product(ec_fsm_t *);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
    53
void ec_fsm_master_rewrite_addresses(ec_fsm_t *);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
    54
void ec_fsm_master_configure_slave(ec_fsm_t *);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
    55
void ec_fsm_master_scan_slaves(ec_fsm_t *);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
    56
void ec_fsm_master_write_eeprom(ec_fsm_t *);
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
    57
void ec_fsm_master_sdodict(ec_fsm_t *);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    58
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
    59
void ec_fsm_startup_start(ec_fsm_t *);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
    60
void ec_fsm_startup_broadcast(ec_fsm_t *);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
    61
void ec_fsm_startup_scan(ec_fsm_t *);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
    62
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
    63
void ec_fsm_configuration_start(ec_fsm_t *);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
    64
void ec_fsm_configuration_conf(ec_fsm_t *);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
    65
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    66
void ec_fsm_slavescan_start(ec_fsm_t *);
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
    67
void ec_fsm_slavescan_address(ec_fsm_t *);
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    68
void ec_fsm_slavescan_state(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    69
void ec_fsm_slavescan_base(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    70
void ec_fsm_slavescan_datalink(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    71
void ec_fsm_slavescan_eeprom_size(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    72
void ec_fsm_slavescan_eeprom_data(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    73
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
    74
void ec_fsm_slaveconf_init(ec_fsm_t *);
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    75
void ec_fsm_slaveconf_sync(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    76
void ec_fsm_slaveconf_preop(ec_fsm_t *);
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
    77
void ec_fsm_slaveconf_fmmu(ec_fsm_t *);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
    78
void ec_fsm_slaveconf_sdoconf(ec_fsm_t *);
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    79
void ec_fsm_slaveconf_saveop(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    80
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
    81
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
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
    83
void ec_fsm_sii_read_check(ec_fsm_t *);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
    84
void ec_fsm_sii_read_fetch(ec_fsm_t *);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
    85
void ec_fsm_sii_start_writing(ec_fsm_t *);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
    86
void ec_fsm_sii_write_check(ec_fsm_t *);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
    87
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
    88
251
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_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
    90
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
    91
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
    92
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
    93
void ec_fsm_change_ack(ec_fsm_t *);
311
197489292da8 Renamed ACK2 state to CHECK ACK.
Florian Pose <fp@igh-essen.com>
parents: 310
diff changeset
    94
void ec_fsm_change_check_ack(ec_fsm_t *);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
    95
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
    96
void ec_fsm_coe_dict_start(ec_fsm_t *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
    97
void ec_fsm_coe_dict_request(ec_fsm_t *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
    98
void ec_fsm_coe_dict_check(ec_fsm_t *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
    99
void ec_fsm_coe_dict_response(ec_fsm_t *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   100
void ec_fsm_coe_dict_desc_request(ec_fsm_t *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   101
void ec_fsm_coe_dict_desc_check(ec_fsm_t *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   102
void ec_fsm_coe_dict_desc_response(ec_fsm_t *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   103
void ec_fsm_coe_dict_entry_request(ec_fsm_t *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   104
void ec_fsm_coe_dict_entry_check(ec_fsm_t *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   105
void ec_fsm_coe_dict_entry_response(ec_fsm_t *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   106
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   107
void ec_fsm_coe_down_start(ec_fsm_t *);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   108
void ec_fsm_coe_down_request(ec_fsm_t *);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   109
void ec_fsm_coe_down_check(ec_fsm_t *);
339
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 338
diff changeset
   110
void ec_fsm_coe_down_response(ec_fsm_t *);
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   111
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   112
void ec_fsm_end(ec_fsm_t *);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   113
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
   114
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   115
void ec_canopen_abort_msg(uint32_t);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   116
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   119
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   120
   Constructor.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   121
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   122
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   123
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
   124
                ec_master_t *master /**< EtherCAT master */
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   125
                )
238
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
    fsm->master = master;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
    fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
    fsm->master_slaves_responding = 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
    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
   131
    fsm->master_validation = 0;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   133
    ec_datagram_init(&fsm->datagram);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   134
    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
   135
        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
   136
        return -1;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    return 0;
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
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   144
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   145
   Destructor.
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
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   148
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
   149
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   150
    ec_datagram_clear(&fsm->datagram);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
}
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
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   155
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   156
   Resets the state machine.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   157
*/
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
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
   160
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    fsm->master_slaves_responding = 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
    fsm->master_slave_states = EC_SLAVE_STATE_UNKNOWN;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   168
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   169
   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
   170
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   171
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   172
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
   173
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    fsm->master_state(fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   177
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   178
343
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   179
/**
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   180
   Initializes the master startup state machine.
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   181
*/
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   182
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   183
void ec_fsm_startup(ec_fsm_t *fsm)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   184
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   185
    fsm->master_state = ec_fsm_startup_start;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   186
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   187
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   188
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   189
343
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   190
/**
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   191
   Returns the running state of the master startup state machine.
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   192
   \return non-zero if not terminated yet.
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   193
*/
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   194
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   195
int ec_fsm_startup_running(ec_fsm_t *fsm /**< Finite state machine */)
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   196
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   197
    return fsm->master_state != ec_fsm_end &&
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   198
        fsm->master_state != ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   199
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   200
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   201
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   202
343
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   203
/**
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   204
   Returns, if the master startup state machine terminated with success.
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   205
   \return non-zero if successful.
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   206
*/
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   207
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   208
int ec_fsm_startup_success(ec_fsm_t *fsm /**< Finite state machine */)
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   209
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   210
    return fsm->master_state == ec_fsm_end;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   211
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   212
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   213
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   214
343
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   215
/**
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   216
   Initializes the master configuration state machine.
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   217
*/
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   218
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   219
void ec_fsm_configuration(ec_fsm_t *fsm)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   220
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   221
    fsm->master_state = ec_fsm_configuration_start;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   222
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   223
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   224
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   225
343
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   226
/**
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   227
   Returns the running state of the master configuration state machine.
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   228
   \return non-zero if not terminated yet.
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   229
*/
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   230
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   231
int ec_fsm_configuration_running(ec_fsm_t *fsm /**< Finite state machine */)
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   232
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   233
    return fsm->master_state != ec_fsm_end &&
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   234
        fsm->master_state != ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   235
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   236
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   237
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   238
343
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   239
/**
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   240
   Returns, if the master confuguration state machine terminated with success.
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   241
   \return non-zero if successful.
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   242
*/
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   243
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   244
int ec_fsm_configuration_success(ec_fsm_t *fsm /**< Finite state machine */)
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   245
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   246
    return fsm->master_state == ec_fsm_end;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   247
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   248
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
/******************************************************************************
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   250
 *  master startup state machine
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   251
 *****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   252
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   253
/**
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   254
   Master state: START.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   255
   Starts with getting slave count and slave states.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   256
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   257
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   258
void ec_fsm_startup_start(ec_fsm_t *fsm)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   259
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   260
    ec_datagram_brd(&fsm->datagram, 0x0130, 2);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   261
    ec_master_queue_datagram(fsm->master, &fsm->datagram);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   262
    fsm->master_state = ec_fsm_startup_broadcast;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   263
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   264
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   265
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   266
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   267
/**
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   268
   Master state: BROADCAST.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   269
   Processes the broadcast read slave count and slaves states.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   270
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   271
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   272
void ec_fsm_startup_broadcast(ec_fsm_t *fsm /**< finite state machine */)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   273
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   274
    ec_datagram_t *datagram = &fsm->datagram;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   275
    unsigned int i;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   276
    ec_slave_t *slave;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   277
    ec_master_t *master = fsm->master;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   278
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   279
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
397
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
   280
        EC_ERR("Failed to receive broadcast datagram.\n");
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   281
        fsm->master_state = ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   282
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   283
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   284
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   285
    EC_INFO("Scanning bus.\n");
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   286
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   287
    ec_master_clear_slaves(master);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   288
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   289
    master->slave_count = datagram->working_counter;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   290
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   291
    if (!master->slave_count) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   292
        // no slaves present -> finish state machine.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   293
        fsm->master_state = ec_fsm_end;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   294
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   295
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   296
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   297
    // init slaves
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   298
    for (i = 0; i < master->slave_count; i++) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   299
        if (!(slave = (ec_slave_t *) kmalloc(sizeof(ec_slave_t),
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   300
                                             GFP_KERNEL))) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   301
            EC_ERR("Failed to allocate slave %i!\n", i);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   302
            fsm->master_state = ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   303
            return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   304
        }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   305
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   306
        if (ec_slave_init(slave, master, i, i + 1)) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   307
            fsm->master_state = ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   308
            return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   309
        }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   310
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   311
        if (kobject_add(&slave->kobj)) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   312
            EC_ERR("Failed to add kobject.\n");
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   313
            kobject_put(&slave->kobj); // free
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   314
            fsm->master_state = ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   315
            return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   316
        }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   317
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   318
        list_add_tail(&slave->list, &master->slaves);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   319
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   320
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   321
    // begin scanning of slaves
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   322
    fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   323
    fsm->slave_state = ec_fsm_slavescan_start;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   324
    fsm->master_state = ec_fsm_startup_scan;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   325
    fsm->master_state(fsm); // execute immediately
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   326
    return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   327
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   328
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   329
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   330
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   331
/**
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   332
   Master state: SCAN.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   333
   Executes the sub-statemachine for the scanning of a slave.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   334
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   335
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   336
void ec_fsm_startup_scan(ec_fsm_t *fsm /**< finite state machine */)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   337
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   338
    ec_master_t *master = fsm->master;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   339
    ec_slave_t *slave = fsm->slave;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   340
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   341
    fsm->slave_state(fsm); // execute slave state machine
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   342
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   343
    if (fsm->slave_state == ec_fsm_error) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   344
        EC_ERR("Slave scanning failed.\n");
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   345
        fsm->master_state = ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   346
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   347
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   348
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   349
    if (fsm->slave_state != ec_fsm_end) return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   350
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   351
    // another slave to scan?
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   352
    if (slave->list.next != &master->slaves) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   353
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   354
        fsm->slave_state = ec_fsm_slavescan_start;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   355
        fsm->slave_state(fsm); // execute immediately
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   356
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   357
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   358
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   359
    EC_INFO("Bus scanning completed.\n");
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   360
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   361
    ec_master_calc_addressing(master);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   362
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   363
    fsm->master_state = ec_fsm_end;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   364
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   365
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   366
/******************************************************************************
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   367
 *  master configuration state machine
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   368
 *****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   369
343
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   370
/**
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   371
   Master configuration state machine: START.
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   372
*/
b3858d25ba4b Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   373
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   374
void ec_fsm_configuration_start(ec_fsm_t *fsm /**< finite state machine */)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   375
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   376
    ec_master_t *master = fsm->master;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   377
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   378
    if (list_empty(&master->slaves)) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   379
        fsm->master_state = ec_fsm_end;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   380
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   381
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   382
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   383
    // begin configuring slaves
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   384
    fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   385
    fsm->slave_state = ec_fsm_slaveconf_init;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   386
    fsm->change_new = EC_SLAVE_STATE_INIT;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   387
    fsm->change_state = ec_fsm_change_start;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   388
    fsm->master_state = ec_fsm_configuration_conf;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   389
    fsm->master_state(fsm); // execute immediately
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   390
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   391
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   392
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   393
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   394
/**
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   395
   Master state: CONF.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   396
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   397
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   398
void ec_fsm_configuration_conf(ec_fsm_t *fsm /**< finite state machine */)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   399
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   400
    ec_master_t *master = fsm->master;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   401
    ec_slave_t *slave = fsm->slave;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   402
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   403
    fsm->slave_state(fsm); // execute slave's state machine
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   404
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   405
    if (fsm->slave_state == ec_fsm_error) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   406
        fsm->master_state = ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   407
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   408
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   409
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   410
    if (fsm->slave_state != ec_fsm_end) return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   411
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   412
    // another slave to configure?
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   413
    if (slave->list.next != &master->slaves) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   414
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   415
        fsm->slave_state = ec_fsm_slaveconf_init;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   416
        fsm->change_new = EC_SLAVE_STATE_INIT;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   417
        fsm->change_state = ec_fsm_change_start;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   418
        fsm->master_state(fsm); // execute immediately
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   419
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   420
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   421
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   422
    fsm->master_state = ec_fsm_end;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   423
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   424
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   425
/******************************************************************************
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   426
 *  operation / idle state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   427
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   428
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   429
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   430
   Master state: START.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
   Starts with getting slave count and slave states.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   432
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
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
   435
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   436
    ec_datagram_brd(&fsm->datagram, 0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   437
    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
   438
    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
   439
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   440
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   441
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   442
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   443
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   444
   Master state: BROADCAST.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   445
   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
   446
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   447
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   448
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
   449
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   450
    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
   451
    unsigned int topology_change, states_change, i;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   452
    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
   453
    ec_master_t *master = fsm->master;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   455
    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
   456
        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
   457
            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
   458
            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
   459
                slave->online = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   460
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   461
        }
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   462
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   464
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   465
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   466
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   467
    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
   468
                       fsm->master_slaves_responding);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   469
    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
   470
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   471
    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
   472
    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
   473
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   474
    if (topology_change) {
262
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   475
        EC_INFO("%i slave%s responding.\n",
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   476
                fsm->master_slaves_responding,
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   477
                fsm->master_slaves_responding == 1 ? "" : "s");
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   478
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   479
        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
   480
            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
   481
                fsm->master_validation = 1; // start validation later
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   482
            }
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   483
            else {
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   484
                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
   485
            }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   486
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   487
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   488
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   489
    if (states_change) {
403
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 402
diff changeset
   490
        char states[EC_STATE_STRING_SIZE];
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   491
        ec_state_string(fsm->master_slave_states, states);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   492
        EC_INFO("Slave states: %s.\n", states);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   493
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   494
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 304
diff changeset
   495
    // topology change in idle mode: clear all slaves and scan the bus
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 304
diff changeset
   496
    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
   497
        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
   498
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   499
        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
   500
        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
   501
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   502
        master->slave_count = datagram->working_counter;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   503
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   504
        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
   505
            // 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
   506
            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
   507
            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
   508
            return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   509
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   510
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   511
        // init slaves
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   512
        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
   513
            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
   514
                                                 GFP_ATOMIC))) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   515
                EC_ERR("Failed to allocate slave %i!\n", i);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   516
                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
   517
                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
   518
                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
   519
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   520
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   521
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   522
            if (ec_slave_init(slave, master, i, i + 1)) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   523
                // freeing of "slave" already done
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   524
                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
   525
                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
   526
                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
   527
                return;
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
            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
   531
                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
   532
                kobject_put(&slave->kobj); // free
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   533
                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
   534
                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
   535
                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
   536
                return;
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
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   539
            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
   540
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   541
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   542
        // begin scanning of slaves
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   543
        fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
   544
        fsm->slave_state = ec_fsm_slavescan_start;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   545
        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
   546
        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
   547
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   548
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   549
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   550
    // 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
   551
    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
   552
    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
   553
    ec_master_queue_datagram(master, &fsm->datagram);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   554
    fsm->master_state = ec_fsm_master_read_states;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   555
}
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   556
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   557
/*****************************************************************************/
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   558
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   559
/**
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   560
   Master action: PROC_STATES.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   561
   Processes the slave states.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   562
*/
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   563
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   564
void ec_fsm_master_action_process_states(ec_fsm_t *fsm
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   565
                                         /**< finite state machine */
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   566
                                         )
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   567
{
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   568
    ec_master_t *master = fsm->master;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   569
    ec_slave_t *slave;
403
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 402
diff changeset
   570
    char old_state[EC_STATE_STRING_SIZE], new_state[EC_STATE_STRING_SIZE];
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   571
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   572
    // check if any slaves are not in the state, they're supposed to be
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   573
    list_for_each_entry(slave, &master->slaves, list) {
421
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   574
        if (slave->error_flag
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   575
            || !slave->online
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   576
            || slave->requested_state == EC_SLAVE_STATE_UNKNOWN
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   577
            || (slave->current_state == slave->requested_state
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   578
                && (slave->configured
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   579
                    || slave->current_state == EC_SLAVE_STATE_INIT))) continue;
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   580
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   581
        if (!slave->configured
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   582
            && slave->current_state != EC_SLAVE_STATE_INIT) {
422
439cd1650c36 Minor output changes in fsm.c
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   583
            ec_state_string(slave->current_state, old_state);
439cd1650c36 Minor output changes in fsm.c
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   584
            EC_INFO("Reconfiguring slave %i (%s).\n",
439cd1650c36 Minor output changes in fsm.c
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   585
                    slave->ring_position, old_state);
421
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   586
        }
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   587
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   588
        if (slave->current_state != slave->requested_state) {
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   589
            ec_state_string(slave->current_state, old_state);
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   590
            ec_state_string(slave->requested_state, new_state);
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   591
            EC_INFO("Changing state of slave %i from %s to %s.\n",
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   592
                    slave->ring_position, old_state, new_state);
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   593
        }
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   594
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   595
        fsm->slave = slave;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
   596
        fsm->slave_state = ec_fsm_slaveconf_init;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   597
        fsm->change_new = EC_SLAVE_STATE_INIT;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   598
        fsm->change_state = ec_fsm_change_start;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   599
        fsm->master_state = ec_fsm_master_configure_slave;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   600
        fsm->master_state(fsm); // execute immediately
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   601
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   602
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   603
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   604
    // Check, if EoE processing has to be started
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   605
    ec_master_eoe_start(master);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   606
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   607
    // check, if slaves have an SDO dictionary to read out.
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   608
    list_for_each_entry(slave, &master->slaves, list) {
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   609
        if (!(slave->sii_mailbox_protocols & EC_MBOX_COE)
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   610
            || slave->sdo_dictionary_fetched
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   611
            || slave->current_state == EC_SLAVE_STATE_INIT
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   612
            || jiffies - slave->jiffies_preop < 5 * HZ
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   613
            || !slave->online
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   614
            || slave->error_flag) continue;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   615
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   616
        if (master->debug_level) {
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
   617
            EC_DBG("Fetching SDO dictionary from slave %i.\n",
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   618
                   slave->ring_position);
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   619
        }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   620
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   621
        if (kobject_add(&slave->sdo_kobj)) {
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   622
            EC_ERR("Failed to add SDO kobj of slave %i.\n",
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   623
                   slave->ring_position);
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   624
            slave->error_flag = 1;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   625
            fsm->master_state = ec_fsm_master_start;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   626
            fsm->master_state(fsm); // execute immediately
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   627
            return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   628
        }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   629
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   630
        slave->sdo_dictionary_fetched = 1;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   631
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   632
        // start fetching SDO dictionary
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   633
        fsm->slave = slave;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   634
        fsm->master_state = ec_fsm_master_sdodict;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   635
        fsm->coe_state = ec_fsm_coe_dict_start;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   636
        fsm->coe_state(fsm); // execute immediately
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   637
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   638
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   639
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 304
diff changeset
   640
    if (master->mode == EC_MASTER_MODE_IDLE) {
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   641
        // nothing to configure. check for pending EEPROM write operations.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   642
        list_for_each_entry(slave, &master->slaves, list) {
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   643
            if (!slave->new_eeprom_data) continue;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   644
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   645
            if (!slave->online || slave->error_flag) {
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   646
                kfree(slave->new_eeprom_data);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   647
                slave->new_eeprom_data = NULL;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   648
                EC_ERR("Discarding EEPROM data, slave %i not ready.\n",
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   649
                       slave->ring_position);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   650
                continue;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   651
            }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   652
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   653
            // found pending EEPROM write operation. execute it!
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   654
            EC_INFO("Writing EEPROM of slave %i...\n", slave->ring_position);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   655
            fsm->sii_offset = 0x0000;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   656
            memcpy(fsm->sii_value, slave->new_eeprom_data, 2);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   657
            fsm->sii_mode = 1;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   658
            fsm->sii_state = ec_fsm_sii_start_writing;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   659
            fsm->slave = slave;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   660
            fsm->master_state = ec_fsm_master_write_eeprom;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   661
            fsm->master_state(fsm); // execute immediately
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   662
            return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   663
        }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   664
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   665
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   666
    // nothing to do. restart master state machine.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   667
    fsm->master_state = ec_fsm_master_start;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   668
    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
   669
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   670
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   671
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   672
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   673
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   674
   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
   675
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   676
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   677
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
   678
                                           /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   679
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   680
    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
   681
    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
   682
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   683
    // 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
   684
    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
   685
        // process next slave
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   686
        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
   687
        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
   688
                         0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   689
        ec_master_queue_datagram(master, &fsm->datagram);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   690
        fsm->master_state = ec_fsm_master_read_states;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   691
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   692
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   693
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   694
    // all slave states read
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   695
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   696
    // 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
   697
    if (fsm->master_validation) {
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   698
        fsm->master_validation = 0;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   699
        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
   700
            if (slave->online) continue;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   701
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   702
            // 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
   703
            EC_INFO("Validating bus.\n");
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   704
            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
   705
            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
   706
            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
   707
            fsm->sii_mode = 0;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   708
            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
   709
            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
   710
            return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   711
        }
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   712
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   713
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   714
    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
   715
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   716
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   717
/*****************************************************************************/
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
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   720
   Master state: READ STATES.
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   721
   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
   722
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   723
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   724
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
   725
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   726
    ec_slave_t *slave = fsm->slave;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   727
    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
   728
    uint8_t new_state;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   729
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   730
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   731
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   732
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   733
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   734
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   735
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   736
    // 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
   737
    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
   738
        if (slave->online) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   739
            slave->online = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   740
            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
   741
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   742
        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
   743
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   744
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   745
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   746
    // slave responded
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   747
    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
   748
    if (!slave->online) { // slave was offline before
403
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 402
diff changeset
   749
        char cur_state[EC_STATE_STRING_SIZE];
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   750
        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
   751
        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
   752
        slave->current_state = new_state;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   753
        ec_state_string(slave->current_state, cur_state);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   754
        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
   755
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   756
    else if (new_state != slave->current_state) {
403
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 402
diff changeset
   757
        char old_state[EC_STATE_STRING_SIZE], cur_state[EC_STATE_STRING_SIZE];
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   758
        ec_state_string(slave->current_state, old_state);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   759
        ec_state_string(new_state, cur_state);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   760
        EC_INFO("Slave %i: %s -> %s.\n",
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   761
                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
   762
        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
   763
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   764
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   765
    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
   766
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   767
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   768
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   769
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   770
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   771
   Master state: VALIDATE_VENDOR.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   772
   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
   773
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   774
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   775
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
   776
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   777
    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
   778
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   779
    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
   780
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   781
    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
   782
        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
   783
        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
   784
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   785
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   786
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   787
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   788
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   789
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   790
    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
   791
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   792
    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
   793
        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
   794
        fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   795
        fsm->master_state(fsm); // execute immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   796
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   797
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   798
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   799
    // 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
   800
    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
   801
    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
   802
    fsm->sii_mode = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   803
    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
   804
    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
   805
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   806
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   807
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   808
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   809
/**
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   810
   Master action: ADDRESS.
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   811
   Looks for slave, that have lost their configuration and writes
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   812
   their station address, so that they can be reconfigured later.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   813
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   814
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   815
void ec_fsm_master_action_addresses(ec_fsm_t *fsm /**< finite state machine */)
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   816
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   817
    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
   818
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   819
    while (fsm->slave->online) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   820
        if (fsm->slave->list.next == &fsm->master->slaves) { // last slave?
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   821
            fsm->master_state = ec_fsm_master_start;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   822
            fsm->master_state(fsm); // execute immediately
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   823
            return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   824
        }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   825
        // check next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   826
        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
   827
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   828
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   829
    EC_INFO("Reinitializing slave %i.\n", fsm->slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   830
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   831
    // write station address
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   832
    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
   833
    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
   834
    ec_master_queue_datagram(fsm->master, datagram);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   835
    fsm->master_state = ec_fsm_master_rewrite_addresses;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   836
}
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   837
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   838
/*****************************************************************************/
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   839
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   840
/**
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   841
   Master state: VALIDATE_PRODUCT.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   842
   Validates the product ID of a slave.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   843
*/
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   844
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   845
void ec_fsm_master_validate_product(ec_fsm_t *fsm /**< finite state machine */)
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   846
{
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   847
    ec_slave_t *slave = fsm->slave;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   848
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   849
    fsm->sii_state(fsm); // execute SII state machine
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   850
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   851
    if (fsm->sii_state == ec_fsm_error) {
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   852
        fsm->slave->error_flag = 1;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   853
        EC_ERR("Failed to validate product code of slave %i.\n",
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   854
               slave->ring_position);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   855
        fsm->master_state = ec_fsm_master_start;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   856
        fsm->master_state(fsm); // execute immediately
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   857
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   858
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   859
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   860
    if (fsm->sii_state != ec_fsm_end) return;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   861
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   862
    if (EC_READ_U32(fsm->sii_value) != slave->sii_product_code) {
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   863
        EC_ERR("Slave %i: invalid product code!\n", slave->ring_position);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   864
        EC_ERR("expected 0x%08X, got 0x%08X.\n", slave->sii_product_code,
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   865
               EC_READ_U32(fsm->sii_value));
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   866
        fsm->master_state = ec_fsm_master_start;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   867
        fsm->master_state(fsm); // execute immediately
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   868
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   869
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   870
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   871
    // have all states been validated?
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   872
    if (slave->list.next == &fsm->master->slaves) {
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   873
        fsm->slave = list_entry(fsm->master->slaves.next, ec_slave_t, list);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   874
        // start writing addresses to offline slaves
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   875
        ec_fsm_master_action_addresses(fsm);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   876
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   877
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   878
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   879
    // validate next slave
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   880
    fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   881
    fsm->master_state = ec_fsm_master_validate_vendor;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   882
    fsm->sii_offset = 0x0008; // vendor ID
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   883
    fsm->sii_mode = 0;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   884
    fsm->sii_state = ec_fsm_sii_start_reading;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   885
    fsm->sii_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
   886
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   887
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   888
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   889
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   890
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   891
   Master state: REWRITE ADDRESS.
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   892
   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
   893
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   894
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   895
void ec_fsm_master_rewrite_addresses(ec_fsm_t *fsm
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   896
                                     /**< finite state machine */
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   897
                                     )
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   898
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   899
    ec_slave_t *slave = fsm->slave;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   900
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   901
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   902
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   903
        || 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
   904
        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
   905
               slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   906
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   907
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   908
    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
   909
        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
   910
        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
   911
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   912
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   913
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   914
    // check next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   915
    fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   916
    // Write new station address to slave
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   917
    ec_fsm_master_action_addresses(fsm);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   918
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   919
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   920
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   921
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   922
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   923
   Master state: SCAN SLAVES.
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   924
   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
   925
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   926
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   927
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
   928
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   929
    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
   930
    ec_slave_t *slave = fsm->slave;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   931
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   932
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   933
    fsm->slave_state(fsm); // execute slave state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   934
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   935
    if (fsm->slave_state != ec_fsm_end
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   936
        && fsm->slave_state != ec_fsm_error) return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   937
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   938
    // another slave to fetch?
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   939
    if (slave->list.next != &master->slaves) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   940
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   941
        fsm->slave_state = ec_fsm_slavescan_start;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   942
        fsm->slave_state(fsm); // execute immediately
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   943
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   944
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   945
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   946
    EC_INFO("Bus scanning completed.\n");
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   947
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   948
    ec_master_calc_addressing(master);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   949
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   950
    // determine initial states.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   951
    list_for_each_entry(slave, &master->slaves, list) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   952
        if (ec_slave_is_coupler(slave)) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   953
            slave->requested_state = EC_SLAVE_STATE_OP;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   954
        }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   955
        else {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   956
            if (master->mode == EC_MASTER_MODE_OPERATION)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   957
                slave->requested_state = EC_SLAVE_STATE_PREOP;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   958
            else
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   959
                slave->requested_state = EC_SLAVE_STATE_INIT;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   960
        }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   961
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   962
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   963
    fsm->master_state = ec_fsm_master_start;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   964
    fsm->master_state(fsm); // execute immediately
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   965
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   966
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   967
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   968
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   969
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   970
   Master state: CONFIGURE SLAVES.
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   971
   Starts configuring a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   972
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   973
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   974
void ec_fsm_master_configure_slave(ec_fsm_t *fsm
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   975
                                   /**< finite state machine */
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   976
                                   )
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   977
{
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   978
    fsm->slave_state(fsm); // execute slave's state machine
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   979
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   980
    if (fsm->slave_state != ec_fsm_end
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   981
        && fsm->slave_state != ec_fsm_error) return;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   982
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   983
    ec_fsm_master_action_process_states(fsm);
238
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
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   986
/*****************************************************************************/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   987
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   988
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   989
   Master state: WRITE EEPROM.
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   990
*/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   991
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   992
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
   993
{
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   994
    ec_slave_t *slave = fsm->slave;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   995
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   996
    fsm->sii_state(fsm); // execute SII state machine
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   997
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   998
    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
   999
        fsm->slave->error_flag = 1;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1000
        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
  1001
               slave->ring_position);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1002
        kfree(slave->new_eeprom_data);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1003
        slave->new_eeprom_data = NULL;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1004
        fsm->master_state = ec_fsm_master_start;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1005
        fsm->master_state(fsm); // execute immediately
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1006
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1007
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1008
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1009
    if (fsm->sii_state != ec_fsm_end) return;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1010
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1011
    fsm->sii_offset++;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1012
    if (fsm->sii_offset < slave->new_eeprom_size) {
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1013
        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
  1014
        fsm->sii_state = ec_fsm_sii_start_writing;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1015
        fsm->sii_state(fsm); // execute immediately
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1016
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1017
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1018
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1019
    // finished writing EEPROM
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1020
    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
  1021
    kfree(slave->new_eeprom_data);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1022
    slave->new_eeprom_data = NULL;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1023
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1024
    // TODO: Evaluate new EEPROM contents!
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1025
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1026
    // restart master state machine.
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1027
    fsm->master_state = ec_fsm_master_start;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1028
    fsm->master_state(fsm); // execute immediately
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1029
}
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1030
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1031
/*****************************************************************************/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1032
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1033
/**
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1034
   Master state: SDODICT.
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1035
*/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1036
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1037
void ec_fsm_master_sdodict(ec_fsm_t *fsm /**< finite state machine */)
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1038
{
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1039
    ec_slave_t *slave = fsm->slave;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1040
    ec_master_t *master = fsm->master;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1041
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1042
    fsm->coe_state(fsm); // execute CoE state machine
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1043
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1044
    if (fsm->coe_state == ec_fsm_error) {
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1045
        fsm->slave->error_flag = 1;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1046
        fsm->slave_state = ec_fsm_error;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1047
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1048
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1049
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1050
    if (fsm->coe_state != ec_fsm_end) return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1051
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1052
    // SDO dictionary fetching finished
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1053
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1054
    if (master->debug_level) {
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  1055
        unsigned int sdo_count, entry_count;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  1056
        ec_slave_sdo_dict_info(slave, &sdo_count, &entry_count);
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  1057
        EC_DBG("Fetched %i SDOs and %i entries from slave %i.\n",
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  1058
               sdo_count, entry_count, slave->ring_position);
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1059
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1060
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1061
    // restart master state machine.
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1062
    fsm->master_state = ec_fsm_master_start;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1063
    fsm->master_state(fsm); // execute immediately
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1064
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1065
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1066
/******************************************************************************
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1067
 *  slave scan state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1068
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1069
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1070
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1071
   Slave scan state: START.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1072
   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
  1073
   slave, according to its ring position.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1074
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1075
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1076
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
  1077
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1078
    ec_datagram_t *datagram = &fsm->datagram;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1079
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1080
    // write station address
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1081
    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
  1082
    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
  1083
    ec_master_queue_datagram(fsm->master, datagram);
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1084
    fsm->slave_state = ec_fsm_slavescan_address;
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1085
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1086
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1087
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1088
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1089
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1090
   Slave scan state: ADDRESS.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1091
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1092
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1093
void ec_fsm_slavescan_address(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1094
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1095
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1096
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1097
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1098
        || datagram->working_counter != 1) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1099
        fsm->slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1100
        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
  1101
        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
  1102
               fsm->slave->ring_position);
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1103
        return;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1104
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1105
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1106
    // Read AL state
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1107
    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
  1108
    ec_master_queue_datagram(fsm->master, datagram);
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1109
    fsm->slave_state = ec_fsm_slavescan_state;
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1110
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1111
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1112
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1113
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1114
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1115
   Slave scan state: STATE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1116
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1117
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1118
void ec_fsm_slavescan_state(ec_fsm_t *fsm /**< finite state machine */)
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1119
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1120
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1121
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1122
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1123
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1124
        || 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
  1125
        fsm->slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1126
        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
  1127
        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
  1128
               fsm->slave->ring_position);
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1129
        return;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1130
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1131
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1132
    slave->current_state = EC_READ_U8(datagram->data);
402
03e31ac14047 Renamed EC_ACK to EC_SLAVE_STATE_ACK_ERR
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
  1133
    if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1134
        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
  1135
                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
  1136
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1137
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1138
    // read base data
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1139
    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
  1140
    ec_master_queue_datagram(fsm->master, datagram);
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1141
    fsm->slave_state = ec_fsm_slavescan_base;
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1142
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1143
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1144
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1145
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1146
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1147
   Slave scan state: BASE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1148
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1149
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1150
void ec_fsm_slavescan_base(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1151
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1152
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1153
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1154
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1155
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1156
        || 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
  1157
        fsm->slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1158
        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
  1159
        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
  1160
               slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1161
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1162
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1163
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1164
    slave->base_type       = EC_READ_U8 (datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1165
    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
  1166
    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
  1167
    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
  1168
    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
  1169
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1170
    if (slave->base_fmmu_count > EC_MAX_FMMUS)
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1171
        slave->base_fmmu_count = EC_MAX_FMMUS;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1172
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1173
    // read data link status
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1174
    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
  1175
    ec_master_queue_datagram(slave->master, datagram);
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1176
    fsm->slave_state = ec_fsm_slavescan_datalink;
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1177
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1178
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1179
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1180
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1181
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1182
   Slave scan state: DATALINK.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1183
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1184
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1185
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
  1186
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1187
    ec_datagram_t *datagram = &fsm->datagram;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1188
    ec_slave_t *slave = fsm->slave;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1189
    uint16_t dl_status;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1190
    unsigned int i;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1191
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1192
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1193
        || 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
  1194
        fsm->slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1195
        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
  1196
        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
  1197
               slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1198
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1199
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1200
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1201
    dl_status = EC_READ_U16(datagram->data);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1202
    for (i = 0; i < 4; i++) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1203
        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
  1204
        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
  1205
        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
  1206
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1207
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1208
    // 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
  1209
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1210
    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
  1211
    fsm->sii_mode = 1;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1212
    fsm->sii_state = ec_fsm_sii_start_reading;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1213
    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
  1214
    fsm->slave_state(fsm); // execute state immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1215
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1216
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1217
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1218
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1219
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1220
   Slave scan state: EEPROM SIZE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1221
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1222
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1223
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
  1224
{
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1225
    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
  1226
    uint16_t cat_type, cat_size;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1227
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1228
    // execute SII state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1229
    fsm->sii_state(fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1230
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1231
    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
  1232
        fsm->slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1233
        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
  1234
        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
  1235
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1236
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1237
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1238
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1239
    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
  1240
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1241
    cat_type = EC_READ_U16(fsm->sii_value);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1242
    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
  1243
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1244
    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
  1245
        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
  1246
        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
  1247
        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
  1248
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1249
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1250
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1251
    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
  1252
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1253
    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
  1254
        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
  1255
                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
  1256
        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
  1257
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1258
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1259
    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
  1260
          (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
  1261
        fsm->slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1262
        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
  1263
        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
  1264
               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
  1265
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1266
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1267
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1268
    // 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
  1269
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1270
    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
  1271
    fsm->sii_mode = 1;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1272
    fsm->sii_state = ec_fsm_sii_start_reading;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1273
    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
  1274
    fsm->slave_state(fsm); // execute state immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1275
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1276
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1277
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1278
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1279
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1280
   Slave scan state: EEPROM DATA.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1281
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1282
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1283
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
  1284
{
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1285
    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
  1286
    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
  1287
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1288
    // execute SII state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1289
    fsm->sii_state(fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1290
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1291
    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
  1292
        fsm->slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1293
        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
  1294
        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
  1295
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1296
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1297
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1298
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1299
    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
  1300
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1301
    // 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
  1302
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1303
    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
  1304
        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
  1305
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1306
    else { // copy the last word
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1307
        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
  1308
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1309
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1310
    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
  1311
        // 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
  1312
        fsm->sii_offset += 2;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1313
        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
  1314
        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
  1315
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1316
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1317
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1318
    // 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
  1319
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1320
    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
  1321
        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
  1322
    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
  1323
        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
  1324
    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
  1325
        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
  1326
    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
  1327
        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
  1328
    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
  1329
        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
  1330
    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
  1331
        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
  1332
    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
  1333
        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
  1334
    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
  1335
        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
  1336
    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
  1337
        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
  1338
    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
  1339
        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
  1340
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1341
    // 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
  1342
    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
  1343
    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
  1344
        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
  1345
        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
  1346
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1347
        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
  1348
            case 0x000A:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1349
                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
  1350
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1351
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1352
            case 0x001E:
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1353
                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
  1354
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1355
            case 0x0028:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1356
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1357
            case 0x0029:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1358
                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
  1359
                                        cat_size))
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1360
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1361
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1362
            case 0x0032:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1363
                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
  1364
                                       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
  1365
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1366
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1367
            case 0x0033:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1368
                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
  1369
                                       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
  1370
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1371
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1372
            default:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1373
                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
  1374
                        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
  1375
        }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1376
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1377
        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
  1378
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1379
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1380
    fsm->slave_state = ec_fsm_end;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1381
    return;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1382
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1383
end:
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1384
    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
  1385
    fsm->slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1386
    fsm->slave_state = ec_fsm_error;
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1387
}
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1388
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1389
/******************************************************************************
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1390
 *  slave configuration state machine
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1391
 *****************************************************************************/
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1392
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1393
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1394
   Slave configuration state: INIT.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1395
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1396
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1397
void ec_fsm_slaveconf_init(ec_fsm_t *fsm /**< finite state machine */)
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1398
{
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1399
    ec_master_t *master = fsm->master;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1400
    ec_slave_t *slave = fsm->slave;
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1401
    ec_datagram_t *datagram = &fsm->datagram;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1402
    const ec_sii_sync_t *sync;
420
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1403
    ec_sii_sync_t mbox_sync;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1404
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1405
    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
  1406
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1407
    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
  1408
        slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1409
        fsm->slave_state = ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1410
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1411
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1412
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1413
    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
  1414
421
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
  1415
    slave->configured = 1;
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
  1416
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1417
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1418
        EC_DBG("Slave %i is now in INIT.\n", slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1419
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1420
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1421
    // 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
  1422
    if (slave->current_state == slave->requested_state) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1423
        fsm->slave_state = ec_fsm_end; // successful
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1424
        if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1425
            EC_DBG("Finished configuration of slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1426
                   slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1427
        }
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1428
        return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1429
    }
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
    // 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
  1432
    //ec_slave_check_crc(slave);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1433
    // 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
  1434
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1435
    if (!slave->base_sync_count) { // no sync managers
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1436
        fsm->slave_state = ec_fsm_slaveconf_preop;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1437
        fsm->change_new = EC_SLAVE_STATE_PREOP;
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1438
        fsm->change_state = ec_fsm_change_start;
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1439
        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
  1440
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1441
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1442
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1443
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1444
        EC_DBG("Configuring sync managers of slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1445
               slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1446
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1447
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1448
    // configure sync managers
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1449
    ec_datagram_npwr(datagram, slave->station_address, 0x0800,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1450
                     EC_SYNC_SIZE * slave->base_sync_count);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1451
    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
  1452
420
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1453
    if (list_empty(&slave->sii_syncs)) {
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1454
        if (slave->sii_rx_mailbox_offset && slave->sii_tx_mailbox_offset) {
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1455
            if (slave->master->debug_level)
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1456
                EC_DBG("Guessing sync manager settings for slave %i.\n",
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1457
                       slave->ring_position);
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1458
            mbox_sync.index = 0;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1459
            mbox_sync.physical_start_address = slave->sii_tx_mailbox_offset;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1460
            mbox_sync.length = slave->sii_tx_mailbox_size;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1461
            mbox_sync.control_register = 0x26;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1462
            mbox_sync.enable = 0x01;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1463
            mbox_sync.est_length = 0;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1464
            ec_sync_config(&mbox_sync, slave,
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1465
                           datagram->data + EC_SYNC_SIZE * mbox_sync.index);
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1466
            mbox_sync.index = 1;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1467
            mbox_sync.physical_start_address = slave->sii_rx_mailbox_offset;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1468
            mbox_sync.length = slave->sii_rx_mailbox_size;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1469
            mbox_sync.control_register = 0x22;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1470
            mbox_sync.enable = 0x01;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1471
            mbox_sync.est_length = 0;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1472
            ec_sync_config(&mbox_sync, slave,
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1473
                           datagram->data + EC_SYNC_SIZE * mbox_sync.index);
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1474
        }
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1475
    }
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1476
    else {
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1477
        list_for_each_entry(sync, &slave->sii_syncs, list) {
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1478
            if (sync->index >= slave->base_sync_count) {
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1479
                EC_ERR("Invalid sync manager configuration found!");
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1480
                fsm->slave->error_flag = 1;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1481
                fsm->slave_state = ec_fsm_error;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1482
                return;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1483
            }
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1484
            ec_sync_config(sync, slave,
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1485
                           datagram->data + EC_SYNC_SIZE * sync->index);
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1486
        }
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1487
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1488
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1489
    ec_master_queue_datagram(fsm->master, datagram);
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1490
    fsm->slave_state = ec_fsm_slaveconf_sync;
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1491
}
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1492
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1493
/*****************************************************************************/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1494
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1495
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1496
   Slave configuration state: SYNC.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1497
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1498
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1499
void ec_fsm_slaveconf_sync(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1500
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1501
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1502
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1503
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1504
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1505
        || datagram->working_counter != 1) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1506
        slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1507
        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
  1508
        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
  1509
               slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1510
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1511
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1512
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1513
    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
  1514
    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
  1515
    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
  1516
    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
  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
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1520
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1521
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1522
   Slave configuration state: PREOP.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1523
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1524
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1525
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
  1526
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1527
    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
  1528
    ec_master_t *master = fsm->master;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1529
    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
  1530
    unsigned int j;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1531
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1532
    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
  1533
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1534
    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
  1535
        slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1536
        fsm->slave_state = ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1537
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1538
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1539
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1540
    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
  1541
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1542
    // slave is now in PREOP
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1543
    slave->jiffies_preop = fsm->datagram.jiffies_received;
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1544
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1545
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1546
        EC_DBG("Slave %i is now in PREOP.\n", slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1547
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1548
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1549
    if (slave->current_state == slave->requested_state) {
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1550
        fsm->slave_state = ec_fsm_end; // successful
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1551
        if (master->debug_level) {
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1552
            EC_DBG("Finished configuration of slave %i.\n",
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1553
                   slave->ring_position);
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1554
        }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1555
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1556
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1557
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1558
    if (!slave->base_fmmu_count) { // skip FMMU configuration
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1559
        if (list_empty(&slave->sdo_confs)) { // skip SDO configuration
338
469369417422 New transition in slave conf state machine: Skip fmmu and SDO configuration.
Florian Pose <fp@igh-essen.com>
parents: 329
diff changeset
  1560
            fsm->slave_state = ec_fsm_slaveconf_saveop;
469369417422 New transition in slave conf state machine: Skip fmmu and SDO configuration.
Florian Pose <fp@igh-essen.com>
parents: 329
diff changeset
  1561
            fsm->change_new = EC_SLAVE_STATE_SAVEOP;
469369417422 New transition in slave conf state machine: Skip fmmu and SDO configuration.
Florian Pose <fp@igh-essen.com>
parents: 329
diff changeset
  1562
            fsm->change_state = ec_fsm_change_start;
469369417422 New transition in slave conf state machine: Skip fmmu and SDO configuration.
Florian Pose <fp@igh-essen.com>
parents: 329
diff changeset
  1563
            fsm->change_state(fsm); // execute immediately
469369417422 New transition in slave conf state machine: Skip fmmu and SDO configuration.
Florian Pose <fp@igh-essen.com>
parents: 329
diff changeset
  1564
            return;
469369417422 New transition in slave conf state machine: Skip fmmu and SDO configuration.
Florian Pose <fp@igh-essen.com>
parents: 329
diff changeset
  1565
        }
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1566
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1567
        // start SDO configuration
338
469369417422 New transition in slave conf state machine: Skip fmmu and SDO configuration.
Florian Pose <fp@igh-essen.com>
parents: 329
diff changeset
  1568
        fsm->slave_state = ec_fsm_slaveconf_sdoconf;
405
61d5d6457fa6 Renamed fsm->sdodata to fsm->coe_sdodata
Florian Pose <fp@igh-essen.com>
parents: 403
diff changeset
  1569
        fsm->coe_sdodata = list_entry(slave->sdo_confs.next, ec_sdo_data_t, list);
338
469369417422 New transition in slave conf state machine: Skip fmmu and SDO configuration.
Florian Pose <fp@igh-essen.com>
parents: 329
diff changeset
  1570
        fsm->coe_state = ec_fsm_coe_down_start;
469369417422 New transition in slave conf state machine: Skip fmmu and SDO configuration.
Florian Pose <fp@igh-essen.com>
parents: 329
diff changeset
  1571
        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
  1572
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1573
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1574
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1575
    // configure FMMUs
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1576
    ec_datagram_npwr(datagram, slave->station_address,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1577
                     0x0600, EC_FMMU_SIZE * slave->base_fmmu_count);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1578
    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
  1579
    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
  1580
        ec_fmmu_config(&slave->fmmus[j], slave,
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1581
                       datagram->data + EC_FMMU_SIZE * j);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1582
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1583
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1584
    ec_master_queue_datagram(master, datagram);
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1585
    fsm->slave_state = ec_fsm_slaveconf_fmmu;
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1586
}
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1587
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1588
/*****************************************************************************/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1589
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1590
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1591
   Slave configuration state: FMMU.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1592
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1593
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1594
void ec_fsm_slaveconf_fmmu(ec_fsm_t *fsm /**< finite state machine */)
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1595
{
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1596
    ec_datagram_t *datagram = &fsm->datagram;
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1597
    ec_slave_t *slave = fsm->slave;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1598
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1599
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1600
        || 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
  1601
        fsm->slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1602
        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
  1603
        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
  1604
               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
  1605
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1606
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1607
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1608
    // No CoE configuration to be applied? Jump to SAVEOP state.
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1609
    if (list_empty(&slave->sdo_confs)) { // skip SDO configuration
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1610
        // set state to SAVEOP
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1611
        fsm->slave_state = ec_fsm_slaveconf_saveop;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1612
        fsm->change_new = EC_SLAVE_STATE_SAVEOP;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1613
        fsm->change_state = ec_fsm_change_start;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1614
        fsm->change_state(fsm); // execute immediately
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1615
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1616
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1617
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1618
    // start SDO configuration
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1619
    fsm->slave_state = ec_fsm_slaveconf_sdoconf;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1620
    fsm->coe_sdodata = list_entry(slave->sdo_confs.next, ec_sdo_data_t, list);
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1621
    fsm->coe_state = ec_fsm_coe_down_start;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1622
    fsm->coe_state(fsm); // execute immediately
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1623
}
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1624
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1625
/*****************************************************************************/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1626
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1627
/**
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1628
   Slave configuration state: SDOCONF.
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1629
*/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1630
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1631
void ec_fsm_slaveconf_sdoconf(ec_fsm_t *fsm /**< finite state machine */)
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1632
{
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1633
    fsm->coe_state(fsm); // execute CoE state machine
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1634
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1635
    if (fsm->coe_state == ec_fsm_error) {
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1636
        fsm->slave->error_flag = 1;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1637
        fsm->slave_state = ec_fsm_error;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1638
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1639
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1640
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1641
    if (fsm->coe_state != ec_fsm_end) return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1642
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1643
    // Another SDO to configure?
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1644
    if (fsm->coe_sdodata->list.next != &fsm->slave->sdo_confs) {
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1645
        fsm->coe_sdodata = list_entry(fsm->coe_sdodata->list.next,
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1646
                                      ec_sdo_data_t, list);
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1647
        fsm->coe_state = ec_fsm_coe_down_start;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1648
        fsm->coe_state(fsm); // execute immediately
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1649
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1650
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1651
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1652
    // All SDOs are now configured.
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1653
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1654
    // set state to SAVEOP
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1655
    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
  1656
    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
  1657
    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
  1658
    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
  1659
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1660
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1661
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1662
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1663
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1664
   Slave configuration state: SAVEOP.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1665
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1666
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1667
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
  1668
{
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1669
    ec_master_t *master = fsm->master;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1670
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1671
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1672
    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
  1673
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1674
    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
  1675
        fsm->slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1676
        fsm->slave_state = ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1677
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1678
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1679
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1680
    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
  1681
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1682
    // slave is now in SAVEOP
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1683
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1684
    if (master->debug_level) {
411
42d239bab6ae Fixed typo.
Florian Pose <fp@igh-essen.com>
parents: 409
diff changeset
  1685
        EC_DBG("Slave %i is now in SAVEOP.\n", slave->ring_position);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1686
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1687
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1688
    if (fsm->slave->current_state == fsm->slave->requested_state) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1689
        fsm->slave_state = ec_fsm_end; // successful
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1690
        if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1691
            EC_DBG("Finished configuration of slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1692
                   slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1693
        }
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1694
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1695
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1696
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1697
    // set state to OP
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1698
    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
  1699
    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
  1700
    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
  1701
    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
  1702
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1703
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1704
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1705
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1706
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1707
   Slave configuration state: OP
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1708
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1709
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1710
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
  1711
{
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1712
    ec_master_t *master = fsm->master;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1713
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1714
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1715
    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
  1716
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1717
    if (fsm->change_state == ec_fsm_error) {
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1718
        slave->error_flag = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1719
        fsm->slave_state = ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1720
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1721
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1722
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1723
    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
  1724
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1725
    // slave is now in OP
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1726
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1727
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1728
        EC_DBG("Slave %i is now in OP.\n", slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1729
        EC_DBG("Finished configuration of slave %i.\n", slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1730
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1731
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1732
    fsm->slave_state = ec_fsm_end; // successful
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1733
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1734
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1735
/******************************************************************************
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1736
 *  SII state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1737
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1738
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1739
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1740
   SII state: START READING.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1741
   Starts reading the slave information interface.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1742
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1743
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1744
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
  1745
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1746
    ec_datagram_t *datagram = &fsm->datagram;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1747
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1748
    // initiate read operation
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1749
    if (fsm->sii_mode) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1750
        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
  1751
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1752
    else {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1753
        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
  1754
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1755
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1756
    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
  1757
    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
  1758
    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
  1759
    ec_master_queue_datagram(fsm->master, datagram);
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1760
    fsm->sii_state = ec_fsm_sii_read_check;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1761
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1762
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
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1765
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1766
   SII state: READ CHECK.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1767
   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
  1768
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1769
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1770
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
  1771
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1772
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1773
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1774
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1775
        || datagram->working_counter != 1) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1776
        EC_ERR("SII: Reception of read datagram failed.\n");
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1777
        fsm->sii_state = ec_fsm_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1778
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1779
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1780
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1781
    fsm->sii_start = datagram->cycles_sent;
397
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1782
    fsm->sii_check_once_more = 1;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1783
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1784
    // 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
  1785
    if (fsm->sii_mode) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1786
        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
  1787
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1788
    else {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1789
        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
  1790
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1791
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1792
    ec_master_queue_datagram(fsm->master, datagram);
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1793
    fsm->sii_state = ec_fsm_sii_read_fetch;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1794
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1795
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1796
/*****************************************************************************/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1797
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1798
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1799
   SII state: READ FETCH.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1800
   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
  1801
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1802
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1803
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
  1804
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1805
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1806
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1807
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1808
        || datagram->working_counter != 1) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1809
        EC_ERR("SII: Reception of check/fetch datagram failed.\n");
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1810
        fsm->sii_state = ec_fsm_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1811
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1812
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1813
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1814
    // check "busy bit"
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1815
    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
  1816
        // still busy... timeout?
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1817
        if (datagram->cycles_received
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1818
            - fsm->sii_start >= (cycles_t) 10 * cpu_khz) {
397
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1819
            if (!fsm->sii_check_once_more) {
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1820
                EC_ERR("SII: Read timeout.\n");
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1821
                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
  1822
#if 0
397
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1823
                EC_DBG("SII busy: %02X %02X %02X %02X\n",
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1824
                       EC_READ_U8(datagram->data + 0),
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1825
                       EC_READ_U8(datagram->data + 1),
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1826
                       EC_READ_U8(datagram->data + 2),
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1827
                       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
  1828
#endif
397
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1829
                return;
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1830
            }
c5d2fb08e43f Serveral changes to avoid timeouts under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 395
diff changeset
  1831
            fsm->sii_check_once_more = 0;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1832
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1833
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1834
        // 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
  1835
        if (fsm->sii_mode) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1836
            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
  1837
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1838
        else {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1839
            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
  1840
        }
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1841
        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
  1842
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1843
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1844
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1845
#if 0
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1846
    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
  1847
           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
  1848
           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
  1849
           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
  1850
           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
  1851
#endif
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1852
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1853
    // SII value received.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1854
    memcpy(fsm->sii_value, datagram->data + 6, 4);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1855
    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
  1856
}
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
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1860
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1861
   SII state: START WRITING.
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1862
   Starts reading the slave information interface.
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1863
*/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1864
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1865
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
  1866
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1867
    ec_datagram_t *datagram = &fsm->datagram;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1868
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1869
    // initiate write operation
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1870
    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
  1871
    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
  1872
    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
  1873
    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
  1874
    memcpy(datagram->data + 6, fsm->sii_value, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1875
    ec_master_queue_datagram(fsm->master, datagram);
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1876
    fsm->sii_state = ec_fsm_sii_write_check;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1877
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1878
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1879
/*****************************************************************************/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1880
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1881
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1882
   SII state: WRITE CHECK.
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1883
*/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1884
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1885
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
  1886
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1887
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1888
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1889
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1890
        || datagram->working_counter != 1) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1891
        EC_ERR("SII: Reception of write datagram failed.\n");
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1892
        fsm->sii_state = ec_fsm_error;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1893
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1894
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1895
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1896
    fsm->sii_start = datagram->cycles_sent;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1897
    fsm->sii_check_once_more = 1;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1898
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1899
    // issue check/fetch datagram
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1900
    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
  1901
    ec_master_queue_datagram(fsm->master, datagram);
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1902
    fsm->sii_state = ec_fsm_sii_write_check2;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1903
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1904
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1905
/*****************************************************************************/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1906
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1907
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1908
   SII state: WRITE CHECK 2.
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1909
*/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1910
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1911
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
  1912
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1913
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1914
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1915
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1916
        || datagram->working_counter != 1) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1917
        EC_ERR("SII: Reception of write check datagram failed.\n");
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1918
        fsm->sii_state = ec_fsm_error;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1919
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1920
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1921
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1922
    if (EC_READ_U8(datagram->data + 1) & 0x82) {
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1923
        // still busy... timeout?
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1924
        if (datagram->cycles_received
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1925
            - fsm->sii_start >= (cycles_t) 10 * cpu_khz) {
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1926
            if (!fsm->sii_check_once_more) {
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1927
                EC_ERR("SII: Write timeout.\n");
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1928
                fsm->sii_state = ec_fsm_error;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1929
                return;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1930
            }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1931
            fsm->sii_check_once_more = 0;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1932
        }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1933
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1934
        // issue check/fetch datagram again
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1935
        ec_master_queue_datagram(fsm->master, datagram);
395
8b1194e51cf2 BUGFIX: Added returns after timeout in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 391
diff changeset
  1936
        return;
8b1194e51cf2 BUGFIX: Added returns after timeout in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 391
diff changeset
  1937
    }
8b1194e51cf2 BUGFIX: Added returns after timeout in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 391
diff changeset
  1938
8b1194e51cf2 BUGFIX: Added returns after timeout in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 391
diff changeset
  1939
    if (EC_READ_U8(datagram->data + 1) & 0x40) {
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1940
        EC_ERR("SII: Write operation failed!\n");
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1941
        fsm->sii_state = ec_fsm_error;
395
8b1194e51cf2 BUGFIX: Added returns after timeout in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 391
diff changeset
  1942
        return;
8b1194e51cf2 BUGFIX: Added returns after timeout in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 391
diff changeset
  1943
    }
8b1194e51cf2 BUGFIX: Added returns after timeout in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 391
diff changeset
  1944
8b1194e51cf2 BUGFIX: Added returns after timeout in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 391
diff changeset
  1945
    // success
8b1194e51cf2 BUGFIX: Added returns after timeout in SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 391
diff changeset
  1946
    fsm->sii_state = ec_fsm_end;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1947
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1948
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1949
/******************************************************************************
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1950
 *  state change state machine
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1951
 *****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1952
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1953
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1954
   Change state: START.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1955
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1956
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1957
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
  1958
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1959
    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
  1960
    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
  1961
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1962
    fsm->change_take_time = 1;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1963
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1964
    // write new state to slave
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1965
    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
  1966
    EC_WRITE_U16(datagram->data, fsm->change_new);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1967
    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
  1968
    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
  1969
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1970
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1971
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1972
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1973
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1974
   Change state: CHECK.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1975
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1976
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1977
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
  1978
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1979
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1980
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1981
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1982
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1983
        fsm->change_state = ec_fsm_error;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1984
        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
  1985
               fsm->slave->ring_position);
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1986
        return;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1987
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1988
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1989
    if (fsm->change_take_time) {
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1990
        fsm->change_take_time = 0;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1991
        fsm->change_jiffies = datagram->jiffies_sent;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1992
    }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1993
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1994
    if (datagram->working_counter != 1) {
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1995
        if (datagram->jiffies_received - fsm->change_jiffies >= 3 * HZ) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1996
            fsm->change_state = ec_fsm_error;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1997
            EC_ERR("Failed to set state 0x%02X on slave %i: Slave did not"
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1998
                   " respond.\n", fsm->change_new, fsm->slave->ring_position);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1999
            return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2000
        }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2001
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2002
        // repeat writing new state to slave
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2003
        ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2004
        EC_WRITE_U16(datagram->data, fsm->change_new);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2005
        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
  2006
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2007
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2008
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2009
    fsm->change_take_time = 1;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2010
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2011
    // read AL status from slave
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2012
    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
  2013
    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
  2014
    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
  2015
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2016
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2017
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2018
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2019
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2020
   Change state: STATUS.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2021
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2022
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2023
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
  2024
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2025
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2026
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2027
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2028
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2029
        || datagram->working_counter != 1) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2030
        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
  2031
        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
  2032
               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
  2033
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2034
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2035
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2036
    if (fsm->change_take_time) {
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2037
        fsm->change_take_time = 0;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2038
        fsm->change_jiffies = datagram->jiffies_sent;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2039
    }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2040
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2041
    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
  2042
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2043
    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
  2044
        // state has been set successfully
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2045
        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
  2046
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2047
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2048
402
03e31ac14047 Renamed EC_ACK to EC_SLAVE_STATE_ACK_ERR
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
  2049
    if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2050
        // state change error
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2051
        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
  2052
               " (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
  2053
               slave->current_state);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2054
        // fetch AL status error code
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2055
        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
  2056
        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
  2057
        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
  2058
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2059
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2060
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2061
    if (datagram->jiffies_received
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2062
        - 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
  2063
        // timeout while checking
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2064
        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
  2065
        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
  2066
               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
  2067
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2068
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2069
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2070
    // still old state: check again
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2071
    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
  2072
    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
  2073
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2074
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2075
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2076
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  2077
/**
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2078
   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
  2079
*/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2080
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2081
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
  2082
    {0x0001, "Unspecified error"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2083
    {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
  2084
    {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
  2085
    {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
  2086
    {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
  2087
    {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
  2088
    {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
  2089
    {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
  2090
    {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
  2091
    {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
  2092
    {0x001A, "Synchronisation error"},
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2093
    {0x001B, "Sync manager watchdog"},
297
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2094
    {0x001C, "Invalid sync manager types"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2095
    {0x001D, "Invalid output configuration"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2096
    {0x001E, "Invalid input configuration"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2097
    {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
  2098
    {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
  2099
    {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
  2100
    {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
  2101
    {0x0023, "Slave needs SAVEOP"},
297
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2102
    {0x0030, "Invalid DC SYNCH configuration"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2103
    {0x0031, "Invalid DC latch configuration"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2104
    {0x0032, "PLL error"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2105
    {0x0033, "Invalid DC IO error"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2106
    {0x0034, "Invalid DC timeout error"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2107
    {0x0042, "MBOX EOE"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2108
    {0x0043, "MBOX COE"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2109
    {0x0044, "MBOX FOE"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2110
    {0x0045, "MBOX SOE"},
ac2a057a8ef2 Added missing AL status code messages.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
  2111
    {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
  2112
    {}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2113
};
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2114
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  2115
/*****************************************************************************/
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2116
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2117
/**
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2118
   Change state: CODE.
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2119
*/
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2120
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2121
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
  2122
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2123
    ec_datagram_t *datagram = &fsm->datagram;
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2124
    ec_slave_t *slave = fsm->slave;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2125
    uint32_t code;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2126
    const ec_code_msg_t *al_msg;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2127
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2128
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2129
        || datagram->working_counter != 1) {
407
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2130
        EC_WARN("Reception of AL status code datagram failed.\n");
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2131
    }
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2132
    else {
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2133
        if ((code = EC_READ_U16(datagram->data))) {
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2134
            for (al_msg = al_status_messages; al_msg->code; al_msg++) {
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2135
                if (al_msg->code != code) continue;
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2136
                EC_ERR("AL status message 0x%04X: \"%s\".\n",
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2137
                       al_msg->code, al_msg->message);
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2138
                break;
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2139
            }
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2140
            if (!al_msg->code)
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2141
                EC_ERR("Unknown AL status code 0x%04X.\n", code);
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2142
        }
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2143
    }
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2144
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2145
    // acknowledge "old" slave state
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2146
    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
  2147
    EC_WRITE_U16(datagram->data, slave->current_state);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2148
    ec_master_queue_datagram(fsm->master, datagram);
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2149
    fsm->change_state = ec_fsm_change_ack;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2150
}
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2151
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2152
/*****************************************************************************/
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2153
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2154
/**
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2155
   Change state: ACK.
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2156
*/
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2157
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2158
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
  2159
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2160
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2161
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2162
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2163
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2164
        || datagram->working_counter != 1) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2165
        fsm->change_state = ec_fsm_error;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2166
        EC_ERR("Reception of state ack datagram failed.\n");
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2167
        return;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2168
    }
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2169
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2170
    fsm->change_take_time = 1;
301
dfe8192a7e19 Ack timeout in FSM.
Florian Pose <fp@igh-essen.com>
parents: 300
diff changeset
  2171
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2172
    // read new AL status
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2173
    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
  2174
    ec_master_queue_datagram(fsm->master, datagram);
311
197489292da8 Renamed ACK2 state to CHECK ACK.
Florian Pose <fp@igh-essen.com>
parents: 310
diff changeset
  2175
    fsm->change_state = ec_fsm_change_check_ack;
197489292da8 Renamed ACK2 state to CHECK ACK.
Florian Pose <fp@igh-essen.com>
parents: 310
diff changeset
  2176
}
197489292da8 Renamed ACK2 state to CHECK ACK.
Florian Pose <fp@igh-essen.com>
parents: 310
diff changeset
  2177
197489292da8 Renamed ACK2 state to CHECK ACK.
Florian Pose <fp@igh-essen.com>
parents: 310
diff changeset
  2178
/*****************************************************************************/
197489292da8 Renamed ACK2 state to CHECK ACK.
Florian Pose <fp@igh-essen.com>
parents: 310
diff changeset
  2179
197489292da8 Renamed ACK2 state to CHECK ACK.
Florian Pose <fp@igh-essen.com>
parents: 310
diff changeset
  2180
/**
197489292da8 Renamed ACK2 state to CHECK ACK.
Florian Pose <fp@igh-essen.com>
parents: 310
diff changeset
  2181
   Change state: CHECK ACK.
197489292da8 Renamed ACK2 state to CHECK ACK.
Florian Pose <fp@igh-essen.com>
parents: 310
diff changeset
  2182
*/
197489292da8 Renamed ACK2 state to CHECK ACK.
Florian Pose <fp@igh-essen.com>
parents: 310
diff changeset
  2183
197489292da8 Renamed ACK2 state to CHECK ACK.
Florian Pose <fp@igh-essen.com>
parents: 310
diff changeset
  2184
void ec_fsm_change_check_ack(ec_fsm_t *fsm /**< finite state machine */)
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2185
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2186
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2187
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2188
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2189
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2190
        || datagram->working_counter != 1) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2191
        fsm->change_state = ec_fsm_error;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2192
        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
  2193
        return;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2194
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  2195
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2196
    if (fsm->change_take_time) {
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2197
        fsm->change_take_time = 0;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2198
        fsm->change_jiffies = datagram->jiffies_sent;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2199
    }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2200
407
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2201
    slave->current_state = EC_READ_U8(datagram->data);
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2202
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2203
    if (!(slave->current_state & EC_SLAVE_STATE_ACK_ERR)) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2204
        fsm->change_state = ec_fsm_error;
407
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2205
        EC_INFO("Acknowledged state 0x%02X on slave %i.\n",
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2206
                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
  2207
        return;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  2208
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  2209
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2210
    if (datagram->jiffies_received
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2211
        - fsm->change_jiffies >= 100 * HZ / 1000) { // 100ms
301
dfe8192a7e19 Ack timeout in FSM.
Florian Pose <fp@igh-essen.com>
parents: 300
diff changeset
  2212
        // timeout while checking
dfe8192a7e19 Ack timeout in FSM.
Florian Pose <fp@igh-essen.com>
parents: 300
diff changeset
  2213
        slave->current_state = EC_SLAVE_STATE_UNKNOWN;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  2214
        fsm->change_state = ec_fsm_error;
407
b73c9f7be5a1 BUGFIX: Fixed faulty state acknowledge behavior.
Florian Pose <fp@igh-essen.com>
parents: 405
diff changeset
  2215
        EC_ERR("Timeout while acknowledging state 0x%02X on slave %i.\n",
301
dfe8192a7e19 Ack timeout in FSM.
Florian Pose <fp@igh-essen.com>
parents: 300
diff changeset
  2216
               fsm->change_new, slave->ring_position);
dfe8192a7e19 Ack timeout in FSM.
Florian Pose <fp@igh-essen.com>
parents: 300
diff changeset
  2217
        return;
dfe8192a7e19 Ack timeout in FSM.
Florian Pose <fp@igh-essen.com>
parents: 300
diff changeset
  2218
    }
dfe8192a7e19 Ack timeout in FSM.
Florian Pose <fp@igh-essen.com>
parents: 300
diff changeset
  2219
dfe8192a7e19 Ack timeout in FSM.
Florian Pose <fp@igh-essen.com>
parents: 300
diff changeset
  2220
    // reread new AL status
dfe8192a7e19 Ack timeout in FSM.
Florian Pose <fp@igh-essen.com>
parents: 300
diff changeset
  2221
    ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
dfe8192a7e19 Ack timeout in FSM.
Florian Pose <fp@igh-essen.com>
parents: 300
diff changeset
  2222
    ec_master_queue_datagram(fsm->master, datagram);
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2223
}
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  2224
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2225
/******************************************************************************
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2226
 *  CoE dictionary state machine
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2227
 *****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2228
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2229
/**
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2230
   CoE state: DICT START.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2231
*/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2232
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2233
void ec_fsm_coe_dict_start(ec_fsm_t *fsm /**< finite state machine */)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2234
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2235
    ec_datagram_t *datagram = &fsm->datagram;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2236
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2237
    uint8_t *data;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2238
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2239
    if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2240
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2241
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2242
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2243
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2244
    EC_WRITE_U16(data, 0x8 << 12); // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2245
    EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2246
    EC_WRITE_U8 (data + 3, 0x00);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2247
    EC_WRITE_U16(data + 4, 0x0000);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2248
    EC_WRITE_U16(data + 6, 0x0001); // deliver all SDOs!
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2249
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2250
    ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2251
    fsm->coe_state = ec_fsm_coe_dict_request;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2252
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2253
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2254
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2255
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2256
/**
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2257
   CoE state: DICT REQUEST.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2258
*/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2259
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2260
void ec_fsm_coe_dict_request(ec_fsm_t *fsm /**< finite state machine */)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2261
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2262
    ec_datagram_t *datagram = &fsm->datagram;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2263
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2264
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2265
    if (datagram->state != EC_DATAGRAM_RECEIVED
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2266
        || datagram->working_counter != 1) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2267
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2268
        EC_ERR("Reception of CoE dictionary request failed.\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2269
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2270
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2271
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2272
    fsm->coe_start = datagram->cycles_sent;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2273
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2274
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2275
    ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2276
    fsm->coe_state = ec_fsm_coe_dict_check;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2277
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2278
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2279
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2280
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2281
/**
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2282
   CoE state: DICT CHECK.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2283
*/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2284
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2285
void ec_fsm_coe_dict_check(ec_fsm_t *fsm /**< finite state machine */)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2286
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2287
    ec_datagram_t *datagram = &fsm->datagram;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2288
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2289
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2290
    if (datagram->state != EC_DATAGRAM_RECEIVED
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2291
        || datagram->working_counter != 1) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2292
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2293
        EC_ERR("Reception of CoE mailbox check datagram failed.\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2294
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2295
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2296
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2297
    if (!ec_slave_mbox_check(datagram)) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2298
        if (datagram->cycles_received
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2299
            - fsm->coe_start >= (cycles_t) 100 * cpu_khz) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2300
            fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2301
            EC_ERR("Timeout while checking SDO dictionary on slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2302
                   slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2303
            return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2304
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2305
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2306
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2307
        ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2308
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2309
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2310
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2311
    // Fetch response
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2312
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2313
    ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2314
    fsm->coe_state = ec_fsm_coe_dict_response;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2315
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2316
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2317
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2318
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2319
/**
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2320
   CoE state: DICT RESPONSE.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2321
*/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2322
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2323
void ec_fsm_coe_dict_response(ec_fsm_t *fsm /**< finite state machine */)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2324
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2325
    ec_datagram_t *datagram = &fsm->datagram;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2326
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2327
    uint8_t *data, mbox_prot;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2328
    size_t rec_size;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2329
    unsigned int sdo_count, i;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2330
    uint16_t sdo_index;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2331
    ec_sdo_t *sdo;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2332
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2333
    if (datagram->state != EC_DATAGRAM_RECEIVED
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2334
        || datagram->working_counter != 1) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2335
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2336
        EC_ERR("Reception of CoE dictionary response failed.\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2337
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2338
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2339
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2340
    if (!(data = ec_slave_mbox_fetch(slave, datagram,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2341
				     &mbox_prot, &rec_size))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2342
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2343
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2344
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2345
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2346
    if (mbox_prot != 0x03) { // CoE
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2347
        EC_WARN("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2348
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2349
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2350
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2351
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2352
    if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2353
        (EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2354
        EC_ERR("SDO information error response at slave %i!\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2355
               slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2356
        ec_canopen_abort_msg(EC_READ_U32(data + 6));
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2357
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2358
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2359
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2360
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2361
    if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2362
        (EC_READ_U8 (data + 2) & 0x7F) != 0x02) { // Get OD List response
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2363
        EC_ERR("Invalid SDO list response at slave %i!\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2364
               slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2365
        ec_print_data(data, rec_size);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2366
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2367
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2368
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2369
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2370
    if (rec_size < 8) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2371
        EC_ERR("Invalid data size!\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2372
        ec_print_data(data, rec_size);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2373
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2374
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2375
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2376
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2377
    sdo_count = (rec_size - 8) / 2;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2378
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2379
    for (i = 0; i < sdo_count; i++) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2380
        sdo_index = EC_READ_U16(data + 8 + i * 2);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2381
        if (!sdo_index) {
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2382
            EC_WARN("SDO dictionary of slave %i contains index 0x0000.\n",
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2383
                    slave->ring_position);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2384
            continue;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2385
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2386
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2387
        if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_ATOMIC))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2388
            EC_ERR("Failed to allocate memory for SDO!\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2389
            fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2390
            return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2391
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2392
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2393
        if (ec_sdo_init(sdo, sdo_index, slave)) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2394
            EC_ERR("Failed to init SDO!\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2395
            fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2396
            return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2397
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2398
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2399
        if (kobject_add(&sdo->kobj)) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2400
            EC_ERR("Failed to add kobject.\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2401
            kobject_put(&sdo->kobj); // free
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2402
            fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2403
            return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2404
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2405
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2406
        list_add_tail(&sdo->list, &slave->sdo_dictionary);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2407
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2408
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2409
    if (EC_READ_U8(data + 2) & 0x80) { // more messages waiting. check again.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2410
        fsm->coe_start = datagram->cycles_sent;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2411
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2412
        ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2413
        fsm->coe_state = ec_fsm_coe_dict_check;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2414
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2415
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2416
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2417
    if (list_empty(&slave->sdo_dictionary)) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2418
        // no SDOs in dictionary. finished.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2419
        fsm->coe_state = ec_fsm_end; // success
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2420
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2421
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2422
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2423
    // fetch SDO descriptions
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2424
    fsm->coe_sdo = list_entry(slave->sdo_dictionary.next, ec_sdo_t, list);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2425
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2426
    if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2427
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2428
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2429
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2430
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2431
    EC_WRITE_U16(data, 0x8 << 12); // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2432
    EC_WRITE_U8 (data + 2, 0x03); // Get object description request
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2433
    EC_WRITE_U8 (data + 3, 0x00);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2434
    EC_WRITE_U16(data + 4, 0x0000);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2435
    EC_WRITE_U16(data + 6, fsm->coe_sdo->index); // SDO index
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2436
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2437
    ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2438
    fsm->coe_state = ec_fsm_coe_dict_desc_request;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2439
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2440
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2441
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2442
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2443
/**
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2444
   CoE state: DICT DESC REQUEST.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2445
*/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2446
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2447
void ec_fsm_coe_dict_desc_request(ec_fsm_t *fsm /**< finite state machine */)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2448
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2449
    ec_datagram_t *datagram = &fsm->datagram;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2450
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2451
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2452
    if (datagram->state != EC_DATAGRAM_RECEIVED
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2453
        || datagram->working_counter != 1) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2454
        fsm->coe_state = ec_fsm_error;
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2455
        EC_ERR("Reception of CoE SDO description"
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2456
               " request failed on slave %i.\n", slave->ring_position);
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2457
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2458
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2459
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2460
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2461
    fsm->coe_start = datagram->cycles_sent;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2462
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2463
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2464
    ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2465
    fsm->coe_state = ec_fsm_coe_dict_desc_check;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2466
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2467
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2468
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2469
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2470
/**
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2471
   CoE state: DICT DESC CHECK.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2472
*/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2473
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2474
void ec_fsm_coe_dict_desc_check(ec_fsm_t *fsm /**< finite state machine */)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2475
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2476
    ec_datagram_t *datagram = &fsm->datagram;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2477
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2478
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2479
    if (datagram->state != EC_DATAGRAM_RECEIVED
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2480
        || datagram->working_counter != 1) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2481
        fsm->coe_state = ec_fsm_error;
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2482
        EC_ERR("Reception of CoE mailbox check datagram failed on slave %i.\n",
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2483
               slave->ring_position);
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2484
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2485
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2486
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2487
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2488
    if (!ec_slave_mbox_check(datagram)) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2489
        if (datagram->cycles_received
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2490
            - fsm->coe_start >= (cycles_t) 100 * cpu_khz) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2491
            fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2492
            EC_ERR("Timeout while checking SDO description on slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2493
                   slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2494
            return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2495
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2496
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2497
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2498
        ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2499
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2500
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2501
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2502
    // Fetch response
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2503
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2504
    ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2505
    fsm->coe_state = ec_fsm_coe_dict_desc_response;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2506
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2507
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2508
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2509
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2510
/**
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2511
   CoE state: DICT DESC RESPONSE.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2512
*/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2513
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2514
void ec_fsm_coe_dict_desc_response(ec_fsm_t *fsm /**< finite state machine */)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2515
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2516
    ec_master_t *master = fsm->master;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2517
    ec_datagram_t *datagram = &fsm->datagram;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2518
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2519
    ec_sdo_t *sdo = fsm->coe_sdo;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2520
    uint8_t *data, mbox_prot;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2521
    size_t rec_size, name_size;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2522
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2523
    if (datagram->state != EC_DATAGRAM_RECEIVED
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2524
        || datagram->working_counter != 1) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2525
        fsm->coe_state = ec_fsm_error;
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2526
        EC_ERR("Reception of CoE SDO description"
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2527
               "response failed on slave %i.\n", slave->ring_position);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2528
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2529
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2530
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2531
    if (!(data = ec_slave_mbox_fetch(slave, datagram,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2532
				     &mbox_prot, &rec_size))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2533
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2534
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2535
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2536
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2537
    if (mbox_prot != 0x03) { // CoE
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2538
        EC_WARN("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2539
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2540
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2541
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2542
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2543
    if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2544
        (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2545
        EC_ERR("SDO information error response at slave %i while"
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2546
               " fetching SDO 0x%04X!\n", slave->ring_position,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2547
               sdo->index);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2548
        ec_canopen_abort_msg(EC_READ_U32(data + 6));
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2549
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2550
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2551
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2552
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2553
    if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2554
        (EC_READ_U8 (data + 2) & 0x7F) != 0x04 || // Object desc. response
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2555
        EC_READ_U16(data + 6) != sdo->index) { // SDO index
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2556
        EC_ERR("Invalid object description response at slave %i while"
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2557
               " fetching SDO 0x%04X!\n", slave->ring_position,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2558
               sdo->index);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2559
        ec_print_data(data, rec_size);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2560
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2561
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2562
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2563
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2564
    if (rec_size < 12) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2565
        EC_ERR("Invalid data size!\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2566
        ec_print_data(data, rec_size);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2567
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2568
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2569
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2570
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2571
    sdo->subindices = EC_READ_U8(data + 10);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2572
    sdo->object_code = EC_READ_U8(data + 11);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2573
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2574
    name_size = rec_size - 12;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2575
    if (name_size) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2576
        if (!(sdo->name = kmalloc(name_size + 1, GFP_ATOMIC))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2577
            EC_ERR("Failed to allocate SDO name!\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2578
            fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2579
            return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2580
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2581
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2582
        memcpy(sdo->name, data + 12, name_size);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2583
        sdo->name[name_size] = 0;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2584
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2585
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2586
    if (EC_READ_U8(data + 2) & 0x80) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2587
        EC_ERR("Fragment follows (not implemented)!\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2588
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2589
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2590
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2591
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2592
    if (!sdo->subindices) { // no entries
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2593
        // another SDO description to fetch?
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2594
        if (fsm->coe_sdo->list.next != &slave->sdo_dictionary) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2595
            fsm->coe_sdo = list_entry(fsm->coe_sdo->list.next, ec_sdo_t, list);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2596
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2597
            if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2598
                fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2599
                return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2600
            }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2601
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2602
            EC_WRITE_U16(data, 0x8 << 12); // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2603
            EC_WRITE_U8 (data + 2, 0x03); // Get object description request
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2604
            EC_WRITE_U8 (data + 3, 0x00);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2605
            EC_WRITE_U16(data + 4, 0x0000);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2606
            EC_WRITE_U16(data + 6, fsm->coe_sdo->index); // SDO index
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2607
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2608
            ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2609
            fsm->coe_state = ec_fsm_coe_dict_desc_request;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2610
            return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2611
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2612
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2613
        if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2614
            EC_DBG("Finished fetching SDO descriptions.\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2615
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2616
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2617
        fsm->coe_state = ec_fsm_end;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2618
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2619
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2620
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2621
    fsm->coe_subindex = 1;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2622
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2623
    if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2624
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2625
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2626
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2627
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2628
    EC_WRITE_U16(data, 0x8 << 12); // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2629
    EC_WRITE_U8 (data + 2, 0x05); // Get entry description request
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2630
    EC_WRITE_U8 (data + 3, 0x00);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2631
    EC_WRITE_U16(data + 4, 0x0000);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2632
    EC_WRITE_U16(data + 6, sdo->index); // SDO index
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2633
    EC_WRITE_U8 (data + 8, fsm->coe_subindex); // SDO subindex
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2634
    EC_WRITE_U8 (data + 9, 0x00); // value info (no values)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2635
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2636
    ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2637
    fsm->coe_state = ec_fsm_coe_dict_entry_request;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2638
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2639
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2640
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2641
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2642
/**
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2643
   CoE state: DICT ENTRY REQUEST.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2644
*/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2645
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2646
void ec_fsm_coe_dict_entry_request(ec_fsm_t *fsm /**< finite state machine */)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2647
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2648
    ec_datagram_t *datagram = &fsm->datagram;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2649
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2650
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2651
    if (datagram->state != EC_DATAGRAM_RECEIVED
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2652
        || datagram->working_counter != 1) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2653
        fsm->coe_state = ec_fsm_error;
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2654
        EC_ERR("Reception of CoE SDO entry request failed on slave %i.\n",
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2655
               slave->ring_position);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2656
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2657
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2658
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2659
    fsm->coe_start = datagram->cycles_sent;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2660
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2661
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2662
    ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2663
    fsm->coe_state = ec_fsm_coe_dict_entry_check;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2664
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2665
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2666
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2667
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2668
/**
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2669
   CoE state: DICT ENTRY CHECK.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2670
*/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2671
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2672
void ec_fsm_coe_dict_entry_check(ec_fsm_t *fsm /**< finite state machine */)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2673
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2674
    ec_datagram_t *datagram = &fsm->datagram;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2675
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2676
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2677
    if (datagram->state != EC_DATAGRAM_RECEIVED
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2678
        || datagram->working_counter != 1) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2679
        fsm->coe_state = ec_fsm_error;
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2680
        EC_ERR("Reception of CoE mailbox check datagram failed on slave %i.\n",
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2681
               slave->ring_position);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2682
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2683
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2684
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2685
    if (!ec_slave_mbox_check(datagram)) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2686
        if (datagram->cycles_received
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2687
            - fsm->coe_start >= (cycles_t) 100 * cpu_khz) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2688
            fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2689
            EC_ERR("Timeout while checking SDO entry on slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2690
                   slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2691
            return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2692
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2693
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2694
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2695
        ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2696
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2697
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2698
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2699
    // Fetch response
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2700
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2701
    ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2702
    fsm->coe_state = ec_fsm_coe_dict_entry_response;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2703
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2704
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2705
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2706
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2707
/**
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2708
   CoE state: DICT ENTRY RESPONSE.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2709
*/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2710
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2711
void ec_fsm_coe_dict_entry_response(ec_fsm_t *fsm /**< finite state machine */)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2712
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2713
    ec_datagram_t *datagram = &fsm->datagram;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2714
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2715
    ec_sdo_t *sdo = fsm->coe_sdo;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2716
    uint8_t *data, mbox_prot;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2717
    size_t rec_size, data_size;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2718
    ec_sdo_entry_t *entry;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2719
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2720
    if (datagram->state != EC_DATAGRAM_RECEIVED
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2721
        || datagram->working_counter != 1) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2722
        fsm->coe_state = ec_fsm_error;
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2723
        EC_ERR("Reception of CoE SDO description"
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  2724
               " response failed on slave %i.\n", slave->ring_position);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2725
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2726
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2727
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2728
    if (!(data = ec_slave_mbox_fetch(slave, datagram,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2729
				     &mbox_prot, &rec_size))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2730
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2731
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2732
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2733
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2734
    if (mbox_prot != 0x03) { // CoE
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2735
        EC_WARN("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2736
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2737
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2738
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2739
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2740
    if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2741
        (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2742
        EC_ERR("SDO information error response at slave %i while"
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2743
               " fetching SDO entry 0x%04X:%i!\n", slave->ring_position,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2744
               sdo->index, fsm->coe_subindex);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2745
        ec_canopen_abort_msg(EC_READ_U32(data + 6));
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2746
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2747
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2748
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2749
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2750
    if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2751
        (EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2752
        EC_READ_U16(data + 6) != sdo->index || // SDO index
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2753
        EC_READ_U8(data + 8) != fsm->coe_subindex) { // SDO subindex
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2754
        EC_ERR("Invalid entry description response at slave %i while"
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2755
               " fetching SDO entry 0x%04X:%i!\n", slave->ring_position,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2756
               sdo->index, fsm->coe_subindex);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2757
        ec_print_data(data, rec_size);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2758
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2759
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2760
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2761
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2762
    if (rec_size < 16) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2763
        EC_ERR("Invalid data size!\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2764
        ec_print_data(data, rec_size);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2765
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2766
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2767
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2768
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2769
    data_size = rec_size - 16;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2770
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2771
    if (!(entry = (ec_sdo_entry_t *)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2772
          kmalloc(sizeof(ec_sdo_entry_t), GFP_ATOMIC))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2773
        EC_ERR("Failed to allocate entry!\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2774
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2775
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2776
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2777
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2778
    if (ec_sdo_entry_init(entry, fsm->coe_subindex, sdo)) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2779
        EC_ERR("Failed to init entry!\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2780
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2781
	return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2782
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2783
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2784
    entry->data_type = EC_READ_U16(data + 10);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2785
    entry->bit_length = EC_READ_U16(data + 12);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2786
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2787
    if (data_size) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2788
        if (!(entry->description = kmalloc(data_size + 1, GFP_ATOMIC))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2789
            EC_ERR("Failed to allocate SDO entry name!\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2790
            fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2791
            return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2792
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2793
        memcpy(entry->description, data + 16, data_size);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2794
        entry->description[data_size] = 0;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2795
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2796
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2797
    if (kobject_add(&entry->kobj)) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2798
        EC_ERR("Failed to add kobject.\n");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2799
        kobject_put(&entry->kobj); // free
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2800
        fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2801
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2802
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2803
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2804
    list_add_tail(&entry->list, &sdo->entries);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2805
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2806
    if (fsm->coe_subindex < sdo->subindices) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2807
        fsm->coe_subindex++;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2808
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2809
        if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2810
            fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2811
            return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2812
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2813
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2814
        EC_WRITE_U16(data, 0x8 << 12); // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2815
        EC_WRITE_U8 (data + 2, 0x05); // Get entry description request
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2816
        EC_WRITE_U8 (data + 3, 0x00);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2817
        EC_WRITE_U16(data + 4, 0x0000);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2818
        EC_WRITE_U16(data + 6, sdo->index); // SDO index
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2819
        EC_WRITE_U8 (data + 8, fsm->coe_subindex); // SDO subindex
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2820
        EC_WRITE_U8 (data + 9, 0x00); // value info (no values)
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2821
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2822
        ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2823
        fsm->coe_state = ec_fsm_coe_dict_entry_request;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2824
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2825
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2826
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2827
    // another SDO description to fetch?
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2828
    if (fsm->coe_sdo->list.next != &slave->sdo_dictionary) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2829
        fsm->coe_sdo = list_entry(fsm->coe_sdo->list.next, ec_sdo_t, list);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2830
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2831
        if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8))) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2832
            fsm->coe_state = ec_fsm_error;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2833
            return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2834
        }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2835
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2836
        EC_WRITE_U16(data, 0x8 << 12); // SDO information
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2837
        EC_WRITE_U8 (data + 2, 0x03); // Get object description request
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2838
        EC_WRITE_U8 (data + 3, 0x00);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2839
        EC_WRITE_U16(data + 4, 0x0000);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2840
        EC_WRITE_U16(data + 6, fsm->coe_sdo->index); // SDO index
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2841
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2842
        ec_master_queue_datagram(fsm->master, datagram);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2843
        fsm->coe_state = ec_fsm_coe_dict_desc_request;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2844
        return;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2845
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2846
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2847
    fsm->coe_state = ec_fsm_end;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2848
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2849
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2850
/******************************************************************************
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2851
 *  CoE state machine
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2852
 *****************************************************************************/
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2853
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2854
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2855
   CoE state: DOWN START.
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2856
*/
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2857
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2858
void ec_fsm_coe_down_start(ec_fsm_t *fsm /**< finite state machine */)
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2859
{
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2860
    ec_datagram_t *datagram = &fsm->datagram;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2861
    ec_slave_t *slave = fsm->slave;
405
61d5d6457fa6 Renamed fsm->sdodata to fsm->coe_sdodata
Florian Pose <fp@igh-essen.com>
parents: 403
diff changeset
  2862
    ec_sdo_data_t *sdodata = fsm->coe_sdodata;
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2863
    uint8_t *data;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2864
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2865
    EC_INFO("Downloading SDO 0x%04X:%i to slave %i.\n",
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2866
            sdodata->index, sdodata->subindex, slave->ring_position);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2867
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2868
    if (slave->sii_rx_mailbox_size < 6 + 10 + sdodata->size) {
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2869
        EC_ERR("SDO fragmenting not supported yet!\n");
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2870
        fsm->coe_state = ec_fsm_error;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2871
        return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2872
    }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2873
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2874
    if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03,
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2875
                                            sdodata->size + 10))) {
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2876
        fsm->coe_state = ec_fsm_error;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2877
        return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2878
    }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2879
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2880
    EC_WRITE_U16(data, 0x2 << 12); // SDO request
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2881
    EC_WRITE_U8 (data + 2, (0x1 // size specified
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2882
                            | 0x1 << 5)); // Download request
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2883
    EC_WRITE_U16(data + 3, sdodata->index);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2884
    EC_WRITE_U8 (data + 5, sdodata->subindex);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2885
    EC_WRITE_U32(data + 6, sdodata->size);
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  2886
    memcpy(data + 10, sdodata->data, sdodata->size);
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2887
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2888
    ec_master_queue_datagram(fsm->master, datagram);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2889
    fsm->coe_state = ec_fsm_coe_down_request;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2890
}
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2891
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2892
/*****************************************************************************/
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2893
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2894
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2895
   CoE state: DOWN REQUEST.
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2896
*/
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2897
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2898
void ec_fsm_coe_down_request(ec_fsm_t *fsm /**< finite state machine */)
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2899
{
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2900
    ec_datagram_t *datagram = &fsm->datagram;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2901
    ec_slave_t *slave = fsm->slave;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2902
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2903
    if (datagram->state != EC_DATAGRAM_RECEIVED
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2904
        || datagram->working_counter != 1) {
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2905
        fsm->coe_state = ec_fsm_error;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2906
        EC_ERR("Reception of CoE download request failed.\n");
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2907
        return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2908
    }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2909
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2910
    fsm->coe_start = datagram->cycles_sent;
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2911
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2912
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2913
    ec_master_queue_datagram(fsm->master, datagram);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2914
    fsm->coe_state = ec_fsm_coe_down_check;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2915
}
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2916
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2917
/*****************************************************************************/
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2918
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2919
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2920
   CoE state: DOWN CHECK.
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2921
*/
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2922
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2923
void ec_fsm_coe_down_check(ec_fsm_t *fsm /**< finite state machine */)
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2924
{
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2925
    ec_datagram_t *datagram = &fsm->datagram;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2926
    ec_slave_t *slave = fsm->slave;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2927
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2928
    if (datagram->state != EC_DATAGRAM_RECEIVED
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2929
        || datagram->working_counter != 1) {
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2930
        fsm->coe_state = ec_fsm_error;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2931
        EC_ERR("Reception of CoE mailbox check datagram failed.\n");
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2932
        return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2933
    }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2934
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2935
    if (!ec_slave_mbox_check(datagram)) {
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2936
        if (datagram->cycles_received
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  2937
            - fsm->coe_start >= (cycles_t) 100 * cpu_khz) {
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2938
            fsm->coe_state = ec_fsm_error;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2939
            EC_ERR("Timeout while checking SDO configuration on slave %i.\n",
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2940
                   slave->ring_position);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2941
            return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2942
        }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2943
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2944
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2945
        ec_master_queue_datagram(fsm->master, datagram);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2946
        return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2947
    }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2948
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2949
    // Fetch response
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2950
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2951
    ec_master_queue_datagram(fsm->master, datagram);
339
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 338
diff changeset
  2952
    fsm->coe_state = ec_fsm_coe_down_response;
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 338
diff changeset
  2953
}
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 338
diff changeset
  2954
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 338
diff changeset
  2955
/*****************************************************************************/
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 338
diff changeset
  2956
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 338
diff changeset
  2957
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  2958
   CoE state: DOWN RESPONSE.
339
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 338
diff changeset
  2959
*/
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 338
diff changeset
  2960
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 338
diff changeset
  2961
void ec_fsm_coe_down_response(ec_fsm_t *fsm /**< finite state machine */)
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2962
{
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2963
    ec_datagram_t *datagram = &fsm->datagram;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2964
    ec_slave_t *slave = fsm->slave;
391
7d67195702dd Removed additional loop in coe_down FSM; renamed mbox_type to mbox_prot.
Florian Pose <fp@igh-essen.com>
parents: 390
diff changeset
  2965
    uint8_t *data, mbox_prot;
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2966
    size_t rec_size;
405
61d5d6457fa6 Renamed fsm->sdodata to fsm->coe_sdodata
Florian Pose <fp@igh-essen.com>
parents: 403
diff changeset
  2967
    ec_sdo_data_t *sdodata = fsm->coe_sdodata;
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2968
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2969
    if (datagram->state != EC_DATAGRAM_RECEIVED
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2970
        || datagram->working_counter != 1) {
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2971
        fsm->coe_state = ec_fsm_error;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2972
        EC_ERR("Reception of CoE download response failed.\n");
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2973
        return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2974
    }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2975
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  2976
    if (!(data = ec_slave_mbox_fetch(slave, datagram,
391
7d67195702dd Removed additional loop in coe_down FSM; renamed mbox_type to mbox_prot.
Florian Pose <fp@igh-essen.com>
parents: 390
diff changeset
  2977
				     &mbox_prot, &rec_size))) {
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2978
        fsm->coe_state = ec_fsm_error;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2979
        return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2980
    }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2981
391
7d67195702dd Removed additional loop in coe_down FSM; renamed mbox_type to mbox_prot.
Florian Pose <fp@igh-essen.com>
parents: 390
diff changeset
  2982
    if (mbox_prot != 0x03) { // CoE
7d67195702dd Removed additional loop in coe_down FSM; renamed mbox_type to mbox_prot.
Florian Pose <fp@igh-essen.com>
parents: 390
diff changeset
  2983
        EC_WARN("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
7d67195702dd Removed additional loop in coe_down FSM; renamed mbox_type to mbox_prot.
Florian Pose <fp@igh-essen.com>
parents: 390
diff changeset
  2984
        fsm->coe_state = ec_fsm_error;
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  2985
	return;
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  2986
    }
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  2987
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2988
    if (rec_size < 6) {
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2989
        fsm->coe_state = ec_fsm_error;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2990
        EC_ERR("Received data is too small (%i bytes):\n", rec_size);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2991
        ec_print_data(data, rec_size);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2992
        return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2993
    }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2994
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2995
    if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2996
        EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2997
        fsm->coe_state = ec_fsm_error;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2998
        EC_ERR("SDO download 0x%04X:%X (%i bytes) aborted on slave %i.\n",
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  2999
               sdodata->index, sdodata->subindex, sdodata->size,
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3000
               slave->ring_position);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3001
        if (rec_size < 10) {
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3002
            EC_ERR("Incomplete Abort command:\n");
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3003
            ec_print_data(data, rec_size);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3004
        }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3005
        else
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3006
            ec_canopen_abort_msg(EC_READ_U32(data + 6));
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3007
        return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3008
    }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3009
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3010
    if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3011
        EC_READ_U8 (data + 2) >> 5 != 0x3 || // Download response
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3012
        EC_READ_U16(data + 3) != sdodata->index || // index
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3013
        EC_READ_U8 (data + 5) != sdodata->subindex) { // subindex
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3014
        fsm->coe_state = ec_fsm_error;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3015
        EC_ERR("SDO download 0x%04X:%X (%i bytes) failed:\n",
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3016
               sdodata->index, sdodata->subindex, sdodata->size);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3017
        EC_ERR("Invalid SDO download response at slave %i!\n",
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3018
               slave->ring_position);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3019
        ec_print_data(data, rec_size);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3020
        return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3021
    }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3022
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3023
    fsm->coe_state = ec_fsm_end; // success
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3024
}
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3025
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3026
/*****************************************************************************/
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3027
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3028
/**
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3029
   SDO abort messages.
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3030
   The "abort SDO transfer request" supplies an abort code,
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3031
   which can be translated to clear text. This table does
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3032
   the mapping of the codes and messages.
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3033
*/
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3034
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3035
const ec_code_msg_t sdo_abort_messages[] = {
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3036
    {0x05030000, "Toggle bit not changed"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3037
    {0x05040000, "SDO protocol timeout"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3038
    {0x05040001, "Client/Server command specifier not valid or unknown"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3039
    {0x05040005, "Out of memory"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3040
    {0x06010000, "Unsupported access to an object"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3041
    {0x06010001, "Attempt to read a write-only object"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3042
    {0x06010002, "Attempt to write a read-only object"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3043
    {0x06020000, "This object does not exist in the object directory"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3044
    {0x06040041, "The object cannot be mapped into the PDO"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3045
    {0x06040042, "The number and length of the objects to be mapped would"
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3046
     " exceed the PDO length"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3047
    {0x06040043, "General parameter incompatibility reason"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3048
    {0x06040047, "Gerneral internal incompatibility in device"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3049
    {0x06060000, "Access failure due to a hardware error"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3050
    {0x06070010, "Data type does not match, length of service parameter does"
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3051
     " not match"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3052
    {0x06070012, "Data type does not match, length of service parameter too"
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3053
     " high"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3054
    {0x06070013, "Data type does not match, length of service parameter too"
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3055
     " low"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3056
    {0x06090011, "Subindex does not exist"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3057
    {0x06090030, "Value range of parameter exceeded"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3058
    {0x06090031, "Value of parameter written too high"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3059
    {0x06090032, "Value of parameter written too low"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3060
    {0x06090036, "Maximum value is less than minimum value"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3061
    {0x08000000, "General error"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3062
    {0x08000020, "Data cannot be transferred or stored to the application"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3063
    {0x08000021, "Data cannot be transferred or stored to the application"
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3064
     " because of local control"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3065
    {0x08000022, "Data cannot be transferred or stored to the application"
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3066
     " because of the present device state"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3067
    {0x08000023, "Object dictionary dynamic generation fails or no object"
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3068
     " dictionary is present"},
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3069
    {}
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3070
};
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3071
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3072
/*****************************************************************************/
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3073
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3074
/**
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3075
   Outputs an SDO abort message.
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3076
*/
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3077
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3078
void ec_canopen_abort_msg(uint32_t abort_code)
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3079
{
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3080
    const ec_code_msg_t *abort_msg;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3081
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3082
    for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) {
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3083
        if (abort_msg->code == abort_code) {
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3084
            EC_ERR("SDO abort message 0x%08X: \"%s\".\n",
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3085
                   abort_msg->code, abort_msg->message);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3086
            return;
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3087
        }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3088
    }
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3089
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3090
    EC_ERR("Unknown SDO abort code 0x%08X.\n", abort_code);
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3091
}
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3092
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3093
/******************************************************************************
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3094
 *  Common state functions
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  3095
 *****************************************************************************/
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  3096
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  3097
/**
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3098
   State: ERROR.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3099
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3100
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3101
void ec_fsm_error(ec_fsm_t *fsm /**< finite state machine */)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3102
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3103
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3104
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3105
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3106
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3107
/**
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3108
   State: END.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3109
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3110
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3111
void ec_fsm_end(ec_fsm_t *fsm /**< finite state machine */)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3112
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3113
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3114
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  3115
/*****************************************************************************/