master/fsm_coe.c
author "Dave Page <dave.page@gleeble.com>"
Mon, 16 Mar 2015 14:18:55 -0400
changeset 2608 ec0b5d9a2ff1
parent 2591 23b360e4a530
permissions -rw-r--r--
Reduce frequency of DC Sync debug messages
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    30
/** \file
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    31
 * EtherCAT CoE state machines.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    32
 */
436
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
#include "globals.h"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "master.h"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "mailbox.h"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "fsm_coe.h"
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    40
#include "slave_config.h"
436
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
 */
1794
94e0e1756dec Reduced CoE timeouts to 1000 ms.
Florian Pose <fp@igh-essen.com>
parents: 1793
diff changeset
    46
#define EC_FSM_COE_DICT_TIMEOUT 1000
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
    47
1907
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    48
/** CoE download request header size.
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    49
 */
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    50
#define EC_COE_DOWN_REQ_HEADER_SIZE 10
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    51
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    52
/** CoE download segment request header size.
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    53
 */
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    54
#define EC_COE_DOWN_SEG_REQ_HEADER_SIZE 3
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    55
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    56
/** Minimum size of download segment.
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    57
 */
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    58
#define EC_COE_DOWN_SEG_MIN_DATA_SIZE 7
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    59
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    60
/** Enable debug output for CoE retries.
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    61
 */
1791
27030c6b2de3 Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents: 1563
diff changeset
    62
#define DEBUG_RETRIES 0
1907
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    63
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    64
/** Enable warning output if transfers take too long.
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    65
 */
1792
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
    66
#define DEBUG_LONG 0
1791
27030c6b2de3 Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents: 1563
diff changeset
    67
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
    68
