master/fsm_coe.c
author Florian Pose <fp@igh-essen.com>
Mon, 15 Jun 2009 15:29:24 +0000
changeset 1469 873e4ee3d5ec
parent 1468 0a804ddbaf93
child 1494 6c632c8f45cc
permissions -rw-r--r--
Improved newlines in debug data output.
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    11
 *  published by the Free Software Foundation.
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    16
 *  Public License for more details.
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1339
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1339
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1339
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1339
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1339
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
   \file
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
   EtherCAT CoE state machines.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "globals.h"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "master.h"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "mailbox.h"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "fsm_coe.h"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
    44
/** Maximum time in ms to wait for responses when reading out the dictionary.
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
    45
 */
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
    46
#define EC_FSM_COE_DICT_TIMEOUT 3000
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
    47
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
    48
/*****************************************************************************/
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
    49
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
void ec_fsm_coe_dict_start(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
void ec_fsm_coe_dict_request(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
void ec_fsm_coe_dict_check(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
void ec_fsm_coe_dict_response(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
void ec_fsm_coe_down_start(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
void ec_fsm_coe_down_request(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
void ec_fsm_coe_down_check(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
void ec_fsm_coe_down_response(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
void ec_fsm_coe_up_start(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
void ec_fsm_coe_up_request(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
void ec_fsm_coe_up_check(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
void ec_fsm_coe_up_response(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
void ec_fsm_coe_end(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
void ec_fsm_coe_error(ec_fsm_coe_t *);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
/**
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    80
   SDO abort messages.
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    81
   The "abort SDO transfer request" supplies an abort code,
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
   which can be translated to clear text. This table does
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
   the mapping of the codes and messages.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
const ec_code_msg_t sdo_abort_messages[] = {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    {0x05030000, "Toggle bit not changed"},
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    88
    {0x05040000, "SDO protocol timeout"},
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
    {0x05040001, "Client/Server command specifier not valid or unknown"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    {0x05040005, "Out of memory"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    {0x06010000, "Unsupported access to an object"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    {0x06010001, "Attempt to read a write-only object"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    {0x06010002, "Attempt to write a read-only object"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    {0x06020000, "This object does not exist in the object directory"},
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    95
    {0x06040041, "The object cannot be mapped into the PDO"},
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    {0x06040042, "The number and length of the objects to be mapped would"
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    97
     " exceed the PDO length"},
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    {0x06040043, "General parameter incompatibility reason"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    {0x06040047, "Gerneral internal incompatibility in device"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    {0x06060000, "Access failure due to a hardware error"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    {0x06070010, "Data type does not match, length of service parameter does"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
     " not match"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    {0x06070012, "Data type does not match, length of service parameter too"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
     " high"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    {0x06070013, "Data type does not match, length of service parameter too"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
     " low"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
    {0x06090011, "Subindex does not exist"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    {0x06090030, "Value range of parameter exceeded"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
    {0x06090031, "Value of parameter written too high"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    {0x06090032, "Value of parameter written too low"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    {0x06090036, "Maximum value is less than minimum value"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    {0x08000000, "General error"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    {0x08000020, "Data cannot be transferred or stored to the application"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
    {0x08000021, "Data cannot be transferred or stored to the application"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
     " because of local control"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    {0x08000022, "Data cannot be transferred or stored to the application"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
     " because of the present device state"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    {0x08000023, "Object dictionary dynamic generation fails or no object"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
     " dictionary is present"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
    {}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
};
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
/**
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   126
   Outputs an SDO abort message.
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
void ec_canopen_abort_msg(uint32_t abort_code)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
    const ec_code_msg_t *abort_msg;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
        if (abort_msg->code == abort_code) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   135
            EC_ERR("SDO abort message 0x%08X: \"%s\".\n",
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
                   abort_msg->code, abort_msg->message);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   141
    EC_ERR("Unknown SDO abort code 0x%08X.\n", abort_code);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
   Constructor.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
void ec_fsm_coe_init(ec_fsm_coe_t *fsm, /**< finite state machine */
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
                     ec_datagram_t *datagram /**< datagram */
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
                     )
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
    fsm->state = NULL;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    fsm->datagram = datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
   Destructor.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
void ec_fsm_coe_clear(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
/**
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   171
   Starts reading a slaves' SDO dictionary.
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
void ec_fsm_coe_dictionary(ec_fsm_coe_t *fsm, /**< finite state machine */
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
                           ec_slave_t *slave /**< EtherCAT slave */
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
                           )
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
    fsm->slave = slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
    fsm->state = ec_fsm_coe_dict_start;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
/**
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   185
   Starts to transfer an SDO to/from a slave.
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   186
*/
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   187
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   188
void ec_fsm_coe_transfer(
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   189
        ec_fsm_coe_t *fsm, /**< State machine. */
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   190
        ec_slave_t *slave, /**< EtherCAT slave. */
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   191
        ec_sdo_request_t *request /**< SDO request. */
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   192
        )
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
    fsm->slave = slave;
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   195
    fsm->request = request;
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   196
    if (request->dir == EC_DIR_OUTPUT)
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   197
        fsm->state = ec_fsm_coe_down_start;
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   198
    else
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   199
        fsm->state = ec_fsm_coe_up_start;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
   Executes the current state of the state machine.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
   \return false, if state machine has terminated
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
int ec_fsm_coe_exec(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
    fsm->state(fsm);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
    return fsm->state != ec_fsm_coe_end && fsm->state != ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
   Returns, if the state machine terminated with success.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
   \return non-zero if successful.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
int ec_fsm_coe_success(ec_fsm_coe_t *fsm /**< Finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
    return fsm->state == ec_fsm_coe_end;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   228
/*****************************************************************************/
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   229
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   230
/** Check if the received data are a CoE emergency request.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   231
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   232
 * If the check is positive, the emergency request is output.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   233
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   234
 * \return The data were an emergency request.
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   235
 */
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   236
int ec_fsm_coe_check_emergency(
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   237
        ec_fsm_coe_t *fsm, /**< Finite state machine */
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   238
        const uint8_t *data, /**< CoE mailbox data. */
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   239
        size_t size /**< CoE mailbox data size. */
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   240
        )
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   241
{
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   242
    if (size < 2 || ((EC_READ_U16(data) >> 12) & 0x0F) != 0x01)
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   243
        return 0;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   244
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   245
    if (size < 10) {
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   246
        EC_WARN("Received incomplete CoE Emergency request from slave %u:\n",
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   247
                fsm->slave->ring_position);
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   248
        ec_print_data(data, size);
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   249
        return 1;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   250
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   251
    
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   252
    EC_INFO("CoE Emergency Request received from slave %u:\n",
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   253
            fsm->slave->ring_position);
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   254
    EC_INFO("Error code 0x%04X, Error register 0x%02X, data:\n",
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   255
            EC_READ_U16(data + 2), EC_READ_U8(data + 4));
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   256
    ec_print_data(data + 5, 5);
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   257
    return 1;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   258
}
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   259
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
/******************************************************************************
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
 *  CoE dictionary state machine
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
 *****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
   CoE state: DICT START.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
void ec_fsm_coe_dict_start(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
    uint8_t *data;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   274
    if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
825
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   275
        EC_ERR("Slave %u does not support CoE!\n", slave->ring_position);
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   276
        fsm->state = ec_fsm_coe_error;
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   277
        return;
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   278
    }
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   279
1219
aa030fb1e980 Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents: 1169
diff changeset
   280
    if (slave->sii.has_general && !slave->sii.coe_details.enable_sdo_info) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   281
        EC_ERR("Slave %u does not support SDO information service!\n",
1219
aa030fb1e980 Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents: 1169
diff changeset
   282
                slave->ring_position);
aa030fb1e980 Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents: 1169
diff changeset
   283
        fsm->state = ec_fsm_coe_error;
aa030fb1e980 Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents: 1169
diff changeset
   284
        return;
aa030fb1e980 Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents: 1169
diff changeset
   285
    }
aa030fb1e980 Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents: 1169
diff changeset
   286
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   287
    data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   288
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   293
    EC_WRITE_U16(data, 0x8 << 12); // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
    EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
    EC_WRITE_U8 (data + 3, 0x00);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
    EC_WRITE_U16(data + 4, 0x0000);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   297
    EC_WRITE_U16(data + 6, 0x0001); // deliver all SDOs!
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   299
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
    fsm->state = ec_fsm_coe_dict_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
   CoE state: DICT REQUEST.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   307
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
void ec_fsm_coe_dict_request(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   315
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   316
        return; // FIXME: request again?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   317
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   318
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   319
        fsm->state = ec_fsm_coe_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   320
        EC_ERR("Failed to receive CoE dictionary request datagram for"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
   321
               " slave %u (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   322
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   323
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   324
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   325
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   326
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   327
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   328
        EC_ERR("Reception of CoE dictionary request failed on slave %u: ",
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   329
                slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   330
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   332
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   334
    fsm->jiffies_start = datagram->jiffies_sent;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   336
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   337
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
    fsm->state = ec_fsm_coe_dict_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
   CoE state: DICT CHECK.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
void ec_fsm_coe_dict_check(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   352
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   353
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   354
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   355
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   356
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   357
        EC_ERR("Failed to receive CoE mailbox check datagram for slave %u"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
   358
                " (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   359
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   360
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   361
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   362
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   363
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   364
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   365
        EC_ERR("Reception of CoE mailbox check datagram failed on slave %u: ",
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
               slave->ring_position);
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   367
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   369
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   370
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   371
    if (!ec_slave_mbox_check(datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   372
        unsigned long diff_ms =
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   373
            (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   374
        if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
            fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   376
            EC_ERR("Timeout while waiting for SDO dictionary list response "
1111
6aaf6a0c375c Improved timeout error messages.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   377
                    "on slave %u.\n", slave->ring_position);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   381
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   382
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   383
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   384
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   385
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   386
    // Fetch response
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   387
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   388
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   389
    fsm->state = ec_fsm_coe_dict_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   390
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   391
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   392
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   393
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   394
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   395
   CoE state: DICT RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   396
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   397
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   398
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   399
void ec_fsm_coe_dict_response(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   400
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   401
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   402
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   403
    uint8_t *data, mbox_prot;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   404
    size_t rec_size;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   405
    unsigned int sdo_count, i;
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   406
    uint16_t sdo_index, fragments_left;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   407
    ec_sdo_t *sdo;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   408
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   409
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   410
        return; // FIXME: request again?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   411
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   412
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   413
        fsm->state = ec_fsm_coe_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   414
        EC_ERR("Failed to receive CoE dictionary response datagram for"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
   415
               " slave %u (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   416
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   417
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   418
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   419
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   420
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   421
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   422
        EC_ERR("Reception of CoE dictionary response failed on slave %u: ",
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   423
                slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   424
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   425
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   426
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   427
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   428
    data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   429
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   430
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   432
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
    if (mbox_prot != 0x03) { // CoE
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 436
diff changeset
   435
        EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   436
        fsm->state = ec_fsm_coe_error;
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   437
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   438
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   439
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   440
    if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) {
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   441
        // check for CoE response again
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   442
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   443
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   444
        fsm->state = ec_fsm_coe_dict_check;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   445
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   446
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   447
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   448
    if (rec_size < 3) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   449
        EC_ERR("Received corrupted SDO dictionary response (size %u).\n",
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   450
                rec_size);
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   451
        fsm->state = ec_fsm_coe_error;
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   452
        return;
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   453
    }
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   454
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   455
    if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
        (EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   457
        EC_ERR("SDO information error response at slave %u!\n",
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   458
               slave->ring_position);
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   459
        if (rec_size < 10) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   460
            EC_ERR("Incomplete SDO information error response:\n");
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   461
            ec_print_data(data, rec_size);
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   462
        } else {
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   463
            ec_canopen_abort_msg(EC_READ_U32(data + 6));
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   464
        }
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   465
        fsm->state = ec_fsm_coe_error;
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   466
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   467
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   468
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   469
    if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   470
        (EC_READ_U8 (data + 2) & 0x7F) != 0x02) { // Get OD List response
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   471
        if (fsm->slave->master->debug_level) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   472
            EC_DBG("Invalid SDO list response at slave %u! Retrying...\n",
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   473
                    slave->ring_position);
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   474
            ec_print_data(data, rec_size);
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   475
        }
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   476
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   477
        fsm->retries = EC_FSM_RETRIES;
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   478
        fsm->state = ec_fsm_coe_dict_check;
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   479
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   480
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   481
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   482
    if (rec_size < 8 || rec_size % 2) {
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   483
        EC_ERR("Invalid data size %u!\n", rec_size);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   484
        ec_print_data(data, rec_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   485
        fsm->state = ec_fsm_coe_error;
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   486
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   487
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   488
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   489
    sdo_count = (rec_size - 8) / 2;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   490
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   491
    for (i = 0; i < sdo_count; i++) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   492
        sdo_index = EC_READ_U16(data + 8 + i * 2);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   493
        if (!sdo_index) {
461
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
   494
            if (slave->master->debug_level)
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   495
                EC_WARN("SDO dictionary of slave %u contains index 0x0000.\n",
461
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
   496
                        slave->ring_position);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   497
            continue;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   498
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   499
998
05a24788f3b2 Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   500
        if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_KERNEL))) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   501
            EC_ERR("Failed to allocate memory for SDO!\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   502
            fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   503
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   504
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   505
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 991
diff changeset
   506
        ec_sdo_init(sdo, slave, sdo_index);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   507
        list_add_tail(&sdo->list, &slave->sdo_dictionary);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   508
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   509
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   510
    fragments_left = EC_READ_U16(data + 4);
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   511
    if (slave->master->debug_level && fragments_left) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   512
        EC_DBG("SDO list fragments left: %u\n", fragments_left);
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   513
    }
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   514
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   515
    if (EC_READ_U8(data + 2) & 0x80 || fragments_left) { // more messages waiting. check again.
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   516
        fsm->jiffies_start = datagram->jiffies_sent;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   517
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   518
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   519
        fsm->state = ec_fsm_coe_dict_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   520
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   521
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   522
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   523
    if (list_empty(&slave->sdo_dictionary)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   524
        // no SDOs in dictionary. finished.
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   525
        fsm->state = ec_fsm_coe_end; // success
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   526
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   527
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   528
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   529
    // fetch SDO descriptions
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   530
    fsm->sdo = list_entry(slave->sdo_dictionary.next, ec_sdo_t, list);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   531
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   532
    data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   533
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   534
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   535
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   536
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   537
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   538
    EC_WRITE_U16(data, 0x8 << 12); // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   539
    EC_WRITE_U8 (data + 2, 0x03); // Get object description request
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   540
    EC_WRITE_U8 (data + 3, 0x00);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   541
    EC_WRITE_U16(data + 4, 0x0000);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   542
    EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   543
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   544
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   545
    fsm->state = ec_fsm_coe_dict_desc_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   546
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   547
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   548
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   549
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   550
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   551
   CoE state: DICT DESC REQUEST.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   552
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   553
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   554
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   555
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   556
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   557
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   558
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   559
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   560
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   561
        return; // FIXME: check for response first?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   562
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   563
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   564
        fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   565
        EC_ERR("Failed to receive CoE SDO description request datagram for"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
   566
               " slave %u (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   567
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   568
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   569
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   570
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   571
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   572
        fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   573
        EC_ERR("Reception of CoE SDO description"
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   574
                " request failed on slave %u: ", slave->ring_position);
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   575
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   576
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   577
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   578
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   579
    fsm->jiffies_start = datagram->jiffies_sent;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   580
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   581
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   582
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   583
    fsm->state = ec_fsm_coe_dict_desc_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   584
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   585
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   586
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   587
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   588
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   589
   CoE state: DICT DESC CHECK.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   590
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   591
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   592
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   593
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   594
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   595
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   596
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   597
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   598
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   599
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   600
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   601
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   602
        EC_ERR("Failed to receive CoE mailbox check datagram from slave %u"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
   603
                " (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   604
                slave->ring_position, datagram->state);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   605
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   606
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   607
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   608
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   609
        fsm->state = ec_fsm_coe_error;
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   610
        EC_ERR("Reception of CoE mailbox check"
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   611
                " datagram failed on slave %u: ", slave->ring_position);
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   612
        ec_datagram_print_wc_error(datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   613
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   614
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   615
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   616
    if (!ec_slave_mbox_check(datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   617
        unsigned long diff_ms =
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   618
            (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   619
        if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   620
            fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   621
            EC_ERR("Timeout while waiting for SDO object description "
1111
6aaf6a0c375c Improved timeout error messages.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   622
                    "response on slave %u.\n", slave->ring_position);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   623
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   624
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   625
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   626
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   627
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   628
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   629
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   630
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   631
    // Fetch response
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   632
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   633
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   634
    fsm->state = ec_fsm_coe_dict_desc_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   635
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   636
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   637
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   638
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   639
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   640
   CoE state: DICT DESC RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   641
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   642
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   643
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   644
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *fsm
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   645
                                   /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   646
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   647
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   648
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   649
    ec_sdo_t *sdo = fsm->sdo;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   650
    uint8_t *data, mbox_prot;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   651
    size_t rec_size, name_size;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   652
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   653
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   654
        return; // FIXME: request again?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   655
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   656
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   657
        fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   658
        EC_ERR("Failed to receive CoE SDO description response datagram from"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
   659
               " slave %u (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   660
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   661
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   662
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   663
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   664
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   665
        fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   666
        EC_ERR("Reception of CoE SDO description"
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   667
                " response failed on slave %u: ", slave->ring_position);
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   668
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   669
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   670
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   671
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   672
    data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   673
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   674
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   675
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   676
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   677
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   678
    if (mbox_prot != 0x03) { // CoE
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 436
diff changeset
   679
        EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   680
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   681
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   682
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   683
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   684
    if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) {
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   685
        // check for CoE response again
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   686
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   687
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   688
        fsm->state = ec_fsm_coe_dict_desc_check;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   689
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   690
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   691
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   692
    if (rec_size < 3) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   693
        EC_ERR("Received corrupted SDO description response (size %u).\n",
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   694
                rec_size);
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   695
        fsm->state = ec_fsm_coe_error;
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   696
        return;
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   697
    }
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   698
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   699
    if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   700
        (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   701
        EC_ERR("SDO information error response at slave %u while"
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   702
               " fetching SDO 0x%04X!\n", slave->ring_position,
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   703
               sdo->index);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   704
        ec_canopen_abort_msg(EC_READ_U32(data + 6));
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   705
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   706
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   707
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   708
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   709
    if (rec_size < 8) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   710
        EC_ERR("Received corrupted SDO description response (size %u).\n",
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   711
                rec_size);
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   712
        fsm->state = ec_fsm_coe_error;
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   713
        return;
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   714
    }
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   715
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   716
    if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   717
        (EC_READ_U8 (data + 2) & 0x7F) != 0x04 || // Object desc. response
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   718
        EC_READ_U16(data + 6) != sdo->index) { // SDO index
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   719
        if (fsm->slave->master->debug_level) {
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   720
            EC_DBG("Invalid object description response at slave %u while"
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   721
                    " fetching SDO 0x%04X!\n", slave->ring_position,
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   722
                    sdo->index);
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   723
            ec_print_data(data, rec_size);
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   724
        }
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   725
        // check for CoE response again
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   726
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   727
        fsm->retries = EC_FSM_RETRIES;
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   728
        fsm->state = ec_fsm_coe_dict_desc_check;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   729
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   730
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   731
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   732
    if (rec_size < 12) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   733
        EC_ERR("Invalid data size!\n");
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   734
        ec_print_data(data, rec_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   735
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   736
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   737
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   738
962
ea83a7aab57a Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
   739
    sdo->max_subindex = EC_READ_U8(data + 10);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   740
    sdo->object_code = EC_READ_U8(data + 11);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   741
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   742
    name_size = rec_size - 12;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   743
    if (name_size) {
998
05a24788f3b2 Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   744
        if (!(sdo->name = kmalloc(name_size + 1, GFP_KERNEL))) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   745
            EC_ERR("Failed to allocate SDO name!\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   746
            fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   747
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   748
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   749
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   750
        memcpy(sdo->name, data + 12, name_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   751
        sdo->name[name_size] = 0;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   752
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   753
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   754
    if (EC_READ_U8(data + 2) & 0x80) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   755
        EC_ERR("Fragment follows (not implemented)!\n");
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   756
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   757
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   758
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   759
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   760
    // start fetching entries
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   761
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   762
    fsm->subindex = 0;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   763
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   764
    data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   765
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   766
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   767
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   768
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   769
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   770
    EC_WRITE_U16(data, 0x8 << 12); // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   771
    EC_WRITE_U8 (data + 2, 0x05); // Get entry description request
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   772
    EC_WRITE_U8 (data + 3, 0x00);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   773
    EC_WRITE_U16(data + 4, 0x0000);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   774
    EC_WRITE_U16(data + 6, sdo->index); // SDO index
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   775
    EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex
1382
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   776
    EC_WRITE_U8 (data + 9, 0x01); // value info (access rights only)
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   777
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   778
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   779
    fsm->state = ec_fsm_coe_dict_entry_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   780
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   781
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   782
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   783
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   784
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   785
   CoE state: DICT ENTRY REQUEST.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   786
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   787
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   788
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   789
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *fsm
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   790
                                   /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   791
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   792
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   793
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   794
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   795
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   796
        return; // FIXME: check for response first?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   797
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   798
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   799
        fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   800
        EC_ERR("Failed to receive CoE SDO entry request datagram for"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
   801
               " slave %u (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   802
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   803
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   804
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   805
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   806
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   807
        fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   808
        EC_ERR("Reception of CoE SDO entry request failed on slave %u: ",
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   809
                slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   810
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   811
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   812
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   813
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   814
    fsm->jiffies_start = datagram->jiffies_sent;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   815
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   816
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   817
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   818
    fsm->state = ec_fsm_coe_dict_entry_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   819
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   820
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   821
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   822
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   823
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   824
   CoE state: DICT ENTRY CHECK.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   825
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   826
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   827
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *fsm
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   828
                                 /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   829
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   830
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   831
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   832
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   833
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   834
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   835
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   836
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   837
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   838
        EC_ERR("Failed to receive CoE mailbox check datagram from slave %u"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
   839
                " (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   840
               slave->ring_position, datagram->state);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   841
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   842
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   843
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   844
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   845
        fsm->state = ec_fsm_coe_error;
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   846
        EC_ERR("Reception of CoE mailbox check"
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   847
                " datagram failed on slave %u: ", slave->ring_position);
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   848
        ec_datagram_print_wc_error(datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   849
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   850
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   851
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   852
    if (!ec_slave_mbox_check(datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   853
        unsigned long diff_ms =
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   854
            (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   855
        if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   856
            fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   857
            EC_ERR("Timeout while waiting for SDO entry description response "
1111
6aaf6a0c375c Improved timeout error messages.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   858
                    "on slave %u.\n", slave->ring_position);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   859
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   860
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   861
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   862
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   863
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   864
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   865
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   866
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   867
    // Fetch response
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   868
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   869
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   870
    fsm->state = ec_fsm_coe_dict_entry_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   871
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   872
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   873
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   874
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   875
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   876
   CoE state: DICT ENTRY RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   877
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   878
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   879
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   880
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *fsm
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   881
                                    /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   882
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   883
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   884
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   885
    ec_sdo_t *sdo = fsm->sdo;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   886
    uint8_t *data, mbox_prot;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   887
    size_t rec_size, data_size;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   888
    ec_sdo_entry_t *entry;
1382
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   889
    u16 word;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   890
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   891
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   892
        return; // FIXME: request again?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   893
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   894
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   895
        fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   896
        EC_ERR("Failed to receive CoE SDO description response datagram from"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
   897
               " slave %u (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
   898
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   899
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   900
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   901
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   902
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   903
        fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   904
        EC_ERR("Reception of CoE SDO description"
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   905
                " response failed on slave %u: ", slave->ring_position);
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   906
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   907
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   908
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   909
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   910
    data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   911
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   912
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   913
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   914
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   915
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   916
    if (mbox_prot != 0x03) { // CoE
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 436
diff changeset
   917
        EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   918
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   919
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   920
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   921
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   922
    if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) {
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   923
        // check for CoE response again
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   924
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   925
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   926
        fsm->state = ec_fsm_coe_dict_entry_check;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   927
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   928
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   929
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   930
    if (rec_size < 3) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   931
        EC_ERR("Received corrupted SDO entry description response "
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   932
                "(size %u).\n", rec_size);
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   933
        fsm->state = ec_fsm_coe_error;
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   934
        return;
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   935
    }
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   936
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   937
    if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   938
        (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   939
        EC_ERR("SDO information error response at slave %u while"
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   940
               " fetching SDO entry 0x%04X:%02X!\n", slave->ring_position,
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   941
               sdo->index, fsm->subindex);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   942
        ec_canopen_abort_msg(EC_READ_U32(data + 6));
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   943
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   944
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   945
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   946
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   947
    if (rec_size < 9) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   948
        EC_ERR("Received corrupted SDO entry description response "
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   949
                "(size %u).\n", rec_size);
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   950
        fsm->state = ec_fsm_coe_error;
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   951
        return;
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   952
    }
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   953
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   954
    if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   955
        (EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   956
        EC_READ_U16(data + 6) != sdo->index || // SDO index
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   957
        EC_READ_U8(data + 8) != fsm->subindex) { // SDO subindex
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   958
        if (fsm->slave->master->debug_level) {
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   959
            EC_DBG("Invalid entry description response at slave %u while"
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   960
                    " fetching SDO entry 0x%04X:%02X!\n", slave->ring_position,
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   961
                    sdo->index, fsm->subindex);
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   962
            ec_print_data(data, rec_size);
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   963
        }
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   964
        // check for CoE response again
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   965
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   966
        fsm->retries = EC_FSM_RETRIES;
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   967
        fsm->state = ec_fsm_coe_dict_entry_check;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   968
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   969
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   970
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   971
    if (rec_size < 16) {
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   972
        EC_ERR("Invalid data size %u!\n", rec_size);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   973
        ec_print_data(data, rec_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   974
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   975
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   976
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   977
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   978
    data_size = rec_size - 16;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   979
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   980
    if (!(entry = (ec_sdo_entry_t *)
998
05a24788f3b2 Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   981
          kmalloc(sizeof(ec_sdo_entry_t), GFP_KERNEL))) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   982
        EC_ERR("Failed to allocate entry!\n");
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   983
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   984
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   985
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   986
991
2548ca639b1f Removed kobject from sdo entry.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   987
    ec_sdo_entry_init(entry, sdo, fsm->subindex);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   988
    entry->data_type = EC_READ_U16(data + 10);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   989
    entry->bit_length = EC_READ_U16(data + 12);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   990
1382
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   991
    // read access rights
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   992
    word = EC_READ_U16(data + 14);
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   993
    entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP] = word & 0x0001;
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   994
    entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = (word >> 1)  & 0x0001;
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   995
    entry->read_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 2)  & 0x0001;
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   996
    entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP] = (word >> 3) & 0x0001;
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   997
    entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = (word >> 4)  & 0x0001;
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   998
    entry->write_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 5)  & 0x0001;
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   999
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1000
    if (data_size) {
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 476
diff changeset
  1001
        uint8_t *desc;
998
05a24788f3b2 Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  1002
        if (!(desc = kmalloc(data_size + 1, GFP_KERNEL))) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1003
            EC_ERR("Failed to allocate SDO entry name!\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1004
            fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1005
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1006
        }
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 476
diff changeset
  1007
        memcpy(desc, data + 16, data_size);
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 476
diff changeset
  1008
        desc[data_size] = 0;
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 476
diff changeset
  1009
        entry->description = desc;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1010
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1011
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1012
    list_add_tail(&entry->list, &sdo->entries);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1013
962
ea83a7aab57a Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1014
    if (fsm->subindex < sdo->max_subindex) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1015
        fsm->subindex++;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1016
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1017
        data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1018
        if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1019
            fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1020
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1021
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1022
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1023
        EC_WRITE_U16(data, 0x8 << 12); // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1024
        EC_WRITE_U8 (data + 2, 0x05); // Get entry description request
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1025
        EC_WRITE_U8 (data + 3, 0x00);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1026
        EC_WRITE_U16(data + 4, 0x0000);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1027
        EC_WRITE_U16(data + 6, sdo->index); // SDO index
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1028
        EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1029
        EC_WRITE_U8 (data + 9, 0x00); // value info (no values)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1030
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1031
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1032
        fsm->state = ec_fsm_coe_dict_entry_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1033
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1034
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1035
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1036
    // another SDO description to fetch?
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1037
    if (fsm->sdo->list.next != &slave->sdo_dictionary) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1038
        fsm->sdo = list_entry(fsm->sdo->list.next, ec_sdo_t, list);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1039
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1040
        data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1041
        if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1042
            fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1043
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1044
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1045
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1046
        EC_WRITE_U16(data, 0x8 << 12); // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1047
        EC_WRITE_U8 (data + 2, 0x03); // Get object description request
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1048
        EC_WRITE_U8 (data + 3, 0x00);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1049
        EC_WRITE_U16(data + 4, 0x0000);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1050
        EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1051
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1052
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1053
        fsm->state = ec_fsm_coe_dict_desc_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1054
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1055
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1056
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1057
    fsm->state = ec_fsm_coe_end;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1058
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1059
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1060
/******************************************************************************
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1061
 *  CoE state machine
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1062
 *****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1063
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1064
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1065
   CoE state: DOWN START.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1066
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1067
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1068
void ec_fsm_coe_down_start(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1069
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1070
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1071
    ec_slave_t *slave = fsm->slave;
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1072
    ec_sdo_request_t *request = fsm->request;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1073
    uint8_t *data;
1169
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1074
    uint8_t size;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1075
874
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1076
    if (fsm->slave->master->debug_level) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1077
        EC_DBG("Downloading SDO 0x%04X:%02X to slave %u.\n",
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1078
               request->index, request->subindex, slave->ring_position);
874
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1079
        ec_print_data(request->data, request->data_size);
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1080
    }
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1081
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
  1082
    if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
825
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1083
        EC_ERR("Slave %u does not support CoE!\n", slave->ring_position);
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1084
        fsm->state = ec_fsm_coe_error;
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1085
        return;
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1086
    }
1169
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1087
	
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1088
	if (request->data_size <= 4) { // use expedited transfer type
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1089
	    data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1090
        if (IS_ERR(data)) {
1169
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1091
	        fsm->state = ec_fsm_coe_error;
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1092
	        return;
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1093
	    }
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1094
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1095
	    size = 4 - request->data_size;
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1096
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1097
	    EC_WRITE_U16(data, 0x2 << 12); // SDO request
1169
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1098
	    EC_WRITE_U8 (data + 2, (0x3 // size specified, expedited
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1099
								| size << 2
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1100
	                            | 0x1 << 5)); // Download request
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1101
	    EC_WRITE_U16(data + 3, request->index);
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1102
	    EC_WRITE_U8 (data + 5, request->subindex);
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1103
	    memcpy(data + 6, request->data, request->data_size);
1457
ec3ad6641d65 Slightly improved CoE download expedited request.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1104
        memset(data + 6 + request->data_size, 0x00, 4 - request->data_size);
1169
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1105
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1106
        if (slave->master->debug_level) {
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1107
            EC_DBG("Expedited download request:\n");
1457
ec3ad6641d65 Slightly improved CoE download expedited request.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1108
            ec_print_data(data, 10);
1169
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1109
        }
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1110
	}
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1111
    else { // request->data_size > 4, use normal transfer type
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
  1112
	    if (slave->configured_rx_mailbox_size < 6 + 10 + request->data_size) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1113
	        EC_ERR("SDO fragmenting not supported yet!\n");
1169
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1114
	        fsm->state = ec_fsm_coe_error;
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1115
	        return;
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1116
	    }
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1117
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1118
	    data = ec_slave_mbox_prepare_send(slave, datagram, 0x03,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1119
                request->data_size + 10);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1120
        if (IS_ERR(data)) {
1169
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1121
	        fsm->state = ec_fsm_coe_error;
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1122
	        return;
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1123
	    }
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1124
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1125
	    EC_WRITE_U16(data, 0x2 << 12); // SDO request
1169
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1126
	    EC_WRITE_U8 (data + 2, (0x1 // size indicator, normal
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1127
	                            | 0x1 << 5)); // Download request
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1128
	    EC_WRITE_U16(data + 3, request->index);
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1129
	    EC_WRITE_U8 (data + 5, request->subindex);
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1130
	    EC_WRITE_U32(data + 6, request->data_size);
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1131
	    memcpy(data + 10, request->data, request->data_size);
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1132
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1133
        if (slave->master->debug_level) {
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1134
            EC_DBG("Normal download request:\n");
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1135
            ec_print_data(data, 10 + request->data_size);
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1136
        }
cf0b5293eea6 Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents: 1112
diff changeset
  1137
	}
975
dae04112bcc7 Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
  1138
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1139
    fsm->request->jiffies_sent = jiffies;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1140
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1141
    fsm->state = ec_fsm_coe_down_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1142
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1143
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1144
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1145
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1146
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1147
   CoE state: DOWN REQUEST.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1148
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1149
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1150
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1151
void ec_fsm_coe_down_request(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1152
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1153
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1154
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1155
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1156
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1157
        return; // FIXME: check for response first?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1158
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1159
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1160
        fsm->state = ec_fsm_coe_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1161
        EC_ERR("Failed to receive CoE download request datagram for"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
  1162
               " slave %u (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
  1163
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1164
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1165
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1166
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1167
    if (datagram->working_counter != 1) {
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1168
        if (!datagram->working_counter) {
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1169
            unsigned long diff_ms =
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1170
                (jiffies - fsm->request->jiffies_sent) * 1000 / HZ;
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1171
            if (diff_ms < fsm->request->response_timeout) {
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1172
                if (fsm->slave->master->debug_level) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1173
                    EC_DBG("Slave %u did not respond to SDO download request. "
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1174
                            "Retrying after %u ms...\n",
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1175
                            slave->ring_position, (u32) diff_ms);
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1176
                }
1112
d11661e1f4de Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents: 1111
diff changeset
  1177
                // no response; send request datagram again
d11661e1f4de Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents: 1111
diff changeset
  1178
                return;
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1179
            }
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1180
        }
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1181
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1182
        EC_ERR("Reception of CoE download request failed on slave %u: ",
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1183
                slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1184
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1185
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1186
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1187
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  1188
    fsm->jiffies_start = datagram->jiffies_sent;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1189
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1190
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1191
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1192
    fsm->state = ec_fsm_coe_down_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1193
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1194
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1195
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1196
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1197
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1198
   CoE state: DOWN CHECK.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1199
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1200
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1201
void ec_fsm_coe_down_check(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1202
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1203
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1204
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1205
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1206
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1207
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1208
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1209
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1210
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1211
        EC_ERR("Failed to receive CoE mailbox check datagram for slave %u"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
  1212
                " (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
  1213
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1214
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1215
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1216
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1217
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1218
        fsm->state = ec_fsm_coe_error;
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1219
        EC_ERR("Reception of CoE mailbox check"
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1220
                " datagram failed on slave %u: ", slave->ring_position);
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1221
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1222
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1223
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1224
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1225
    if (!ec_slave_mbox_check(datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  1226
        unsigned long diff_ms =
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  1227
            (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1228
        if (diff_ms >= fsm->request->response_timeout) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1229
            fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1230
            EC_ERR("Timeout while waiting for SDO download response on "
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1231
                    "slave %u.\n", slave->ring_position);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1232
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1233
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1234
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1235
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1236
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1237
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1238
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1239
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1240
    // Fetch response
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1241
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1242
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1243
    fsm->state = ec_fsm_coe_down_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1244
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1245
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1246
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1247
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1248
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1249
   CoE state: DOWN RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1250
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1251
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1252
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1253
void ec_fsm_coe_down_response(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1254
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1255
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1256
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1257
    uint8_t *data, mbox_prot;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1258
    size_t rec_size;
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1259
    ec_sdo_request_t *request = fsm->request;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1260
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1261
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1262
        return; // FIXME: request again?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1263
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1264
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1265
        fsm->state = ec_fsm_coe_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1266
        EC_ERR("Failed to receive CoE download response datagram from"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
  1267
               " slave %u (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
  1268
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1269
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1270
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1271
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1272
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1273
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1274
        EC_ERR("Reception of CoE download response failed on slave %u: ",
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1275
                slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1276
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1277
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1278
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1279
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1280
    data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1281
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1282
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1283
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1284
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1285
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1286
    if (mbox_prot != 0x03) { // CoE
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  1287
        fsm->state = ec_fsm_coe_error;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 436
diff changeset
  1288
        EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  1289
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1290
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1291
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1292
    if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) {
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1293
        // check for CoE response again
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1294
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1295
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1296
        fsm->state = ec_fsm_coe_down_check;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1297
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1298
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1299
975
dae04112bcc7 Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
  1300
    if (slave->master->debug_level) {
dae04112bcc7 Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
  1301
        EC_DBG("Download response:\n");
dae04112bcc7 Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
  1302
        ec_print_data(data, rec_size);
dae04112bcc7 Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
  1303
    }
dae04112bcc7 Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
  1304
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1305
    if (rec_size < 6) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1306
        fsm->state = ec_fsm_coe_error;
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1307
        EC_ERR("Received data are too small (%u bytes):\n", rec_size);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1308
        ec_print_data(data, rec_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1309
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1310
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1311
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1312
    if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1313
        EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1314
        fsm->state = ec_fsm_coe_error;
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1315
        EC_ERR("SDO download 0x%04X:%02X (%u bytes) aborted on slave %u.\n",
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1316
               request->index, request->subindex, request->data_size,
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1317
               slave->ring_position);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1318
        if (rec_size < 10) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1319
            EC_ERR("Incomplete Abort command:\n");
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1320
            ec_print_data(data, rec_size);
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1321
        } else {
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1322
            fsm->request->abort_code = EC_READ_U32(data + 6);
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1323
            ec_canopen_abort_msg(fsm->request->abort_code);
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1324
        }
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1325
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1326
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1327
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1328
    if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1329
        EC_READ_U8 (data + 2) >> 5 != 0x3 || // Download response
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1330
        EC_READ_U16(data + 3) != request->index || // index
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1331
        EC_READ_U8 (data + 5) != request->subindex) { // subindex
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1332
        if (slave->master->debug_level) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1333
            EC_DBG("Invalid SDO download response at slave %u! Retrying...\n",
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1334
                    slave->ring_position);
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1335
            ec_print_data(data, rec_size);
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1336
        }
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1337
        // check for CoE response again
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1338
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1339
        fsm->retries = EC_FSM_RETRIES;
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1340
        fsm->state = ec_fsm_coe_down_check;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1341
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1342
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1343
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1344
    fsm->state = ec_fsm_coe_end; // success
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1345
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1346
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1347
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1348
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1349
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1350
   CoE state: UP START.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1351
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1352
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1353
void ec_fsm_coe_up_start(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1354
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1355
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1356
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1357
    ec_master_t *master = slave->master;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1358
    ec_sdo_request_t *request = fsm->request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1359
    uint8_t *data;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1360
459
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
  1361
    if (master->debug_level)
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1362
        EC_DBG("Uploading SDO 0x%04X:%02X from slave %u.\n",
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 825
diff changeset
  1363
               request->index, request->subindex, slave->ring_position);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1364
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
  1365
    if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
825
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1366
        EC_ERR("Slave %u does not support CoE!\n", slave->ring_position);
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1367
        fsm->state = ec_fsm_coe_error;
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1368
        return;
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1369
    }
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1370
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1371
    data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1372
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1373
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1374
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1375
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1376
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1377
    EC_WRITE_U16(data, 0x2 << 12); // SDO request
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1378
    EC_WRITE_U8 (data + 2, 0x2 << 5); // initiate upload request
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 825
diff changeset
  1379
    EC_WRITE_U16(data + 3, request->index);
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 825
diff changeset
  1380
    EC_WRITE_U8 (data + 5, request->subindex);
476
fd7c0ee645f8 Fixed CoE Upload Request, now 10 bytes of Mailbox Service Data.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1381
    memset(data + 6, 0x00, 4);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1382
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1383
    if (master->debug_level) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1384
        EC_DBG("Upload request:\n");
476
fd7c0ee645f8 Fixed CoE Upload Request, now 10 bytes of Mailbox Service Data.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1385
        ec_print_data(data, 10);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1386
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1387
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1388
    fsm->request->jiffies_sent = jiffies;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1389
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1390
    fsm->state = ec_fsm_coe_up_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1391
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1392
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1393
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1394
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1395
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1396
   CoE state: UP REQUEST.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1397
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1398
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1399
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1400
void ec_fsm_coe_up_request(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1401
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1402
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1403
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1404
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1405
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1406
        return; // FIXME: check for response first?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1407
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1408
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1409
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1410
        EC_ERR("Failed to receive CoE upload request for slave %u"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
  1411
                " (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
  1412
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1413
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1414
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1415
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1416
    if (datagram->working_counter != 1) {
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1417
        if (!datagram->working_counter) {
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1418
            unsigned long diff_ms =
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1419
                (jiffies - fsm->request->jiffies_sent) * 1000 / HZ;
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1420
            if (diff_ms < fsm->request->response_timeout) {
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1421
                if (fsm->slave->master->debug_level) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1422
                    EC_DBG("Slave %u did not respond to SDO upload request. "
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1423
                            "Retrying after %u ms...\n",
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1424
                            slave->ring_position, (u32) diff_ms);
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1425
                }
1112
d11661e1f4de Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents: 1111
diff changeset
  1426
                // no response; send request datagram again
d11661e1f4de Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents: 1111
diff changeset
  1427
                return;
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1428
            }
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1429
        }
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1430
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1431
        EC_ERR("Reception of CoE upload request failed on slave %u: ",
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1432
                slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1433
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1434
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1435
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1436
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  1437
    fsm->jiffies_start = datagram->jiffies_sent;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1438
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1439
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1440
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1441
    fsm->state = ec_fsm_coe_up_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1442
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1443
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1444
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1445
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1446
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1447
   CoE state: UP CHECK.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1448
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1449
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1450
void ec_fsm_coe_up_check(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1451
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1452
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1453
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1454
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1455
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1456
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1457
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1458
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1459
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1460
        EC_ERR("Failed to receive CoE mailbox check datagram from slave %u"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
  1461
                " (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
  1462
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1463
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1464
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1465
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1466
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1467
        fsm->state = ec_fsm_coe_error;
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1468
        EC_ERR("Reception of CoE mailbox check"
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1469
                " datagram failed on slave %u: ", slave->ring_position);
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1470
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1471
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1472
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1473
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1474
    if (!ec_slave_mbox_check(datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  1475
        unsigned long diff_ms =
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  1476
            (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
1043
2abea4233a6d Response timeout for checking Sdo upload.
Florian Pose <fp@igh-essen.com>
parents: 1038
diff changeset
  1477
        if (diff_ms >= fsm->request->response_timeout) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1478
            fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1479
            EC_ERR("Timeout while waiting for SDO upload response on "
1111
6aaf6a0c375c Improved timeout error messages.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
  1480
                    "slave %u.\n", slave->ring_position);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1481
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1482
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1483
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1484
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1485
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1486
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1487
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1488
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1489
    // Fetch response
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1490
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1491
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1492
    fsm->state = ec_fsm_coe_up_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1493
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1494
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1495
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1496
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1497
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1498
   CoE state: UP RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1499
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1500
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1501
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1502
void ec_fsm_coe_up_response(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1503
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1504
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1505
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1506
    ec_master_t *master = slave->master;
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1507
    uint16_t rec_index;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1508
    uint8_t *data, mbox_prot, rec_subindex;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1509
    size_t rec_size, data_size;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1510
    ec_sdo_request_t *request = fsm->request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1511
    unsigned int expedited, size_specified;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1512
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1513
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1514
        return; // FIXME: request again?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1515
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1516
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1517
        fsm->state = ec_fsm_coe_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1518
        EC_ERR("Failed to receive CoE upload response datagram for"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
  1519
               " slave %u (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
  1520
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1521
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1522
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1523
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1524
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1525
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1526
        EC_ERR("Reception of CoE upload response failed on slave %u: ",
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1527
                slave->ring_position);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1528
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1529
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1530
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1531
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1532
    data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1533
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1534
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1535
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1536
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1537
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1538
    if (master->debug_level) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1539
        EC_DBG("Upload response:\n");
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1540
        ec_print_data(data, rec_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1541
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1542
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1543
    if (mbox_prot != 0x03) { // CoE
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  1544
        fsm->state = ec_fsm_coe_error;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1545
        EC_WARN("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1546
        return;
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1547
    }
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1548
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1549
    if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) {
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1550
        // check for CoE response again
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1551
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1552
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1553
        fsm->state = ec_fsm_coe_up_check;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1554
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1555
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1556
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1557
    if (rec_size < 6) {
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  1558
        fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1559
        EC_ERR("Received currupted SDO upload response (%u bytes)!\n", rec_size);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1560
        ec_print_data(data, rec_size);
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1561
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1562
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1563
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1564
    if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1565
            EC_READ_U8(data + 2) >> 5 == 0x4) { // abort SDO transfer request
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1566
        EC_ERR("SDO upload 0x%04X:%02X aborted on slave %u.\n",
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 825
diff changeset
  1567
               request->index, request->subindex, slave->ring_position);
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1568
        if (rec_size >= 10) {
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1569
            request->abort_code = EC_READ_U32(data + 6);
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1570
            ec_canopen_abort_msg(request->abort_code);
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1571
        } else {
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1572
            EC_ERR("No abort message.\n");
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1573
        }
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1574
        fsm->state = ec_fsm_coe_error;
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1575
        return;
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1576
    }
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1577
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1578
    if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1579
            EC_READ_U8(data + 2) >> 5 != 0x2) { // upload response
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1580
        EC_ERR("Received unknown response while uploading SDO 0x%04X:%02X"
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1581
                " from slave %u.\n", request->index, request->subindex,
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1582
                slave->ring_position);
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1583
        ec_print_data(data, rec_size);
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1584
        fsm->state = ec_fsm_coe_error;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1585
        return;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1586
    }
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1587
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1588
    rec_index = EC_READ_U16(data + 3);
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1589
    rec_subindex = EC_READ_U8(data + 5);
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1590
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1591
    if (rec_index != request->index || rec_subindex != request->subindex) {
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1592
        EC_ERR("Received upload response for wrong SDO (0x%04X:%02X,"
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1593
                " requested: 0x%04X:%02X) from slave %u.\n",
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1594
                rec_index, rec_subindex, request->index, request->subindex,
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1595
                slave->ring_position);
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1596
        ec_print_data(data, rec_size);
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1597
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1598
        // check for CoE response again
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1599
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1600
        fsm->retries = EC_FSM_RETRIES;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1601
        fsm->state = ec_fsm_coe_up_check;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1602
        return;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1603
    }
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1604
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1605
    // normal or expedited?
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1606
    expedited = EC_READ_U8(data + 2) & 0x02;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1607
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1608
    if (expedited) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1609
        size_specified = EC_READ_U8(data + 2) & 0x01;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1610
        if (size_specified) {
1339
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1611
            fsm->complete_size = 4 - ((EC_READ_U8(data + 2) & 0x0C) >> 2);
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1612
        } else {
1339
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1613
            fsm->complete_size = 4;
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1614
        }
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1615
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1616
        if (rec_size < 6 + fsm->complete_size) {
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  1617
            fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1618
            EC_ERR("Received currupted SDO expedited upload"
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1619
                    " response (only %u bytes)!\n", rec_size);
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1620
            ec_print_data(data, rec_size);
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1621
            return;
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1622
        }
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1623
1339
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1624
        if (ec_sdo_request_copy_data(request, data + 6, fsm->complete_size)) {
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1625
            fsm->state = ec_fsm_coe_error;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1626
            return;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1627
        }
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1628
    } else { // normal
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1629
        if (rec_size < 10) {
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  1630
            fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1631
            EC_ERR("Received currupted SDO normal upload"
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1632
                    " response (only %u bytes)!\n", rec_size);
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1633
            ec_print_data(data, rec_size);
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1634
            return;
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1635
        }
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1636
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1637
        data_size = rec_size - 10;
1339
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1638
        fsm->complete_size = EC_READ_U32(data + 6);
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1639
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1640
        if (!fsm->complete_size) {
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  1641
            fsm->state = ec_fsm_coe_error;
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1642
            EC_ERR("No complete size supplied!\n");
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1643
            ec_print_data(data, rec_size);
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1644
            return;
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1645
        }
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  1646
1339
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1647
        if (ec_sdo_request_alloc(request, fsm->complete_size)) {
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1648
            fsm->state = ec_fsm_coe_error;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1649
            return;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1650
        }
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1651
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1652
        if (ec_sdo_request_copy_data(request, data + 10, data_size)) {
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1653
            fsm->state = ec_fsm_coe_error;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1654
            return;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1655
        }
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1656
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1657
        fsm->toggle = 0;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1658
1339
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1659
        if (data_size < fsm->complete_size) {
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1660
            if (master->debug_level)
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1661
                EC_DBG("SDO data incomplete (%u / %u). Segmenting...\n",
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1662
                        data_size, fsm->complete_size);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 436
diff changeset
  1663
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1664
            data = ec_slave_mbox_prepare_send(slave, datagram,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1665
                    0x03, 3);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1666
            if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1667
                fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1668
                return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1669
            }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1670
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1671
            EC_WRITE_U16(data, 0x2 << 12); // SDO request
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1672
            EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1673
                                    | 0x3 << 5)); // upload segment request
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1674
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1675
            if (master->debug_level) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1676
                EC_DBG("Upload segment request:\n");
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1677
                ec_print_data(data, 3);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1678
            }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1679
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1680
            fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1681
            fsm->state = ec_fsm_coe_up_seg_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1682
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1683
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1684
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1685
874
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1686
    if (master->debug_level) {
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1687
        EC_DBG("Uploaded data:\n");
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1688
        ec_print_data(request->data, request->data_size);
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1689
    }
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1690
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1691
    fsm->state = ec_fsm_coe_end; // success
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1692
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1693
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1694
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1695
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1696
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1697
   CoE state: UP REQUEST.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1698
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1699
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1700
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1701
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1702
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1703
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1704
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1705
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1706
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1707
        return; // FIXME: check for response first?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1708
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1709
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1710
        fsm->state = ec_fsm_coe_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1711
        EC_ERR("Failed to receive CoE upload segment request datagram for"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
  1712
               " slave %u (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
  1713
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1714
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1715
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1716
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1717
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1718
        fsm->state = ec_fsm_coe_error;
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1719
        EC_ERR("Reception of CoE upload segment"
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1720
                " request failed on slave %u: ", slave->ring_position);
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1721
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1722
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1723
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1724
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  1725
    fsm->jiffies_start = datagram->jiffies_sent;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1726
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1727
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1728
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1729
    fsm->state = ec_fsm_coe_up_seg_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1730
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1731
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1732
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1733
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1734
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1735
   CoE state: UP CHECK.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1736
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1737
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1738
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1739
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1740
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1741
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1742
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1743
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1744
        return;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1745
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1746
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1747
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1748
        EC_ERR("Failed to receive CoE mailbox check datagram for slave %u"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
  1749
                " (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
  1750
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1751
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1752
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1753
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1754
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1755
        fsm->state = ec_fsm_coe_error;
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1756
        EC_ERR("Reception of CoE mailbox check"
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1757
                " datagram failed on slave %u: ", slave->ring_position);
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1758
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1759
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1760
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1761
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1762
    if (!ec_slave_mbox_check(datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  1763
        unsigned long diff_ms =
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  1764
            (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1765
        if (diff_ms >= fsm->request->response_timeout) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1766
            fsm->state = ec_fsm_coe_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1767
            EC_ERR("Timeout while waiting for SDO upload segment response "
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1768
                    "on slave %u.\n", slave->ring_position);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1769
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1770
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1771
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1772
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1773
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1774
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1775
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1776
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1777
    // Fetch response
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1778
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1779
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1780
    fsm->state = ec_fsm_coe_up_seg_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1781
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1782
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1783
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1784
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1785
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1786
   CoE state: UP RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1787
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1788
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1789
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1790
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1791
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1792
    ec_datagram_t *datagram = fsm->datagram;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1793
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1794
    ec_master_t *master = slave->master;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1795
    uint8_t *data, mbox_prot;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1796
    size_t rec_size, data_size;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1797
    ec_sdo_request_t *request = fsm->request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1798
    uint32_t seg_size;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1799
    unsigned int last_segment;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1800
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1801
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1802
        return; // FIXME: request again?
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1803
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1804
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1805
        fsm->state = ec_fsm_coe_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1806
        EC_ERR("Failed to receive CoE upload segment response datagram for"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 975
diff changeset
  1807
               " slave %u (datagram state %u).\n",
594
07dd2a7df66e Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents: 505
diff changeset
  1808
               slave->ring_position, datagram->state);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1809
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1810
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1811
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1812
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1813
        fsm->state = ec_fsm_coe_error;
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1814
        EC_ERR("Reception of CoE upload segment"
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1815
                " response failed on slave %u: ", slave->ring_position);
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1816
        ec_datagram_print_wc_error(datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1817
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1818
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1819
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1820
    data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1821
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1822
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1823
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1824
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1825
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1826
    if (master->debug_level) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1827
        EC_DBG("Upload segment response:\n");
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1828
        ec_print_data(data, rec_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1829
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1830
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1831
    if (mbox_prot != 0x03) { // CoE
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 436
diff changeset
  1832
        EC_ERR("Received mailbox protocol 0x%02X as response.\n", mbox_prot);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1833
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1834
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1835
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1836
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1837
    if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) {
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1838
        // check for CoE response again
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1839
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1840
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1841
        fsm->state = ec_fsm_coe_up_seg_check;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1842
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1843
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1844
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1845
    if (rec_size < 10) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1846
        EC_ERR("Received currupted SDO upload segment response!\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1847
        ec_print_data(data, rec_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1848
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1849
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1850
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1851
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1852
    if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  1853
            EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1854
        EC_ERR("SDO upload 0x%04X:%02X aborted on slave %u.\n",
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 825
diff changeset
  1855
               request->index, request->subindex, slave->ring_position);
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1856
        request->abort_code = EC_READ_U32(data + 6);
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1857
        ec_canopen_abort_msg(request->abort_code);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1858
        fsm->state = ec_fsm_coe_error;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1859
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1860
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1861
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1862
    if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1863
        EC_READ_U8 (data + 2) >> 5 != 0x0) { // upload segment response
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1864
        if (fsm->slave->master->debug_level) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1865
            EC_DBG("Invalid SDO upload segment response at slave %u!\n",
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1866
               slave->ring_position);
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1867
            ec_print_data(data, rec_size);
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1868
        }
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1869
        // check for CoE response again
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1870
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1871
        fsm->retries = EC_FSM_RETRIES;
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1872
        fsm->state = ec_fsm_coe_up_seg_check;
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1873
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1874
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1875
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1876
    last_segment = EC_READ_U8(data + 2) & 0x01;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1877
    seg_size = (EC_READ_U8(data + 2) & 0xE) >> 1;
1339
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1878
    if (rec_size > 10) {
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1879
        data_size = rec_size - 10;
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1880
    } else { // == 10
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1881
        /* seg_size contains the number of trailing bytes to ignore. */
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1882
        data_size = rec_size - seg_size;
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1883
    }
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1884
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1885
    if (request->data_size + data_size > fsm->complete_size) {
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1886
        EC_ERR("SDO upload 0x%04X:%02X failed on slave %u: Fragment"
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1887
                " exceeding complete size!\n",
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1888
               request->index, request->subindex, slave->ring_position);
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1889
        fsm->state = ec_fsm_coe_error;
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1890
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1891
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1892
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1893
    memcpy(request->data + request->data_size, data + 10, data_size);
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  1894
    request->data_size += data_size;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1895
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1896
    if (!last_segment) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1897
        fsm->toggle = !fsm->toggle;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1898
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1899
        data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 3);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1900
        if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1901
            fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1902
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1903
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1904
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1905
        EC_WRITE_U16(data, 0x2 << 12); // SDO request
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1906
        EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1907
                                | 0x3 << 5)); // upload segment request
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1908
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1909
        if (master->debug_level) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1910
            EC_DBG("Upload segment request:\n");
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1911
            ec_print_data(data, 3);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1912
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1913
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1914
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1915
        fsm->state = ec_fsm_coe_up_seg_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1916
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1917
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1918
1339
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1919
    if (request->data_size != fsm->complete_size) {
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1920
        EC_WARN("SDO upload 0x%04X:%02X on slave %u: Assembled data"
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1921
                " size (%u) does not match complete size (%u)!\n",
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1922
                request->index, request->subindex, slave->ring_position,
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1923
                request->data_size, fsm->complete_size);
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1924
    }
3483999e1aba merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
  1925
874
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1926
    if (master->debug_level) {
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1927
        EC_DBG("Uploaded data:\n");
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1928
        ec_print_data(request->data, request->data_size);
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1929
    }
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1930
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1931
    fsm->state = ec_fsm_coe_end; // success
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1932
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1933
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1934
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1935
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1936
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1937
   State: ERROR.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1938
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1939
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1940
void ec_fsm_coe_error(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1941
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1942
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1943
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1944
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1945
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1946
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1947
   State: END.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1948
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1949
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1950
void ec_fsm_coe_end(ec_fsm_coe_t *fsm /**< finite state machine */)
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1951
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1952
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1953
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1954
/*****************************************************************************/