/*****************************************************************************/
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
    69
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    70
void ec_fsm_coe_dict_start(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    71
void ec_fsm_coe_dict_request(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    72
void ec_fsm_coe_dict_check(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    73
void ec_fsm_coe_dict_response(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    74
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    75
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    76
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    77
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    78
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    79
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    80
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    81
void ec_fsm_coe_down_start(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    82
void ec_fsm_coe_down_request(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    83
void ec_fsm_coe_down_check(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    84
void ec_fsm_coe_down_response(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    85
void ec_fsm_coe_down_seg_check(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    86
void ec_fsm_coe_down_seg_response(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    87
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    88
void ec_fsm_coe_up_start(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    89
void ec_fsm_coe_up_request(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    90
void ec_fsm_coe_up_check(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    91
void ec_fsm_coe_up_response(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    92
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    93
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    94
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    95
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    96
void ec_fsm_coe_end(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    97
void ec_fsm_coe_error(ec_fsm_coe_t *, ec_datagram_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    98
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
    99
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   100
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   101
/** SDO abort messages.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   102
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   103
 * The "abort SDO transfer request" supplies an abort code, which can be
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   104
 * translated to clear text. This table does the mapping of the codes and
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   105
 * messages.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   106
 */
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
const ec_code_msg_t sdo_abort_messages[] = {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    {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
   109
    {0x05040000, "SDO protocol timeout"},
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    {0x05040001, "Client/Server command specifier not valid or unknown"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    {0x05040005, "Out of memory"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    {0x06010000, "Unsupported access to an object"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    {0x06010001, "Attempt to read a write-only object"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
    {0x06010002, "Attempt to write a read-only object"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    {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
   116
    {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
   117
    {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
   118
     " exceed the PDO length"},
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
    {0x06040043, "General parameter incompatibility reason"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
    {0x06040047, "Gerneral internal incompatibility in device"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
    {0x06060000, "Access failure due to a hardware error"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
    {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
   123
     " not match"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    {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
   125
     " high"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    {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
   127
     " low"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
    {0x06090011, "Subindex does not exist"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
    {0x06090030, "Value range of parameter exceeded"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
    {0x06090031, "Value of parameter written too high"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
    {0x06090032, "Value of parameter written too low"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
    {0x06090036, "Maximum value is less than minimum value"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    {0x08000000, "General error"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
    {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
   135
    {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
   136
     " because of local control"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    {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
   138
     " because of the present device state"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    {0x08000023, "Object dictionary dynamic generation fails or no object"
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
     " dictionary is present"},
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    {}
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
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   146
/** Outputs an SDO abort message.
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   147
 */
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   148
void ec_canopen_abort_msg(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   149
        const ec_slave_t *slave, /**< Slave. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   150
        uint32_t abort_code /**< Abort code to search for. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   151
        )
436
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
    const ec_code_msg_t *abort_msg;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    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
   156
        if (abort_msg->code == abort_code) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   157
            EC_SLAVE_ERR(slave, "SDO abort message 0x%08X: \"%s\".\n",
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
                   abort_msg->code, abort_msg->message);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
            return;
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
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   163
    EC_SLAVE_ERR(slave, "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
   164
}
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   168
/** Constructor.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   169
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   170
void ec_fsm_coe_init(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   171
        ec_fsm_coe_t *fsm /**< Finite state machine */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   172
        )
436
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
    fsm->state = NULL;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   175
    fsm->datagram = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   176
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   177
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   178
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   179
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   180
/** Destructor.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   181
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   182
void ec_fsm_coe_clear(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   183
        ec_fsm_coe_t *fsm /**< Finite state machine */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   184
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   185
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   186
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   187
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   188
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   189
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   190
/** Starts reading a slaves' SDO dictionary.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   191
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   192
void ec_fsm_coe_dictionary(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   193
        ec_fsm_coe_t *fsm, /**< Finite state machine */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   194
        ec_slave_t *slave /**< EtherCAT slave */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   195
        )
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
    fsm->slave = slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    fsm->state = ec_fsm_coe_dict_start;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
}
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   203
/** Starts to transfer an SDO to/from a slave.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   204
 */
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   205
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
   206
        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
   207
        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
   208
        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
   209
        )
436
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->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
   212
    fsm->request = request;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   213
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   214
    if (request->dir == EC_DIR_OUTPUT) {
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   215
        fsm->state = ec_fsm_coe_down_start;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   216
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   217
    else {
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   218
        fsm->state = ec_fsm_coe_up_start;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   219
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   220
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   221
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   222
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   223
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   224
/** Executes the current state of the state machine.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   225
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   226
 * \return 1 if the datagram was used, else 0.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   227
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   228
int ec_fsm_coe_exec(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   229
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   230
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   231
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   232
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   233
    int datagram_used = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   234
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   235
    if (fsm->datagram &&
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   236
            (fsm->datagram->state == EC_DATAGRAM_INIT ||
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   237
             fsm->datagram->state == EC_DATAGRAM_QUEUED ||
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   238
             fsm->datagram->state == EC_DATAGRAM_SENT)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   239
        // datagram not received yet
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   240
        return datagram_used;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   241
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   242
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   243
    fsm->state(fsm, datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   244
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   245
    datagram_used =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   246
        fsm->state != ec_fsm_coe_end && fsm->state != ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   247
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   248
    if (datagram_used) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   249
        fsm->datagram = datagram;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   250
    } else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   251
        fsm->datagram = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   252
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   253
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   254
    return datagram_used;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   255
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   256
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   257
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   258
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   259
/** Returns, if the state machine terminated with success.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   260
 * \return non-zero if successful.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   261
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   262
int ec_fsm_coe_success(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   263
        const ec_fsm_coe_t *fsm /**< Finite state machine */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   264
        )
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
    return fsm->state == ec_fsm_coe_end;
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
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   269
/*****************************************************************************/
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   270
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   271
/** 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
   272
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   273
 * 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
   274
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   275
 * \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
   276
 */
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   277
int ec_fsm_coe_check_emergency(
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   278
        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
   279
        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
   280
        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
   281
        )
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   282
{
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   283
    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
   284
        return 0;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   285
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   286
    if (size < 10) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   287
        EC_SLAVE_WARN(fsm->slave, "Received incomplete CoE Emergency"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   288
                " request:\n");
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   289
        ec_print_data(data, size);
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   290
        return 1;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   291
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   292
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   293
    {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   294
        ec_slave_config_t *sc = fsm->slave->config;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   295
        if (sc) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   296
            ec_coe_emerg_ring_push(&sc->emerg_ring, data + 2);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   297
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   298
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   299
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   300
    EC_SLAVE_WARN(fsm->slave, "CoE Emergency Request received:\n"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   301
            "Error code 0x%04X, Error register 0x%02X, data:\n",
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   302
            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
   303
    ec_print_data(data + 5, 5);
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   304
    return 1;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   305
}
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   306
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
/******************************************************************************
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
 *  CoE dictionary state machine
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   311
/** Prepare a dictionary request.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   312
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   313
 * \return Zero on success, otherwise a negative error code.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   314
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   315
int ec_fsm_coe_prepare_dict(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   316
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   317
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   318
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   319
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   320
    ec_slave_t *slave = fsm->slave;
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   321
    uint8_t *data = ec_slave_mbox_prepare_send(slave, datagram,
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   322
			EC_MBOX_TYPE_COE, 8);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   323
    if (IS_ERR(data)) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   324
        return PTR_ERR(data);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   327
    EC_WRITE_U16(data, 0x8 << 12); // SDO information
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
    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
   329
    EC_WRITE_U8 (data + 3, 0x00);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
    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
   331
    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
   332
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   333
    fsm->state = ec_fsm_coe_dict_request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   334
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   335
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   336
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   337
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   338
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   339
/** CoE state: DICT START.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   340
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   341
void ec_fsm_coe_dict_start(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   342
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   343
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   344
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   345
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   346
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   347
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   348
    if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   349
        EC_SLAVE_ERR(slave, "Slave does not support CoE!\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   350
        fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   351
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   352
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   353
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   354
    if (slave->sii.has_general && !slave->sii.coe_details.enable_sdo_info) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   355
        EC_SLAVE_ERR(slave, "Slave does not support"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   356
                " SDO information service!\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   357
        fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   358
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   359
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   360
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   361
    fsm->retries = EC_FSM_RETRIES;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   362
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   363
    if (ec_fsm_coe_prepare_dict(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   364
        fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   365
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   366
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   367
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   368
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   369
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   370
/** CoE state: DICT REQUEST.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   371
 * \todo Timeout behavior
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   372
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   373
void ec_fsm_coe_dict_request(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   374
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   375
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   376
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   377
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   378
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   379
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   380
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   381
        if (ec_fsm_coe_prepare_dict(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   382
            fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   383
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   384
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   385
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   386
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   387
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   388
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   389
        EC_SLAVE_ERR(slave, "Failed to receive CoE dictionary"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   390
                " request datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   391
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   392
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   393
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   394
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   395
    if (fsm->datagram->working_counter != 1) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   396
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   397
        EC_SLAVE_ERR(slave, "Reception of CoE dictionary request failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   398
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   399
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   400
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   401
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   402
    fsm->jiffies_start = fsm->datagram->jiffies_sent;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   403
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   404
    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
   405
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   406
    fsm->state = ec_fsm_coe_dict_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   407
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   408
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   409
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   410
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   411
/** CoE state: DICT CHECK.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   412
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   413
void ec_fsm_coe_dict_check(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   414
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   415
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   416
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   417
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   418
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   419
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   420
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   421
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   422
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   423
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   424
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   425
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   426
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   427
        EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   428
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   429
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   430
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   431
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   432
    if (fsm->datagram->working_counter != 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   433
        fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   434
        EC_SLAVE_ERR(slave,"Reception of CoE mailbox check"
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   435
                " datagram failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   436
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   437
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   438
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   439
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   440
    if (!ec_slave_mbox_check(fsm->datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   441
        unsigned long diff_ms =
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   442
            (fsm->datagram->jiffies_received - fsm->jiffies_start) *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   443
            1000 / HZ;
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   444
        if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   445
            fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   446
            EC_SLAVE_ERR(slave, "Timeout while waiting for"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   447
                    " SDO dictionary list response.\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   448
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   449
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   450
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   451
        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
   452
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   453
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
    // Fetch response
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   457
    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
   458
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   459
    fsm->state = ec_fsm_coe_dict_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   460
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   461
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   462
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   464
/** Prepare an object description request.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   465
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   466
 * \return Zero on success, otherwise a negative error code.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   467
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   468
int ec_fsm_coe_dict_prepare_desc(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   469
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   470
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   471
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   472
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   473
    ec_slave_t *slave = fsm->slave;
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   474
    u8 *data = ec_slave_mbox_prepare_send(slave, datagram, EC_MBOX_TYPE_COE,
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   475
			8);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   476
    if (IS_ERR(data)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   477
        return PTR_ERR(data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   478
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   479
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   480
    EC_WRITE_U16(data, 0x8 << 12); // SDO information
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   481
    EC_WRITE_U8 (data + 2, 0x03); // Get object description request
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   482
    EC_WRITE_U8 (data + 3, 0x00);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   483
    EC_WRITE_U16(data + 4, 0x0000);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   484
    EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   485
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   486
    fsm->state = ec_fsm_coe_dict_desc_request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   487
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   488
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   489
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   490
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   491
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   492
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   493
   CoE state: DICT RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   494
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   495
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   496
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   497
void ec_fsm_coe_dict_response(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   498
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   499
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   500
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   501
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   502
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   503
    uint8_t *data, mbox_prot;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   504
    size_t rec_size;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   505
    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
   506
    uint16_t sdo_index, fragments_left;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   507
    ec_sdo_t *sdo;
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 2041
diff changeset
   508
    bool first_segment;
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 2041
diff changeset
   509
    size_t index_list_offset;
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 2041
diff changeset
   510
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   511
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   512
        ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   513
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   514
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   515
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   516
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   517
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   518
        EC_SLAVE_ERR(slave, "Failed to receive CoE dictionary"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   519
                " response datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   520
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   521
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   522
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   523
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   524
    if (fsm->datagram->working_counter != 1) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   525
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   526
        EC_SLAVE_ERR(slave, "Reception of CoE dictionary response failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   527
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   528
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   529
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   530
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   531
    data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   532
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   533
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   534
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   535
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   536
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   537
    if (mbox_prot != EC_MBOX_TYPE_COE) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   538
        EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   539
                mbox_prot);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   540
        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
   541
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   542
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   543
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   544
    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
   545
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   546
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   547
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   548
        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
   549
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   550
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   551
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
   552
    if (rec_size < 3) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   553
        EC_SLAVE_ERR(slave, "Received corrupted SDO dictionary response"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   554
                " (size %zu).\n", 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
   555
        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
   556
        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
   557
    }
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   558
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   559
    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
   560
        (EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   561
        EC_SLAVE_ERR(slave, "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
   562
        if (rec_size < 10) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   563
            EC_SLAVE_ERR(slave, "Incomplete SDO information"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   564
                    " 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
   565
            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
   566
        } else {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   567
            ec_canopen_abort_msg(slave, EC_READ_U32(data + 6));
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
   568
        }
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   569
        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
   570
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   571
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   572
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   573
    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
   574
        (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
   575
        if (fsm->slave->master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   576
            EC_SLAVE_DBG(slave, 1, "Invalid SDO list response!"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   577
                    " Retrying...\n");
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   578
            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
   579
        }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   580
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   581
        fsm->retries = EC_FSM_RETRIES;
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   582
        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
   583
        return;
436
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
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 2041
diff changeset
   586
    first_segment = list_empty(&slave->sdo_dictionary) ? true : false;
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 2041
diff changeset
   587
    index_list_offset = first_segment ? 8 : 6;
2041
f5b31f46c38f Fixed segmented sdo dictionary upload (only first segment contains list type)
Rafael Blank <ch1010866@ch10pc436>
parents: 1948
diff changeset
   588
2194
1b583b3110cb Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   589
    if (rec_size < index_list_offset || rec_size % 2) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   590
        EC_SLAVE_ERR(slave, "Invalid data size %zu!\n", rec_size);
2194
1b583b3110cb Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   591
        ec_print_data(data, rec_size);
1b583b3110cb Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   592
        fsm->state = ec_fsm_coe_error;
1b583b3110cb Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   593
        return;
1b583b3110cb Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   594
    }
1b583b3110cb Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   595
2041
f5b31f46c38f Fixed segmented sdo dictionary upload (only first segment contains list type)
Rafael Blank <ch1010866@ch10pc436>
parents: 1948
diff changeset
   596
    sdo_count = (rec_size - index_list_offset) / 2;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   597
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   598
    for (i = 0; i < sdo_count; i++) {
2041
f5b31f46c38f Fixed segmented sdo dictionary upload (only first segment contains list type)
Rafael Blank <ch1010866@ch10pc436>
parents: 1948
diff changeset
   599
        sdo_index = EC_READ_U16(data + index_list_offset + i * 2);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   600
        if (!sdo_index) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   601
            EC_SLAVE_DBG(slave, 1, "SDO dictionary contains index 0x0000.\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   602
            continue;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   603
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   604
998
05a24788f3b2 Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   605
        if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   606
            EC_SLAVE_ERR(slave, "Failed to allocate memory for SDO!\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   607
            fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   608
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   609
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   610
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 991
diff changeset
   611
        ec_sdo_init(sdo, slave, sdo_index);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   612
        list_add_tail(&sdo->list, &slave->sdo_dictionary);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   613
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   614
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   615
    fragments_left = EC_READ_U16(data + 4);
1923
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   616
    if (fragments_left) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   617
        EC_SLAVE_DBG(slave, 1, "SDO list fragments left: %u\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   618
                fragments_left);
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   619
    }
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   620
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   621
    if (EC_READ_U8(data + 2) & 0x80 || fragments_left) {
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   622
        // more messages waiting. check again.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   623
        fsm->jiffies_start = fsm->datagram->jiffies_sent;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   624
        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
   625
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   626
        fsm->state = ec_fsm_coe_dict_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   627
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   628
    }
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
    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
   631
        // no SDOs in dictionary. finished.
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   632
        fsm->state = ec_fsm_coe_end; // success
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   633
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   634
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   635
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   636
    // fetch SDO descriptions
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   637
    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
   638
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   639
    fsm->retries = EC_FSM_RETRIES;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   640
    if (ec_fsm_coe_dict_prepare_desc(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   641
        fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   642
    }
436
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
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   645
/*****************************************************************************/
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
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   648
   CoE state: DICT DESC REQUEST.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   649
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   650
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   651
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   652
void ec_fsm_coe_dict_desc_request(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   653
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   654
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   655
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   656
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   657
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   658
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   659
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   660
        if (ec_fsm_coe_dict_prepare_desc(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   661
            fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   662
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   663
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   664
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   665
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   666
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   667
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   668
        EC_SLAVE_ERR(slave, "Failed to receive CoE SDO"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   669
                " description request datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   670
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   671
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   672
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   673
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   674
    if (fsm->datagram->working_counter != 1) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   675
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   676
        EC_SLAVE_ERR(slave, "Reception of CoE SDO description"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   677
                " request failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   678
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   679
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   680
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   681
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   682
    fsm->jiffies_start = fsm->datagram->jiffies_sent;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   683
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   684
    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
   685
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   686
    fsm->state = ec_fsm_coe_dict_desc_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   687
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   688
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   689
/*****************************************************************************/
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
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   692
   CoE state: DICT DESC CHECK.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   693
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   694
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   695
void ec_fsm_coe_dict_desc_check(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   696
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   697
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   698
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   699
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   700
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   701
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   702
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   703
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   704
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   705
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   706
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   707
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   708
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   709
        EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   710
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   711
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   712
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   713
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   714
    if (fsm->datagram->working_counter != 1) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   715
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   716
        EC_SLAVE_ERR(slave, "Reception of CoE mailbox check"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   717
                " datagram failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   718
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   719
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   720
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   721
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   722
    if (!ec_slave_mbox_check(fsm->datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   723
        unsigned long diff_ms =
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   724
            (fsm->datagram->jiffies_received - fsm->jiffies_start) *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   725
            1000 / HZ;
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   726
        if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   727
            fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   728
            EC_SLAVE_ERR(slave, "Timeout while waiting for"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   729
                    " SDO 0x%04x object description response.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   730
                    fsm->sdo->index);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   731
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   732
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   733
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   734
        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
   735
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   736
        return;
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
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   739
    // Fetch response
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   740
    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
   741
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   742
    fsm->state = ec_fsm_coe_dict_desc_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   743
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   744
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   745
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   746
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   747
/** Prepare an entry description request.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   748
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   749
 * \return Zero on success, otherwise a negative error code.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   750
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   751
int ec_fsm_coe_dict_prepare_entry(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   752
        ec_fsm_coe_t *fsm, /**< Finite state machine */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   753
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   754
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   755
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   756
    ec_slave_t *slave = fsm->slave;
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   757
    u8 *data = ec_slave_mbox_prepare_send(slave, datagram, EC_MBOX_TYPE_COE,
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   758
			10);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   759
    if (IS_ERR(data)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   760
        return PTR_ERR(data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   761
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   762
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   763
    EC_WRITE_U16(data, 0x8 << 12); // SDO information
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   764
    EC_WRITE_U8 (data + 2, 0x05); // Get entry description request
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   765
    EC_WRITE_U8 (data + 3, 0x00);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   766
    EC_WRITE_U16(data + 4, 0x0000);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   767
    EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   768
    EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   769
    EC_WRITE_U8 (data + 9, 0x01); // value info (access rights only)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   770
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   771
    fsm->state = ec_fsm_coe_dict_entry_request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   772
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   773
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   774
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   775
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   776
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   777
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   778
   CoE state: DICT DESC RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   779
   \todo Timeout behavior
436
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   782
void ec_fsm_coe_dict_desc_response(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   783
        ec_fsm_coe_t *fsm, /**< Finite state machine */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   784
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   785
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   786
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   787
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   788
    ec_sdo_t *sdo = fsm->sdo;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   789
    uint8_t *data, mbox_prot;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   790
    size_t rec_size, name_size;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   791
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   792
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   793
        ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   794
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   795
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   796
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   797
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   798
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   799
        EC_SLAVE_ERR(slave, "Failed to receive CoE SDO description"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   800
                " response datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   801
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   802
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   803
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   804
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   805
    if (fsm->datagram->working_counter != 1) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   806
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   807
        EC_SLAVE_ERR(slave, "Reception of CoE SDO description"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   808
                " response failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   809
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   810
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   811
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   812
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   813
    data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
   814
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   815
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   816
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   817
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   818
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   819
    if (mbox_prot != EC_MBOX_TYPE_COE) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   820
        EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   821
                mbox_prot);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   822
        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
   823
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   824
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   825
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   826
    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
   827
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   828
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   829
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
   830
        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
   831
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   832
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   833
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
   834
    if (rec_size < 3) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   835
        EC_SLAVE_ERR(slave, "Received corrupted SDO description response"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   836
                " (size %zu).\n", 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
   837
        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
   838
        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
   839
    }
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   840
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   841
    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
   842
        (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   843
        EC_SLAVE_ERR(slave, "SDO information error response while"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   844
                " fetching SDO 0x%04X!\n", sdo->index);
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   845
        ec_canopen_abort_msg(slave, EC_READ_U32(data + 6));
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   846
        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
   847
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   848
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   849
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
   850
    if (rec_size < 8) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   851
        EC_SLAVE_ERR(slave, "Received corrupted SDO"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   852
                " description response (size %zu).\n", 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
   853
        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
   854
        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
   855
    }
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   856
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   857
    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
   858
        (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
   859
        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
   860
        if (fsm->slave->master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   861
            EC_SLAVE_DBG(slave, 1, "Invalid object description response while"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   862
                    " fetching SDO 0x%04X!\n", sdo->index);
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   863
            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
   864
        }
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   865
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   866
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   867
        fsm->retries = EC_FSM_RETRIES;
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   868
        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
   869
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   870
    }
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
    if (rec_size < 12) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   873
        EC_SLAVE_ERR(slave, "Invalid data size!\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   874
        ec_print_data(data, rec_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   875
        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
   876
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   877
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   878
962
ea83a7aab57a Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
   879
    sdo->max_subindex = EC_READ_U8(data + 10);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   880
    sdo->object_code = EC_READ_U8(data + 11);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   881
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   882
    name_size = rec_size - 12;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   883
    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
   884
        if (!(sdo->name = kmalloc(name_size + 1, GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   885
            EC_SLAVE_ERR(slave, "Failed to allocate SDO name!\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   886
            fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   887
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   888
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   889
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   890
        memcpy(sdo->name, data + 12, name_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   891
        sdo->name[name_size] = 0;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   892
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   893
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   894
    if (EC_READ_U8(data + 2) & 0x80) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   895
        EC_SLAVE_ERR(slave, "Fragment follows (not implemented)!\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   896
        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
   897
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   898
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   899
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   900
    // start fetching entries
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   901
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   902
    fsm->subindex = 0;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   903
    fsm->retries = EC_FSM_RETRIES;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   904
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   905
    if (ec_fsm_coe_dict_prepare_entry(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   906
        fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   907
    }
436
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
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   910
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   911
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   912
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   913
   CoE state: DICT ENTRY REQUEST.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   914
   \todo Timeout behavior
436
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   917
void ec_fsm_coe_dict_entry_request(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   918
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   919
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   920
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   921
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   922
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   923
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   924
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   925
        if (ec_fsm_coe_dict_prepare_entry(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   926
            fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   927
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   928
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   929
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   930
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   931
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   932
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   933
        EC_SLAVE_ERR(slave, "Failed to receive CoE SDO entry"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   934
                " request datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   935
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   936
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   937
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   938
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   939
    if (fsm->datagram->working_counter != 1) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   940
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   941
        EC_SLAVE_ERR(slave, "Reception of CoE SDO entry request failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   942
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   943
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   944
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   945
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   946
    fsm->jiffies_start = fsm->datagram->jiffies_sent;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   947
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   948
    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
   949
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   950
    fsm->state = ec_fsm_coe_dict_entry_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   951
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   952
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   953
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   954
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   955
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   956
   CoE state: DICT ENTRY CHECK.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   957
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   958
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   959
void ec_fsm_coe_dict_entry_check(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   960
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   961
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   962
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   963
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   964
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   965
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   966
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   967
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   968
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   969
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   970
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   971
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   972
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   973
        EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   974
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   975
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   976
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   977
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   978
    if (fsm->datagram->working_counter != 1) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
   979
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   980
        EC_SLAVE_ERR(slave, "Reception of CoE mailbox check"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   981
                " datagram failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   982
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   983
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   984
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   985
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   986
    if (!ec_slave_mbox_check(fsm->datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
   987
        unsigned long diff_ms =
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   988
            (fsm->datagram->jiffies_received - fsm->jiffies_start) *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   989
            1000 / HZ;
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
   990
        if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   991
            fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   992
            EC_SLAVE_ERR(slave, "Timeout while waiting for"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   993
                    " SDO entry 0x%04x:%x description response.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
   994
                    fsm->sdo->index, fsm->subindex);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   995
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   996
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   997
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
   998
        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
   999
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1000
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1001
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1002
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1003
    // Fetch response
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1004
    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
  1005
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1006
    fsm->state = ec_fsm_coe_dict_entry_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1007
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1008
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1009
/*****************************************************************************/
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
   CoE state: DICT ENTRY RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1013
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1014
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1015
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1016
void ec_fsm_coe_dict_entry_response(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1017
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1018
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1019
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1020
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1021
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1022
    ec_sdo_t *sdo = fsm->sdo;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1023
    uint8_t *data, mbox_prot;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1024
    size_t rec_size, data_size;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1025
    ec_sdo_entry_t *entry;
1382
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
  1026
    u16 word;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1027
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1028
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1029
        ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1030
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1031
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1032
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1033
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1034
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1035
        EC_SLAVE_ERR(slave, "Failed to receive CoE SDO"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1036
                " description response datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1037
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1038
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1039
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1040
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1041
    if (fsm->datagram->working_counter != 1) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1042
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1043
        EC_SLAVE_ERR(slave, "Reception of CoE SDO description"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1044
                " response failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1045
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1046
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1047
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1048
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1049
    data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1050
    if (IS_ERR(data)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1051
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1052
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1053
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1054
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  1055
    if (mbox_prot != EC_MBOX_TYPE_COE) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1056
        EC_SLAVE_ERR(slave, "Received mailbox protocol"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1057
                " 0x%02X as response.\n", mbox_prot);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1058
        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
  1059
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1060
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1061
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1062
    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
  1063
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1064
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1065
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1066
        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
  1067
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1068
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1069
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
  1070
    if (rec_size < 3) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1071
        EC_SLAVE_ERR(slave, "Received corrupted SDO entry"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1072
                " description response (size %zu).\n", 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
  1073
        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
  1074
        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
  1075
    }
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
  1076
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1077
    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
  1078
        (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response
2195
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1079
        EC_SLAVE_WARN(slave, "SDO information error response while"
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1080
               " fetching SDO entry 0x%04X:%02X!\n",
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1081
               sdo->index, fsm->subindex);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1082
        ec_canopen_abort_msg(slave, EC_READ_U32(data + 6));
2195
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1083
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1084
        /* There may be gaps in the subindices, so try to continue with next
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1085
         * subindex. */
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1086
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1087
    } else {
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1088
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1089
        if (rec_size < 9) {
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1090
            EC_SLAVE_ERR(slave, "Received corrupted SDO entry"
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1091
                    " description response (size %zu).\n", rec_size);
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1092
            fsm->state = ec_fsm_coe_error;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1093
            return;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1094
        }
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1095
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1096
        if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1097
            (EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1098
            EC_READ_U16(data + 6) != sdo->index || // SDO index
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1099
            EC_READ_U8(data + 8) != fsm->subindex) { // SDO subindex
2195
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1100
            if (fsm->slave->master->debug_level) {
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1101
                EC_SLAVE_DBG(slave, 1, "Invalid entry description response"
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1102
                        " while fetching SDO entry 0x%04X:%02X!\n",
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1103
                        sdo->index, fsm->subindex);
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1104
                ec_print_data(data, rec_size);
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1105
            }
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1106
            // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1107
            ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
2195
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1108
            fsm->retries = EC_FSM_RETRIES;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1109
            fsm->state = ec_fsm_coe_dict_entry_check;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1110
            return;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1111
        }
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1112
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1113
        if (rec_size < 16) {
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1114
            EC_SLAVE_ERR(slave, "Invalid data size %zu!\n", rec_size);
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1115
            ec_print_data(data, rec_size);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1116
            fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1117
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1118
        }
2195
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1119
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1120
        data_size = rec_size - 16;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1121
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1122
        if (!(entry = (ec_sdo_entry_t *)
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1123
              kmalloc(sizeof(ec_sdo_entry_t), GFP_KERNEL))) {
2195
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1124
            EC_SLAVE_ERR(slave, "Failed to allocate entry!\n");
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1125
            fsm->state = ec_fsm_coe_error;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1126
            return;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1127
        }
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1128
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1129
        ec_sdo_entry_init(entry, sdo, fsm->subindex);
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1130
        entry->data_type = EC_READ_U16(data + 10);
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1131
        entry->bit_length = EC_READ_U16(data + 12);
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1132
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1133
        // read access rights
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1134
        word = EC_READ_U16(data + 14);
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1135
        entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP] = word & 0x0001;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1136
        entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1137
            (word >> 1)  & 0x0001;
2195
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1138
        entry->read_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 2)  & 0x0001;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1139
        entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP] = (word >> 3) & 0x0001;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1140
        entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1141
            (word >> 4)  & 0x0001;
2195
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1142
        entry->write_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 5)  & 0x0001;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1143
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1144
        if (data_size) {
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1145
            uint8_t *desc;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1146
            if (!(desc = kmalloc(data_size + 1, GFP_KERNEL))) {
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1147
                EC_SLAVE_ERR(slave, "Failed to allocate SDO entry name!\n");
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1148
                fsm->state = ec_fsm_coe_error;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1149
                return;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1150
            }
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1151
            memcpy(desc, data + 16, data_size);
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1152
            desc[data_size] = 0;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1153
            entry->description = desc;
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1154
        }
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1155
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1156
        list_add_tail(&entry->list, &sdo->entries);
d9146c0ff00f Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents: 2194
diff changeset
  1157
    }
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1158
962
ea83a7aab57a Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1159
    if (fsm->subindex < sdo->max_subindex) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1160
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1161
        fsm->subindex++;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1162
        fsm->retries = EC_FSM_RETRIES;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1163
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1164
        if (ec_fsm_coe_dict_prepare_entry(fsm, datagram)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1165
            fsm->state = ec_fsm_coe_error;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1166
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1167
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1168
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1169
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1170
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1171
    // another SDO description to fetch?
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1172
    if (fsm->sdo->list.next != &slave->sdo_dictionary) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1173
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1174
        fsm->sdo = list_entry(fsm->sdo->list.next, ec_sdo_t, list);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1175
        fsm->retries = EC_FSM_RETRIES;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1176
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1177
        if (ec_fsm_coe_dict_prepare_desc(fsm, datagram)) {
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1178
            fsm->state = ec_fsm_coe_error;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1179
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1180
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1181
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1182
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1183
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1184
    fsm->state = ec_fsm_coe_end;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1185
}
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
/******************************************************************************
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1188
 *  CoE state machine
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1191
/** Prepare a donwnload request.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1192
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1193
 * \return Zero on success, otherwise a negative error code.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1194
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1195
int ec_fsm_coe_prepare_down_start(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1196
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1197
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1198
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1199
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1200
    u8 *data;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1201
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1202
    ec_sdo_request_t *request = fsm->request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1203
    uint8_t data_set_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1204
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1205
    if (request->data_size <= 4) { // use expedited transfer type
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  1206
        data = ec_slave_mbox_prepare_send(slave, datagram, EC_MBOX_TYPE_COE,
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1207
                EC_COE_DOWN_REQ_HEADER_SIZE);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1208
        if (IS_ERR(data)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1209
            request->errno = PTR_ERR(data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1210
            return PTR_ERR(data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1211
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1212
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1213
        fsm->remaining = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1214
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1215
        data_set_size = 4 - request->data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1216
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1217
        EC_WRITE_U16(data, 0x2 << 12); // SDO request
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1218
        EC_WRITE_U8 (data + 2, (0x3 // size specified, expedited
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1219
                    | data_set_size << 2
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1220
                    | ((request->complete_access ? 1 : 0) << 4)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1221
                    | 0x1 << 5)); // Download request
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1222
        EC_WRITE_U16(data + 3, request->index);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1223
        EC_WRITE_U8 (data + 5,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1224
                request->complete_access ? 0x00 : request->subindex);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1225
        memcpy(data + 6, request->data, request->data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1226
        memset(data + 6 + request->data_size, 0x00, 4 - request->data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1227
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1228
        if (slave->master->debug_level) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1229
            EC_SLAVE_DBG(slave, 1, "Expedited download request:\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1230
            ec_print_data(data, EC_COE_DOWN_REQ_HEADER_SIZE);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1231
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1232
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1233
    else { // request->data_size > 4, use normal transfer type
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1234
        size_t data_size,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1235
               max_data_size =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1236
                   slave->configured_rx_mailbox_size - EC_MBOX_HEADER_SIZE,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1237
               required_data_size =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1238
                   EC_COE_DOWN_REQ_HEADER_SIZE + request->data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1239
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1240
        if (max_data_size < required_data_size) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1241
            // segmenting needed
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1242
            data_size = max_data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1243
        } else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1244
            data_size = required_data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1245
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1246
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  1247
        data = ec_slave_mbox_prepare_send(slave, datagram, EC_MBOX_TYPE_COE,
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1248
                data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1249
        if (IS_ERR(data)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1250
            request->errno = PTR_ERR(data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1251
            return PTR_ERR(data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1252
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1253
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1254
        fsm->offset = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1255
        fsm->remaining = request->data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1256
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1257
        EC_WRITE_U16(data, 0x2 << 12); // SDO request
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1258
        EC_WRITE_U8(data + 2,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1259
                0x1 // size indicator, normal
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1260
                | ((request->complete_access ? 1 : 0) << 4)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1261
                | 0x1 << 5); // Download request
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1262
        EC_WRITE_U16(data + 3, request->index);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1263
        EC_WRITE_U8 (data + 5,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1264
                request->complete_access ? 0x00 : request->subindex);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1265
        EC_WRITE_U32(data + 6, request->data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1266
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1267
        if (data_size > EC_COE_DOWN_REQ_HEADER_SIZE) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1268
            size_t segment_size = data_size - EC_COE_DOWN_REQ_HEADER_SIZE;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1269
            memcpy(data + EC_COE_DOWN_REQ_HEADER_SIZE,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1270
                    request->data, segment_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1271
            fsm->offset += segment_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1272
            fsm->remaining -= segment_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1273
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1274
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1275
        if (slave->master->debug_level) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1276
            EC_SLAVE_DBG(slave, 1, "Normal download request:\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1277
            ec_print_data(data, data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1278
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1279
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1280
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1281
    fsm->state = ec_fsm_coe_down_request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1282
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1283
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1284
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1285
/****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1286
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1287
/** CoE state: DOWN START.
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1288
 */
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1289
void ec_fsm_coe_down_start(
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1290
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1291
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1292
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1293
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1294
    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
  1295
    ec_sdo_request_t *request = fsm->request;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1296
874
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1297
    if (fsm->slave->master->debug_level) {
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1298
        char subidxstr[10];
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1299
        if (request->complete_access) {
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1300
            subidxstr[0] = 0x00;
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1301
        } else {
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1302
            sprintf(subidxstr, ":%02X", request->subindex);
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1303
        }
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1304
        EC_SLAVE_DBG(slave, 1, "Downloading SDO 0x%04X%s.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1305
                request->index, subidxstr);
874
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1306
        ec_print_data(request->data, request->data_size);
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  1307
    }
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1308
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
  1309
    if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1310
        EC_SLAVE_ERR(slave, "Slave does not support CoE!\n");
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1311
        request->errno = EPROTONOSUPPORT;
825
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1312
        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
  1313
        return;
3771f5a0ed90 CoE state machines raising error, if the slave does not support CoE.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1314
    }
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1498
diff changeset
  1315
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1316
    if (slave->configured_rx_mailbox_size <
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1317
            EC_MBOX_HEADER_SIZE + EC_COE_DOWN_REQ_HEADER_SIZE) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1318
        EC_SLAVE_ERR(slave, "Mailbox too small!\n");
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1319
        request->errno = EOVERFLOW;
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1320
        fsm->state = ec_fsm_coe_error;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1321
        return;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1322
    }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1323
975
dae04112bcc7 Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
  1324
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1325
    fsm->request->jiffies_sent = jiffies;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1326
    fsm->retries = EC_FSM_RETRIES;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1327
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1328
    if (ec_fsm_coe_prepare_down_start(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1329
        fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1330
    }
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1331
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1332
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1333
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1334
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1335
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1336
   CoE state: DOWN REQUEST.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1337
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1338
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1339
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1340
void ec_fsm_coe_down_request(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1341
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1342
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1343
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1344
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1345
    ec_slave_t *slave = fsm->slave;
1792
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1346
    unsigned long diff_ms;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1347
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1348
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1349
        if (ec_fsm_coe_prepare_down_start(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1350
            fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1351
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1352
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1353
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1354
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1355
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1356
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1357
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1358
        EC_SLAVE_ERR(slave, "Failed to receive CoE download"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1359
                " request datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1360
        ec_datagram_print_state(fsm->datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1361
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1362
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1363
1792
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1364
    diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ;
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1365
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1366
    if (fsm->datagram->working_counter != 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1367
        if (!fsm->datagram->working_counter) {
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1368
            if (diff_ms < fsm->request->response_timeout) {
1791
27030c6b2de3 Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents: 1563
diff changeset
  1369
#if DEBUG_RETRIES
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1370
                EC_SLAVE_DBG(slave, 1, "Slave did not respond to SDO"
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1371
                        " download request. Retrying after %lu ms...\n",
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1372
                        diff_ms);
1791
27030c6b2de3 Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents: 1563
diff changeset
  1373
#endif
1112
d11661e1f4de Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents: 1111
diff changeset
  1374
                // no response; send request datagram again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1375
                if (ec_fsm_coe_prepare_down_start(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1376
                    fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1377
                }
1112
d11661e1f4de Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents: 1111
diff changeset
  1378
                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
  1379
            }
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1380
        }
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1381
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1382
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1383
        EC_SLAVE_ERR(slave, "Reception of CoE download request"
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1384
                " for SDO 0x%04x:%x failed with timeout after %lu ms: ",
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1385
                fsm->request->index, fsm->request->subindex, diff_ms);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1386
        ec_datagram_print_wc_error(fsm->datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1387
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1388
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1389
1792
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1390
#if DEBUG_LONG
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1391
    if (diff_ms > 200) {
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1392
        EC_SLAVE_WARN(slave, "SDO 0x%04x:%x download took %lu ms.\n",
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1393
                fsm->request->index, fsm->request->subindex, diff_ms);
1792
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1394
    }
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1395
#endif
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1396
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1397
    fsm->jiffies_start = fsm->datagram->jiffies_sent;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1398
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1399
    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
  1400
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1401
    fsm->state = ec_fsm_coe_down_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1402
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1403
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1404
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1405
1907
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
  1406
/** CoE state: DOWN CHECK.
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
  1407
 */
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1408
void ec_fsm_coe_down_check(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1409
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1410
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1411
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1412
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1413
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1414
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1415
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1416
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1417
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1418
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1419
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1420
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1421
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1422
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1423
        EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1424
                " datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1425
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1426
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1427
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1428
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1429
    if (fsm->datagram->working_counter != 1) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1430
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1431
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1432
        EC_SLAVE_ERR(slave, "Reception of CoE mailbox check"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1433
                " datagram failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1434
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1435
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1436
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1437
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1438
    if (!ec_slave_mbox_check(fsm->datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  1439
        unsigned long diff_ms =
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1440
            (fsm->datagram->jiffies_received - fsm->jiffies_start) *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1441
            1000 / HZ;
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1442
        if (diff_ms >= fsm->request->response_timeout) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1443
            fsm->request->errno = EIO;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1444
            fsm->state = ec_fsm_coe_error;
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1445
            EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting"
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1446
                    " for SDO 0x%04x:%x download response.\n", diff_ms,
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1447
                    fsm->request->index, fsm->request->subindex);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1448
            return;
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1451
        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
  1452
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1453
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1454
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1455
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1456
    // Fetch response
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1457
    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
  1458
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1459
    fsm->state = ec_fsm_coe_down_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1460
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1461
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1462
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1463
1907
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
  1464
/** Prepare a download segment request.
dd276ae226b4 Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
  1465
 */
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1466
void ec_fsm_coe_down_prepare_segment_request(
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1467
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1468
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1469
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1470
{
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1471
    ec_slave_t *slave = fsm->slave;
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1472
    ec_sdo_request_t *request = fsm->request;
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1473
    size_t max_segment_size =
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1474
        slave->configured_rx_mailbox_size
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1475
        - EC_MBOX_HEADER_SIZE
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1476
        - EC_COE_DOWN_SEG_REQ_HEADER_SIZE;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1477
    size_t data_size;
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1478
    uint8_t last_segment, seg_data_size, *data;
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1479
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1480
    if (fsm->remaining > max_segment_size) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1481
        fsm->segment_size = max_segment_size;
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1482
        last_segment = 0;
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1483
    } else {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1484
        fsm->segment_size = fsm->remaining;
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1485
        last_segment = 1;
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1486
    }
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1487
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1488
    if (fsm->segment_size > EC_COE_DOWN_SEG_MIN_DATA_SIZE) {
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1489
        seg_data_size = 0x00;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1490
        data_size = EC_COE_DOWN_SEG_REQ_HEADER_SIZE + fsm->segment_size;
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1491
    } else {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1492
        seg_data_size = EC_COE_DOWN_SEG_MIN_DATA_SIZE - fsm->segment_size;
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1493
        data_size = EC_COE_DOWN_SEG_REQ_HEADER_SIZE
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1494
            + EC_COE_DOWN_SEG_MIN_DATA_SIZE;
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1495
    }
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1496
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  1497
    data = ec_slave_mbox_prepare_send(slave, datagram, EC_MBOX_TYPE_COE,
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1498
            data_size);
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1499
    if (IS_ERR(data)) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1500
        request->errno = PTR_ERR(data);
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1501
        fsm->state = ec_fsm_coe_error;
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1502
        return;
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1503
    }
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1504
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1505
    EC_WRITE_U16(data, 0x2 << 12); // SDO request
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1506
    EC_WRITE_U8(data + 2, (last_segment ? 1 : 0)
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1507
            | (seg_data_size << 1)
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1508
            | (fsm->toggle << 4)
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1509
            | (0x00 << 5)); // Download segment request
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1510
    memcpy(data + EC_COE_DOWN_SEG_REQ_HEADER_SIZE,
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1511
            request->data + fsm->offset, fsm->segment_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1512
    if (fsm->segment_size < EC_COE_DOWN_SEG_MIN_DATA_SIZE) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1513
        memset(data + EC_COE_DOWN_SEG_REQ_HEADER_SIZE + fsm->segment_size,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1514
                0x00, EC_COE_DOWN_SEG_MIN_DATA_SIZE - fsm->segment_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1515
    }
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1516
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1517
    if (slave->master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1518
        EC_SLAVE_DBG(slave, 1, "Download segment request:\n");
1563
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1519
        ec_print_data(data, data_size);
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1520
    }
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1521
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1522
    fsm->state = ec_fsm_coe_down_seg_check;
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1523
}
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1524
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1525
/*****************************************************************************/
ddedb71b3a85 Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents: 1562
diff changeset
  1526
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1527
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1528
   CoE state: DOWN RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1529
   \todo Timeout behavior
436
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1532
void ec_fsm_coe_down_response(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1533
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1534
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1535
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1536
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1537
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1538
    uint8_t *data, mbox_prot;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1539
    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
  1540
    ec_sdo_request_t *request = fsm->request;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1541
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1542
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1543
        ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1544
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1545
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1546
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1547
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1548
        request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1549
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1550
        EC_SLAVE_ERR(slave, "Failed to receive CoE download"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1551
                " response datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1552
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1553
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1554
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1555
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1556
    if (fsm->datagram->working_counter != 1) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1557
        request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1558
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1559
        EC_SLAVE_ERR(slave, "Reception of CoE download response failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1560
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1561
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1562
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1563
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1564
    data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1565
    if (IS_ERR(data)) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1566
        request->errno = PTR_ERR(data);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1567
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1568
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1569
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1570
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  1571
    if (mbox_prot != EC_MBOX_TYPE_COE) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1572
        request->errno = EIO;
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  1573
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1574
        EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1575
                mbox_prot);
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  1576
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1577
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1578
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1579
    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
  1580
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1581
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1582
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1583
        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
  1584
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1585
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  1586
975
dae04112bcc7 Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
  1587
    if (slave->master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1588
        EC_SLAVE_DBG(slave, 1, "Download response:\n");
975
dae04112bcc7 Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
  1589
        ec_print_data(data, rec_size);
dae04112bcc7 Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
  1590
    }
dae04112bcc7 Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
  1591
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1592
    if (rec_size < 6) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1593
        request->errno = EIO;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1594
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1595
        EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1596
                rec_size);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1597
        ec_print_data(data, rec_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1598
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1599
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1600
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1601
    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
  1602
        EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1603
        char subidxstr[10];
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1604
        request->errno = EIO;
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1605
        fsm->state = ec_fsm_coe_error;
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1606
        if (request->complete_access) {
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1607
            subidxstr[0] = 0x00;
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1608
        } else {
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1609
            sprintf(subidxstr, ":%02X", request->subindex);
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1610
        }
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1611
        EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1612
                request->index, subidxstr, request->data_size);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1613
        if (rec_size < 10) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1614
            EC_SLAVE_ERR(slave, "Incomplete abort command:\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1615
            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
  1616
        } 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
  1617
            fsm->request->abort_code = EC_READ_U32(data + 6);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1618
            ec_canopen_abort_msg(slave, fsm->request->abort_code);
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
  1619
        }
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1620
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1621
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1622
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1623
    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
  1624
        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
  1625
        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
  1626
        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
  1627
        if (slave->master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1628
            EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1629
                    " Retrying...\n");
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1630
            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
  1631
        }
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1632
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1633
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1634
        fsm->retries = EC_FSM_RETRIES;
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  1635
        fsm->state = ec_fsm_coe_down_check;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1636
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1637
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1638
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1639
    if (fsm->remaining) { // more segments to download
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1640
        fsm->toggle = 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1641
        ec_fsm_coe_down_prepare_segment_request(fsm, datagram);
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1642
    } else {
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1643
        fsm->state = ec_fsm_coe_end; // success
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1644
    }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1645
}
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1646
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1647
/*****************************************************************************/
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1648
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1649
/**
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1650
   CoE state: DOWN SEG CHECK.
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1651
*/
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1652
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1653
void ec_fsm_coe_down_seg_check(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1654
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1655
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1656
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1657
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1658
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1659
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1660
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1661
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1662
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1663
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1664
        fsm->request->errno = EIO;
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1665
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1666
        EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1667
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1668
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1669
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1670
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1671
    if (fsm->datagram->working_counter != 1) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1672
        fsm->request->errno = EIO;
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1673
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1674
        EC_SLAVE_ERR(slave, "Reception of CoE mailbox segment check"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1675
                " datagram failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1676
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1677
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1678
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1679
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1680
    if (!ec_slave_mbox_check(fsm->datagram)) {
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1681
        unsigned long diff_ms =
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1682
            (fsm->datagram->jiffies_received - fsm->jiffies_start) *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1683
            1000 / HZ;
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1684
        if (diff_ms >= fsm->request->response_timeout) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1685
            fsm->request->errno = EIO;
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1686
            fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1687
            EC_SLAVE_ERR(slave, "Timeout while waiting for SDO download"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1688
                    " segment response.\n");
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1689
            return;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1690
        }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1691
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1692
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1693
        fsm->retries = EC_FSM_RETRIES;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1694
        return;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1695
    }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1696
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1697
    // Fetch response
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1698
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1699
    fsm->retries = EC_FSM_RETRIES;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1700
    fsm->state = ec_fsm_coe_down_seg_response;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1701
}
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1702
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1703
/*****************************************************************************/
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1704
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1705
/**
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1706
   CoE state: DOWN SEG RESPONSE.
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1707
   \todo Timeout behavior
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1708
*/
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1709
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1710
void ec_fsm_coe_down_seg_response(
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1711
        ec_fsm_coe_t *fsm, /**< Finite state machine */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1712
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1713
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1714
{
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1715
    ec_slave_t *slave = fsm->slave;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1716
    uint8_t *data, mbox_prot;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1717
    size_t rec_size;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1718
    ec_sdo_request_t *request = fsm->request;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1719
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1720
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1721
        ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1722
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1723
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1724
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1725
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1726
        request->errno = EIO;
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1727
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1728
        EC_SLAVE_ERR(slave, "Failed to receive CoE download response"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1729
                " datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1730
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1731
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1732
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1733
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1734
    if (fsm->datagram->working_counter != 1) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1735
        request->errno = EIO;
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1736
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1737
        EC_SLAVE_ERR(slave, "Reception of CoE download response failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1738
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1739
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1740
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1741
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1742
    data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size);
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1743
    if (IS_ERR(data)) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1744
        request->errno = PTR_ERR(data);
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1745
        fsm->state = ec_fsm_coe_error;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1746
        return;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1747
    }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1748
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  1749
    if (mbox_prot != EC_MBOX_TYPE_COE) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1750
        request->errno = EIO;
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1751
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1752
        EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1753
                mbox_prot);
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1754
        return;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1755
    }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1756
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1757
    if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) {
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1758
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1759
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1760
        fsm->retries = EC_FSM_RETRIES;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1761
        fsm->state = ec_fsm_coe_down_check;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1762
        return;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1763
    }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1764
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1765
    if (slave->master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1766
        EC_SLAVE_DBG(slave, 1, "Download response:\n");
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1767
        ec_print_data(data, rec_size);
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1768
    }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1769
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1770
    if (rec_size < 6) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1771
        request->errno = EIO;
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1772
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1773
        EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1774
                rec_size);
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1775
        ec_print_data(data, rec_size);
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1776
        return;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1777
    }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1778
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1779
    if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1780
        EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1781
        char subidxstr[10];
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1782
        request->errno = EIO;
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1783
        fsm->state = ec_fsm_coe_error;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1784
        if (request->complete_access) {
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1785
            subidxstr[0] = 0x00;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1786
        } else {
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1787
            sprintf(subidxstr, ":%02X", request->subindex);
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1788
        }
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1789
        EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1790
                request->index, subidxstr, request->data_size);
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1791
        if (rec_size < 10) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1792
            EC_SLAVE_ERR(slave, "Incomplete abort command:\n");
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1793
            ec_print_data(data, rec_size);
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1794
        } else {
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1795
            fsm->request->abort_code = EC_READ_U32(data + 6);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1796
            ec_canopen_abort_msg(slave, fsm->request->abort_code);
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1797
        }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1798
        return;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1799
    }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1800
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1801
    if (EC_READ_U16(data) >> 12 != 0x3 ||
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1802
            ((EC_READ_U8(data + 2) >> 5) != 0x01)) { // segment response
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1803
        if (slave->master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1804
            EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1805
                    " Retrying...\n");
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1806
            ec_print_data(data, rec_size);
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1807
        }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1808
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1809
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1810
        fsm->retries = EC_FSM_RETRIES;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1811
        fsm->state = ec_fsm_coe_down_seg_check;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1812
        return;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1813
    }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1814
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1815
    if (((EC_READ_U8(data + 2) >> 4) & 0x01) != fsm->toggle) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1816
        EC_SLAVE_ERR(slave, "Invalid toggle received during"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1817
                " segmented download:\n");
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1818
        ec_print_data(data, rec_size);
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1819
        request->errno = EIO;
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1820
        fsm->state = ec_fsm_coe_error;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1821
        return;
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1822
    }
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1823
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1824
    fsm->offset += fsm->segment_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1825
    fsm->remaining -= fsm->segment_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1826
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1827
    if (fsm->remaining) { // more segments to download
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1828
        fsm->toggle = !fsm->toggle;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1829
        ec_fsm_coe_down_prepare_segment_request(fsm, datagram);
1562
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1830
    } else {
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1831
        fsm->state = ec_fsm_coe_end; // success
5c249f469b81 SDO segmented download.
Florian Pose <fp@igh-essen.com>
parents: 1550
diff changeset
  1832
    }
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1833
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1834
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1835
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1836
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1837
/** Prepare an upload request.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1838
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1839
 * \return Zero on success, otherwise a negative error code.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1840
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1841
int ec_fsm_coe_prepare_up(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1842
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1843
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1844
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1845
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1846
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1847
    ec_sdo_request_t *request = fsm->request;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1848
    ec_master_t *master = slave->master;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1849
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  1850
    u8 *data = ec_slave_mbox_prepare_send(slave, datagram, EC_MBOX_TYPE_COE,
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  1851
			10);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  1852
    if (IS_ERR(data)) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1853
        request->errno = PTR_ERR(data);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1854
        return PTR_ERR(data);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1855
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1856
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1857
    EC_WRITE_U16(data, 0x2 << 12); // SDO request
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1858
    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
  1859
    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
  1860
    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
  1861
    memset(data + 6, 0x00, 4);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1862
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1863
    if (master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1864
        EC_SLAVE_DBG(slave, 1, "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
  1865
        ec_print_data(data, 10);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1866
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1867
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1868
    fsm->state = ec_fsm_coe_up_request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1869
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1870
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1871
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1872
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1873
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1874
/**
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1875
   CoE state: UP START.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1876
*/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1877
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1878
void ec_fsm_coe_up_start(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1879
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1880
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1881
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1882
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1883
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1884
    ec_sdo_request_t *request = fsm->request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1885
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1886
    EC_SLAVE_DBG(slave, 1, "Uploading SDO 0x%04X:%02X.\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1887
            request->index, request->subindex);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1888
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1889
    if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1890
        EC_SLAVE_ERR(slave, "Slave does not support CoE!\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1891
        request->errno = EPROTONOSUPPORT;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1892
        fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1893
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1894
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1895
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1896
    fsm->retries = EC_FSM_RETRIES;
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1897
    fsm->request->jiffies_sent = jiffies;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1898
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1899
    if (ec_fsm_coe_prepare_up(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1900
        fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1901
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1902
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1903
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1904
/*****************************************************************************/
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1905
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1906
   CoE state: UP REQUEST.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1907
   \todo Timeout behavior
436
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1910
void ec_fsm_coe_up_request(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1911
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1912
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1913
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1914
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1915
    ec_slave_t *slave = fsm->slave;
1792
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1916
    unsigned long diff_ms;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1917
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1918
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1919
        if (ec_fsm_coe_prepare_up(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1920
            fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1921
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1922
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1923
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1924
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1925
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1926
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1927
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1928
        EC_SLAVE_ERR(slave, "Failed to receive CoE upload request: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1929
        ec_datagram_print_state(fsm->datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1930
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1931
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1932
1792
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1933
    diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ;
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1934
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1935
    if (fsm->datagram->working_counter != 1) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1936
        if (!fsm->datagram->working_counter) {
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1937
            if (diff_ms < fsm->request->response_timeout) {
1791
27030c6b2de3 Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents: 1563
diff changeset
  1938
#if DEBUG_RETRIES
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1939
                EC_SLAVE_DBG(slave, 1, "Slave did not respond to"
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1940
                        " SDO upload request. Retrying after %lu ms...\n",
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1941
                        diff_ms);
1791
27030c6b2de3 Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents: 1563
diff changeset
  1942
#endif
1112
d11661e1f4de Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents: 1111
diff changeset
  1943
                // no response; send request datagram again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1944
                if (ec_fsm_coe_prepare_up(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1945
                    fsm->state = ec_fsm_coe_error;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1946
                }
1112
d11661e1f4de Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents: 1111
diff changeset
  1947
                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
  1948
            }
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
  1949
        }
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1950
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1951
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1952
        EC_SLAVE_ERR(slave, "Reception of CoE upload request for"
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1953
                " SDO 0x%04x:%x failed with timeout after %lu ms: ",
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1954
                fsm->request->index, fsm->request->subindex, diff_ms);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1955
        ec_datagram_print_wc_error(fsm->datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1956
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1957
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1958
1792
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1959
#if DEBUG_LONG
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1960
    if (diff_ms > 200) {
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1961
        EC_SLAVE_WARN(slave, "SDO 0x%04x:%x upload took %lu ms.\n",
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  1962
                fsm->request->index, fsm->request->subindex, diff_ms);
1792
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1963
    }
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1964
#endif
3eb466e9bad5 Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1791
diff changeset
  1965
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1966
    fsm->jiffies_start = fsm->datagram->jiffies_sent;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1967
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1968
    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
  1969
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1970
    fsm->state = ec_fsm_coe_up_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1971
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1972
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1973
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1974
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1975
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1976
   CoE state: UP CHECK.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1977
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1978
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1979
void ec_fsm_coe_up_check(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1980
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1981
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1982
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1983
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1984
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1985
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1986
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1987
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1988
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1989
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1990
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1991
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  1992
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  1993
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  1994
        EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1995
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1996
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1997
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1998
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  1999
    if (fsm->datagram->working_counter != 1) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2000
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2001
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2002
        EC_SLAVE_ERR(slave, "Reception of CoE mailbox check"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2003
                " datagram failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2004
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2005
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2006
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2007
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2008
    if (!ec_slave_mbox_check(fsm->datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  2009
        unsigned long diff_ms =
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2010
            (fsm->datagram->jiffies_received - fsm->jiffies_start) *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2011
            1000 / HZ;
1043
2abea4233a6d Response timeout for checking Sdo upload.
Florian Pose <fp@igh-essen.com>
parents: 1038
diff changeset
  2012
        if (diff_ms >= fsm->request->response_timeout) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2013
            fsm->request->errno = EIO;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2014
            fsm->state = ec_fsm_coe_error;
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  2015
            EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting for"
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1923
diff changeset
  2016
                    " SDO 0x%04x:%x upload response.\n", diff_ms,
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2017
                    fsm->request->index, fsm->request->subindex);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2018
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2019
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2020
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2021
        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
  2022
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2023
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2024
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2025
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2026
    // Fetch response
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2027
    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
  2028
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2029
    fsm->state = ec_fsm_coe_up_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2030
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2031
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2032
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2033
1498
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2034
/** Prepare an SDO upload segment request.
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2035
 */
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2036
void ec_fsm_coe_up_prepare_segment_request(
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2037
        ec_fsm_coe_t *fsm, /**< Finite state machine */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2038
        ec_datagram_t *datagram /**< Datagram to use. */
1498
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2039
        )
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2040
{
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2041
    uint8_t *data =
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  2042
        ec_slave_mbox_prepare_send(fsm->slave, datagram, EC_MBOX_TYPE_COE,
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  2043
				10);
1498
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2044
    if (IS_ERR(data)) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2045
        fsm->request->errno = PTR_ERR(data);
1498
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2046
        fsm->state = ec_fsm_coe_error;
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2047
        return;
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2048
    }
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2049
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2050
    EC_WRITE_U16(data, 0x2 << 12); // SDO request
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2051
    EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2052
                | 0x3 << 5)); // upload segment request
1550
81a16ba13ae6 Avoid zeroing mailbox datagram because of VoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 1544
diff changeset
  2053
    memset(data + 3, 0x00, 7);
1498
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2054
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2055
    if (fsm->slave->master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2056
        EC_SLAVE_DBG(fsm->slave, 1, "Upload segment request:\n");
1498
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2057
        ec_print_data(data, 10);
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2058
    }
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2059
}
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2060
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2061
/*****************************************************************************/
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2062
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2063
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2064
   CoE state: UP RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2065
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2066
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2067
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2068
void ec_fsm_coe_up_response(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2069
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2070
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2071
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2072
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2073
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2074
    ec_master_t *master = slave->master;
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2075
    uint16_t rec_index;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2076
    uint8_t *data, mbox_prot, rec_subindex;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2077
    size_t rec_size, data_size;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2078
    ec_sdo_request_t *request = fsm->request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2079
    unsigned int expedited, size_specified;
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2080
    int ret;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2081
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2082
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2083
        ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2084
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2085
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2086
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2087
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2088
        request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2089
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2090
        EC_SLAVE_ERR(slave, "Failed to receive CoE upload response"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2091
                " datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2092
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2093
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2094
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2095
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2096
    if (fsm->datagram->working_counter != 1) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2097
        request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2098
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2099
        EC_SLAVE_ERR(slave, "Reception of CoE upload response failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2100
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2101
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2102
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2103
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2104
    data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  2105
    if (IS_ERR(data)) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2106
        request->errno = PTR_ERR(data);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2107
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2108
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2109
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2110
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2111
    if (master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2112
        EC_SLAVE_DBG(slave, 1, "Upload response:\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2113
        ec_print_data(data, rec_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2114
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2115
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  2116
    if (mbox_prot != EC_MBOX_TYPE_COE) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2117
        request->errno = EIO;
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  2118
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2119
        EC_SLAVE_WARN(slave, "Received mailbox protocol 0x%02X"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2120
                " 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
  2121
        return;
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2122
    }
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2123
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  2124
    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
  2125
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2126
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  2127
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  2128
        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
  2129
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  2130
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  2131
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2132
    if (rec_size < 6) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2133
        request->errno = EIO;
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  2134
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2135
        EC_SLAVE_ERR(slave, "Received currupted SDO upload response"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2136
                " (%zu bytes)!\n", rec_size);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2137
        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
  2138
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2139
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2140
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  2141
    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
  2142
            EC_READ_U8(data + 2) >> 5 == 0x4) { // abort SDO transfer request
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2143
        EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2144
               request->index, request->subindex);
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
  2145
        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
  2146
            request->abort_code = EC_READ_U32(data + 6);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2147
            ec_canopen_abort_msg(slave, request->abort_code);
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
  2148
        } else {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2149
            EC_SLAVE_ERR(slave, "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
  2150
        }
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2151
        request->errno = EIO;
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2152
        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
  2153
        return;
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2154
    }
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2155
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2156
    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
  2157
            EC_READ_U8(data + 2) >> 5 != 0x2) { // upload response
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2158
        EC_SLAVE_ERR(slave, "Received unknown response while"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2159
                " uploading SDO 0x%04X:%02X.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2160
                request->index, request->subindex);
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2161
        ec_print_data(data, rec_size);
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2162
        request->errno = EIO;
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2163
        fsm->state = ec_fsm_coe_error;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2164
        return;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2165
    }
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2166
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2167
    rec_index = EC_READ_U16(data + 3);
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2168
    rec_subindex = EC_READ_U8(data + 5);
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2169
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2170
    if (rec_index != request->index || rec_subindex != request->subindex) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2171
        EC_SLAVE_ERR(slave, "Received upload response for wrong SDO"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2172
                " (0x%04X:%02X, requested: 0x%04X:%02X).\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2173
                rec_index, rec_subindex, request->index, request->subindex);
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2174
        ec_print_data(data, rec_size);
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2175
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2176
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2177
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
1468
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2178
        fsm->retries = EC_FSM_RETRIES;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2179
        fsm->state = ec_fsm_coe_up_check;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2180
        return;
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2181
    }
0a804ddbaf93 Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents: 1457
diff changeset
  2182
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2183
    // normal or expedited?
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2184
    expedited = EC_READ_U8(data + 2) & 0x02;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2185
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2186
    if (expedited) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2187
        size_specified = EC_READ_U8(data + 2) & 0x01;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2188
        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
  2189
            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
  2190
        } 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
  2191
            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
  2192
        }
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
  2193
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
  2194
        if (rec_size < 6 + fsm->complete_size) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2195
            request->errno = EIO;
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  2196
            fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2197
            EC_SLAVE_ERR(slave, "Received corrupted SDO expedited upload"
1543
373cd456dc26 Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
  2198
                    " response (only %zu bytes)!\n", 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
  2199
            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
  2200
            return;
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2201
        }
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2202
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2203
        ret = ec_sdo_request_copy_data(request, data + 6, fsm->complete_size);
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2204
        if (ret) {
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2205
            request->errno = -ret;
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
  2206
            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
  2207
            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
  2208
        }
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2209
    } else { // normal
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2210
        if (rec_size < 10) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2211
            request->errno = EIO;
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  2212
            fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2213
            EC_SLAVE_ERR(slave, "Received currupted SDO normal upload"
1543
373cd456dc26 Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
  2214
                    " response (only %zu bytes)!\n", 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
  2215
            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
  2216
            return;
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2217
        }
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2218
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2219
        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
  2220
        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
  2221
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
  2222
        if (!fsm->complete_size) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2223
            request->errno = EIO;
860
ba5c38f0bb30 Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
  2224
            fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2225
            EC_SLAVE_ERR(slave, "No complete size supplied!\n");
769
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2226
            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
  2227
            return;
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2228
        }
2195c2ea37b4 Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
  2229
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2230
        ret = ec_sdo_request_alloc(request, fsm->complete_size);
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2231
        if (ret) {
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2232
            request->errno = -ret;
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
  2233
            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
  2234
            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
  2235
        }
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  2236
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2237
        ret = ec_sdo_request_copy_data(request, data + 10, data_size);
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2238
        if (ret) {
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2239
            request->errno = -ret;
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
  2240
            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
  2241
            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
  2242
        }
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
  2243
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2244
        fsm->toggle = 0;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2245
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
  2246
        if (data_size < fsm->complete_size) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2247
            EC_SLAVE_DBG(slave, 1, "SDO data incomplete (%zu / %u)."
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2248
                    " Segmenting...\n", data_size, fsm->complete_size);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2249
            ec_fsm_coe_up_prepare_segment_request(fsm, datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2250
            fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2251
            fsm->state = ec_fsm_coe_up_seg_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2252
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2253
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2254
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2255
874
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  2256
    if (master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2257
        EC_SLAVE_DBG(slave, 1, "Uploaded data:\n");
874
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  2258
        ec_print_data(request->data, request->data_size);
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  2259
    }
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  2260
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2261
    fsm->state = ec_fsm_coe_end; // success
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2262
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2263
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2264
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2265
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2266
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2267
   CoE state: UP REQUEST.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2268
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2269
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2270
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2271
void ec_fsm_coe_up_seg_request(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2272
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2273
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2274
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2275
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2276
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2277
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2278
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2279
        ec_fsm_coe_up_prepare_segment_request(fsm, datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2280
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2281
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2282
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2283
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2284
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2285
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2286
        EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2287
                " request datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2288
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2289
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2290
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2291
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2292
    if (fsm->datagram->working_counter != 1) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2293
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2294
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2295
        EC_SLAVE_ERR(slave, "Reception of CoE upload segment"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2296
                " request failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2297
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2298
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2299
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2300
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2301
    fsm->jiffies_start = fsm->datagram->jiffies_sent;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2302
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2303
    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
  2304
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2305
    fsm->state = ec_fsm_coe_up_seg_check;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2306
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2307
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2308
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2309
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2310
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2311
   CoE state: UP CHECK.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2312
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2313
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2314
void ec_fsm_coe_up_seg_check(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2315
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2316
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2317
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2318
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2319
    ec_slave_t *slave = fsm->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2320
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2321
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2322
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2323
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2324
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2325
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2326
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2327
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2328
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2329
        EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2330
                " datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2331
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2332
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2333
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2334
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2335
    if (fsm->datagram->working_counter != 1) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2336
        fsm->request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2337
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2338
        EC_SLAVE_ERR(slave, "Reception of CoE mailbox check datagram"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2339
                " failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2340
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2341
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2342
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2343
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2344
    if (!ec_slave_mbox_check(fsm->datagram)) {
1038
7ca4103ba170 Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
  2345
        unsigned long diff_ms =
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2346
            (fsm->datagram->jiffies_received - fsm->jiffies_start) *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2347
            1000 / HZ;
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  2348
        if (diff_ms >= fsm->request->response_timeout) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2349
            fsm->request->errno = EIO;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2350
            fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2351
            EC_SLAVE_ERR(slave, "Timeout while waiting for SDO upload"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2352
                    " segment response.\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2353
            return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2354
        }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2355
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2356
        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
  2357
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2358
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2359
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2360
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2361
    // Fetch response
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2362
    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
  2363
    fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2364
    fsm->state = ec_fsm_coe_up_seg_response;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2365
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2366
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2367
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2368
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2369
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2370
   CoE state: UP RESPONSE.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2371
   \todo Timeout behavior
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2372
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2373
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2374
void ec_fsm_coe_up_seg_response(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2375
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2376
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2377
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2378
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2379
    ec_slave_t *slave = fsm->slave;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2380
    ec_master_t *master = slave->master;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2381
    uint8_t *data, mbox_prot;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2382
    size_t rec_size, data_size;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2383
    ec_sdo_request_t *request = fsm->request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2384
    unsigned int last_segment;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2385
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2386
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2387
        ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2388
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2389
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2390
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2391
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2392
        request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2393
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2394
        EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2395
                " response datagram: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2396
        ec_datagram_print_state(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2397
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2398
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2399
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2400
    if (fsm->datagram->working_counter != 1) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2401
        request->errno = EIO;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2402
        fsm->state = ec_fsm_coe_error;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2403
        EC_SLAVE_ERR(slave, "Reception of CoE upload segment"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2404
                " response failed: ");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2405
        ec_datagram_print_wc_error(fsm->datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2406
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2407
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2408
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2409
    data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1310
diff changeset
  2410
    if (IS_ERR(data)) {
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2411
        request->errno = PTR_ERR(data);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2412
        fsm->state = ec_fsm_coe_error;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2413
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2414
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2415
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2416
    if (master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2417
        EC_SLAVE_DBG(slave, 1, "Upload segment response:\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2418
        ec_print_data(data, rec_size);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2419
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2420
2591
23b360e4a530 Centrally defined mailbox types.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
  2421
    if (mbox_prot != EC_MBOX_TYPE_COE) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2422
        EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2423
                mbox_prot);
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2424
        request->errno = EIO;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2425
        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
  2426
        return;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  2427
    }
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  2428
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  2429
    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
  2430
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2431
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
895
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  2432
        fsm->retries = EC_FSM_RETRIES;
5c2125247dde Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents: 874
diff changeset
  2433
        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
  2434
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2435
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2437
    if (rec_size < 10) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2438
        EC_SLAVE_ERR(slave, "Received currupted SDO upload"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2439
                " segment response!\n");
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2440
        ec_print_data(data, rec_size);
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2441
        request->errno = EIO;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2442
        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
  2443
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2444
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2445
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  2446
    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
  2447
            EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2448
        EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2449
               request->index, request->subindex);
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
  2450
        request->abort_code = EC_READ_U32(data + 6);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2451
        ec_canopen_abort_msg(slave, request->abort_code);
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2452
        request->errno = EIO;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2453
        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
  2454
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2455
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2456
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  2457
    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
  2458
        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
  2459
        if (fsm->slave->master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2460
            EC_SLAVE_DBG(slave, 1, "Invalid SDO upload segment response!\n");
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  2461
            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
  2462
        }
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  2463
        // check for CoE response again
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2464
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  2465
        fsm->retries = EC_FSM_RETRIES;
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1043
diff changeset
  2466
        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
  2467
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2468
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2469
1533
bd150d066ea2 Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
  2470
    data_size = rec_size - 3; /* Header of segment upload is smaller than
bd150d066ea2 Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
  2471
                                 normal upload */
bd150d066ea2 Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
  2472
    if (rec_size == 10) {
bd150d066ea2 Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
  2473
        uint8_t seg_size = (EC_READ_U8(data + 2) & 0xE) >> 1;
bd150d066ea2 Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
  2474
        data_size -= seg_size;
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
  2475
    }
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
  2476
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
  2477
    if (request->data_size + data_size > fsm->complete_size) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2478
        EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X failed: Fragment"
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
  2479
                " exceeding complete size!\n",
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2480
                request->index, request->subindex);
1948
fa1c4fb0a8da Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
  2481
        request->errno = EOVERFLOW;
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
  2482
        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
  2483
        return;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2484
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2485
1498
58532f81a456 Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents: 1495
diff changeset
  2486
    memcpy(request->data + request->data_size, data + 3, data_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
  2487
    request->data_size += data_size;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2488
1533
bd150d066ea2 Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
  2489
    last_segment = EC_READ_U8(data + 2) & 0x01;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2490
    if (!last_segment) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2491
        fsm->toggle = !fsm->toggle;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2492
        ec_fsm_coe_up_prepare_segment_request(fsm, datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 501
diff changeset
  2493
        fsm->retries = EC_FSM_RETRIES;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2494
        fsm->state = ec_fsm_coe_up_seg_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2495
        return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2496
    }
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2497
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
  2498
    if (request->data_size != fsm->complete_size) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2499
        EC_SLAVE_WARN(slave, "SDO upload 0x%04X:%02X: Assembled data"
1543
373cd456dc26 Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
  2500
                " size (%zu) does not match complete size (%u)!\n",
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2501
                request->index, request->subindex,
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
  2502
                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
  2503
    }
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
  2504
874
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  2505
    if (master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1907
diff changeset
  2506
        EC_SLAVE_DBG(slave, 1, "Uploaded data:\n");
874
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  2507
        ec_print_data(request->data, request->data_size);
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  2508
    }
022f869ea40f Added CoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 860
diff changeset
  2509
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2510
    fsm->state = ec_fsm_coe_end; // success
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2511
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2512
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2513
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2514
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2515
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2516
   State: ERROR.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2517
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2518
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2519
void ec_fsm_coe_error(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2520
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2521
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2522
        )
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2523
{
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2524
}
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2525
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2526
/*****************************************************************************/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2527
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2528
/**
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2529
   State: END.
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2530
*/
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2531
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2532
void ec_fsm_coe_end(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2533
        ec_fsm_coe_t *fsm, /**< Finite state machine. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2534
        ec_datagram_t *datagram /**< Datagram to use. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2535
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2536
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2537
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2538
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2195
diff changeset
  2539
/*****************************************************************************/