master/slave.c
author Gavin Lambert <gavinl@compacsort.com>
Sat, 31 May 2014 14:49:02 +1200
changeset 2616 f99e5b11806c
parent 2600 1a969896d52e
permissions -rw-r--r--
Moved userspace domain unmap to deactivate instead of release, fixing memory/ref leak.
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 26
diff changeset
     1
/******************************************************************************
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 26
diff changeset
     3
 *  $Id$
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
     5
 *  Copyright (C) 2006-2012  Florian Pose, Ingenieurgemeinschaft IgH
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     6
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
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.
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
    12
 *
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.
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
    17
 *
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
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1338
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: 1338
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: 1338
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    27
 *
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 26
diff changeset
    28
 *****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    30
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    31
   \file
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    32
   EtherCAT slave methods.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    33
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    34
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    35
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    36
24
d417dd9bdc2f Wilhelms ?nderungen ?bernommen.
Florian Pose <fp@igh-essen.com>
parents: 23
diff changeset
    37
#include <linux/module.h>
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
    38
#include <linux/delay.h>
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    40
#include "globals.h"
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
    41
#include "datagram.h"
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    42
#include "master.h"
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
    43
#include "slave_config.h"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
    44
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
    45
#include "slave.h"
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 26
diff changeset
    47
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    49
extern const ec_code_msg_t al_status_messages[];
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    50
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    51
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    52
624
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
    53
char *ec_slave_sii_string(ec_slave_t *, unsigned int);
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    54
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    55
/*****************************************************************************/
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    56
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
    58
   Slave constructor.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
    59
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
    60
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
    61
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
    62
void ec_slave_init(
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
    63
        ec_slave_t *slave, /**< EtherCAT slave */
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
    64
        ec_master_t *master, /**< EtherCAT master */
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    65
        ec_device_index_t dev_idx, /**< Device index. */
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
    66
        uint16_t ring_position, /**< ring position */
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
    67
        uint16_t station_address /**< station address to configure */
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
    68
        )
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
    69
{
142
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
    70
    unsigned int i;
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
    71
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
    72
    slave->master = master;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
    73
    slave->device_index = dev_idx;
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    74
    slave->ring_position = ring_position;
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    75
    slave->station_address = station_address;
1909
ea3eb4c74c1b Introduced effective_alias variable to separate reg12 alias from SII alias.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
    76
    slave->effective_alias = 0x0000;
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    77
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
    78
    slave->config = NULL;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
    79
    slave->requested_state = EC_SLAVE_STATE_PREOP;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 320
diff changeset
    80
    slave->current_state = EC_SLAVE_STATE_UNKNOWN;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 320
diff changeset
    81
    slave->error_flag = 0;
908
386b908033be Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    82
    slave->force_config = 0;
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
    83
    slave->configured_rx_mailbox_offset = 0x0000;
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
    84
    slave->configured_rx_mailbox_size = 0x0000;
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
    85
    slave->configured_tx_mailbox_offset = 0x0000;
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
    86
    slave->configured_tx_mailbox_size = 0x0000;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 320
diff changeset
    87
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
    88
    slave->base_type = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
    89
    slave->base_revision = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
    90
    slave->base_build = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
    91
    slave->base_fmmu_count = 0;
1379
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    92
    slave->base_sync_count = 0;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 320
diff changeset
    93
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
    94
    for (i = 0; i < EC_MAX_PORTS; i++) {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
    95
        slave->ports[i].desc = EC_PORT_NOT_IMPLEMENTED;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
    96
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
    97
        slave->ports[i].link.link_up = 0;
2600
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
    98
        slave->ports[i].link.loop_closed = 1;
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
    99
        slave->ports[i].link.signal_detected = 0;
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   100
        slave->sii.physical_layer[i] = 0xFF;
1420
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   101
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   102
        slave->ports[i].receive_time = 0U;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   103
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   104
        slave->ports[i].next_slave = NULL;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   105
        slave->ports[i].delay_to_next_dc = 0U;
2600
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   106
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   107
#ifdef EC_LOOP_CONTROL
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   108
        slave->ports[i].state = EC_SLAVE_PORT_DOWN;
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   109
        slave->ports[i].link_detection_jiffies = 0;
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   110
#endif
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   111
    }
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   112
1379
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   113
    slave->base_fmmu_bit_operation = 0;
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   114
    slave->base_dc_supported = 0;
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   115
    slave->base_dc_range = EC_DC_32;
1419
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   116
    slave->has_dc_system_time = 0;
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
   117
    slave->transmission_delay = 0U;
1379
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   118
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 967
diff changeset
   119
    slave->sii_words = NULL;
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 967
diff changeset
   120
    slave->sii_nwords = 0;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 320
diff changeset
   121
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   122
    slave->sii.alias = 0x0000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   123
    slave->sii.vendor_id = 0x00000000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   124
    slave->sii.product_code = 0x00000000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   125
    slave->sii.revision_number = 0x00000000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   126
    slave->sii.serial_number = 0x00000000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   127
    slave->sii.boot_rx_mailbox_offset = 0x0000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   128
    slave->sii.boot_rx_mailbox_size = 0x0000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   129
    slave->sii.boot_tx_mailbox_offset = 0x0000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   130
    slave->sii.boot_tx_mailbox_size = 0x0000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   131
    slave->sii.std_rx_mailbox_offset = 0x0000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   132
    slave->sii.std_rx_mailbox_size = 0x0000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   133
    slave->sii.std_tx_mailbox_offset = 0x0000;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   134
    slave->sii.std_tx_mailbox_size = 0x0000;
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   135
    slave->sii.mailbox_protocols = 0;
835
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   136
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   137
    slave->sii.strings = NULL;
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   138
    slave->sii.string_count = 0;
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   139
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   140
    slave->sii.has_general = 0;
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   141
    slave->sii.group = NULL;
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   142
    slave->sii.image = NULL;
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   143
    slave->sii.order = NULL;
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   144
    slave->sii.name = NULL;
835
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   145
    memset(&slave->sii.coe_details, 0x00, sizeof(ec_sii_coe_details_t));
836
860a5bacea6a Display notLRW flag.
Florian Pose <fp@igh-essen.com>
parents: 835
diff changeset
   146
    memset(&slave->sii.general_flags, 0x00, sizeof(ec_sii_general_flags_t));
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   147
    slave->sii.current_on_ebus = 0;
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   148
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   149
    slave->sii.syncs = NULL;
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   150
    slave->sii.sync_count = 0;
835
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   151
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   152
    INIT_LIST_HEAD(&slave->sii.pdos);
835
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   153
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
   154
    INIT_LIST_HEAD(&slave->sdo_dictionary);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   155
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   156
    slave->sdo_dictionary_fetched = 0;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   157
    slave->jiffies_preop = 0;
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   158
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   159
    INIT_LIST_HEAD(&slave->sdo_requests);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   160
    INIT_LIST_HEAD(&slave->reg_requests);
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   161
    INIT_LIST_HEAD(&slave->foe_requests);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
   162
    INIT_LIST_HEAD(&slave->soe_requests);
2597
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   163
    INIT_LIST_HEAD(&slave->eoe_requests);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   164
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   165
    // create state machine object
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   166
    ec_fsm_slave_init(&slave->fsm, slave);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   167
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   168
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   169
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   170
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   171
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   172
   Slave destructor.
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   173
   Clears and frees a slave object.
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   174
*/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   175
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
   176
void ec_slave_clear(ec_slave_t *slave /**< EtherCAT slave */)
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   177
{
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   178
    ec_sdo_t *sdo, *next_sdo;
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
   179
    unsigned int i;
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
   180
    ec_pdo_t *pdo, *next_pdo;
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   181
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   182
    // abort all pending requests
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   183
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   184
    while (!list_empty(&slave->sdo_requests)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   185
        ec_sdo_request_t *request =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   186
            list_entry(slave->sdo_requests.next, ec_sdo_request_t, list);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   187
        list_del_init(&request->list); // dequeue
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   188
        EC_SLAVE_WARN(slave, "Discarding SDO request,"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   189
                " slave about to be deleted.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   190
        request->state = EC_INT_REQUEST_FAILURE;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   191
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   192
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   193
    while (!list_empty(&slave->reg_requests)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   194
        ec_reg_request_t *reg =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   195
            list_entry(slave->reg_requests.next, ec_reg_request_t, list);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   196
        list_del_init(&reg->list); // dequeue
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   197
        EC_SLAVE_WARN(slave, "Discarding register request,"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   198
                " slave about to be deleted.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   199
        reg->state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   200
    }
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   201
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   202
    while (!list_empty(&slave->foe_requests)) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   203
        ec_foe_request_t *request =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   204
            list_entry(slave->foe_requests.next, ec_foe_request_t, list);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   205
        list_del_init(&request->list); // dequeue
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   206
        EC_SLAVE_WARN(slave, "Discarding FoE request,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   207
                " slave about to be deleted.\n");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   208
        request->state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   209
    }
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   210
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   211
    while (!list_empty(&slave->soe_requests)) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   212
        ec_soe_request_t *request =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   213
            list_entry(slave->soe_requests.next, ec_soe_request_t, list);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   214
        list_del_init(&request->list); // dequeue
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   215
        EC_SLAVE_WARN(slave, "Discarding SoE request,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   216
                " slave about to be deleted.\n");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   217
        request->state = EC_INT_REQUEST_FAILURE;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   218
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   219
2597
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   220
    while (!list_empty(&slave->eoe_requests)) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   221
        ec_eoe_request_t *request =
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   222
            list_entry(slave->eoe_requests.next, ec_eoe_request_t, list);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   223
        list_del_init(&request->list); // dequeue
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   224
        EC_SLAVE_WARN(slave, "Discarding EoE request,"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   225
                " slave about to be deleted.\n");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   226
        request->state = EC_INT_REQUEST_FAILURE;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   227
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 2589
diff changeset
   228
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   229
    wake_up_all(&slave->master->request_queue);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   230
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   231
    if (slave->config) {
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
   232
        ec_slave_config_detach(slave->config);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   233
    }
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
   234
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   235
    // free all SDOs
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   236
    list_for_each_entry_safe(sdo, next_sdo, &slave->sdo_dictionary, list) {
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   237
        list_del(&sdo->list);
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
   238
        ec_sdo_clear(sdo);
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
   239
        kfree(sdo);
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
   240
    }
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   241
624
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   242
    // free all strings
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   243
    if (slave->sii.strings) {
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   244
        for (i = 0; i < slave->sii.string_count; i++)
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   245
            kfree(slave->sii.strings[i]);
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   246
        kfree(slave->sii.strings);
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   247
    }
121
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   248
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   249
    // free all sync managers
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   250
    ec_slave_clear_sync_managers(slave);
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   251
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   252
    // free all SII PDOs
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   253
    list_for_each_entry_safe(pdo, next_pdo, &slave->sii.pdos, list) {
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   254
        list_del(&pdo->list);
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents: 626
diff changeset
   255
        ec_pdo_clear(pdo);
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   256
        kfree(pdo);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   257
    }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   258
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   259
    if (slave->sii_words) {
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 967
diff changeset
   260
        kfree(slave->sii_words);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   261
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   262
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   263
    ec_fsm_slave_clear(&slave->fsm);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   264
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   265
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   266
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   267
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   268
/** Clear the sync manager array.
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   269
 */
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   270
void ec_slave_clear_sync_managers(ec_slave_t *slave /**< EtherCAT slave. */)
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   271
{
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   272
    unsigned int i;
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   273
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   274
    if (slave->sii.syncs) {
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   275
        for (i = 0; i < slave->sii.sync_count; i++) {
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   276
            ec_sync_clear(&slave->sii.syncs[i]);
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   277
        }
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   278
        kfree(slave->sii.syncs);
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   279
        slave->sii.syncs = NULL;
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   280
    }
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   281
}
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   282
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   283
/*****************************************************************************/
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   284
482
fbaaaf2a6234 Added clear function for SDO kobject.
Florian Pose <fp@igh-essen.com>
parents: 467
diff changeset
   285
/**
2600
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   286
 * Sets the data-link state of a slave.
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   287
 */
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   288
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   289
void ec_slave_set_dl_status(ec_slave_t *slave, /**< EtherCAT slave */
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   290
        uint16_t new_state /**< content of registers 0x0110-0x0111. */
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   291
        )
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   292
{
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   293
    unsigned int i;
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   294
    uint8_t state;
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   295
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   296
    for (i = 0; i < EC_MAX_PORTS; i++) {
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   297
        // link status
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   298
        state = new_state & (1 << (4 + i)) ? 1 : 0;
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   299
        if (slave->ports[i].link.link_up != state) {
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   300
            EC_SLAVE_DBG(slave, 1, "Port %u link status changed to %s.\n",
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   301
                    i, state ? "up" : "down");
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   302
            slave->ports[i].link.link_up = state;
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   303
        }
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   304
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   305
        // loop status
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   306
        state = new_state & (1 << (8 + i * 2)) ? 1 : 0;
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   307
        if (slave->ports[i].link.loop_closed != state) {
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   308
            EC_SLAVE_DBG(slave, 1, "Port %u loop status changed to %s.\n",
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   309
                    i, state ? "closed" : "open");
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   310
            slave->ports[i].link.loop_closed = state;
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   311
        }
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   312
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   313
        // signal detection
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   314
        state = new_state & (1 << (9 + i * 2)) ? 1 : 0;
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   315
        if (slave->ports[i].link.signal_detected != state) {
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   316
            EC_SLAVE_DBG(slave, 1, "Port %u signal status changed to %s.\n",
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   317
                    i, state ? "yes" : "no");
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   318
            slave->ports[i].link.signal_detected = state;
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   319
        }
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   320
    }
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   321
}
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   322
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   323
/*****************************************************************************/
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   324
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   325
/**
610
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   326
 * Sets the application state of a slave.
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   327
 */
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   328
2600
1a969896d52e Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents: 2597
diff changeset
   329
void ec_slave_set_al_status(ec_slave_t *slave, /**< EtherCAT slave */
610
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   330
        ec_slave_state_t new_state /**< new application state */
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   331
        )
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   332
{
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   333
    if (new_state != slave->current_state) {
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   334
        if (slave->master->debug_level) {
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   335
            char old_state[EC_STATE_STRING_SIZE],
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   336
                cur_state[EC_STATE_STRING_SIZE];
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   337
            ec_state_string(slave->current_state, old_state, 0);
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   338
            ec_state_string(new_state, cur_state, 0);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   339
            EC_SLAVE_DBG(slave, 0, "%s -> %s.\n", old_state, cur_state);
610
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   340
        }
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   341
        slave->current_state = new_state;
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   342
    }
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   343
}
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   344
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   345
/*****************************************************************************/
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   346
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 609
diff changeset
   347
/**
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   348
 * Request a slave state and resets the error flag.
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   349
 */
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   350
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 632
diff changeset
   351
void ec_slave_request_state(ec_slave_t *slave, /**< EtherCAT slave */
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   352
                            ec_slave_state_t state /**< new state */
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   353
                            )
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   354
{
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   355
    slave->requested_state = state;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   356
    slave->error_flag = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   357
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   358
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   359
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   360
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 423
diff changeset
   361
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   362
   Fetches data from a STRING category.
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   363
   \todo range checking
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   364
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   365
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   366
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   367
int ec_slave_fetch_sii_strings(
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   368
        ec_slave_t *slave, /**< EtherCAT slave */
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   369
        const uint8_t *data, /**< category data */
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   370
        size_t data_size /**< number of bytes */
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   371
        )
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   372
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   373
    int i, err;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   374
    size_t size;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   375
    off_t offset;
624
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   376
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   377
    slave->sii.string_count = data[0];
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   378
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   379
    if (slave->sii.string_count) {
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   380
        if (!(slave->sii.strings =
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   381
                    kmalloc(sizeof(char *) * slave->sii.string_count,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   382
                        GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   383
            EC_SLAVE_ERR(slave, "Failed to allocate string array memory.\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   384
            err = -ENOMEM;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   385
            goto out_zero;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   386
        }
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   387
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   388
        offset = 1;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   389
        for (i = 0; i < slave->sii.string_count; i++) {
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   390
            size = data[offset];
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   391
            // allocate memory for string structure and data at a single blow
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   392
            if (!(slave->sii.strings[i] =
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   393
                        kmalloc(sizeof(char) * size + 1, GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   394
                EC_SLAVE_ERR(slave, "Failed to allocate string memory.\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   395
                err = -ENOMEM;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   396
                goto out_free;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   397
            }
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   398
            memcpy(slave->sii.strings[i], data + offset + 1, size);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   399
            slave->sii.strings[i][size] = 0x00; // append binary zero
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   400
            offset += 1 + size;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   401
        }
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   402
    }
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   403
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   404
    return 0;
624
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   405
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   406
out_free:
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   407
    for (i--; i >= 0; i--)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   408
        kfree(slave->sii.strings[i]);
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   409
    kfree(slave->sii.strings);
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   410
    slave->sii.strings = NULL;
624
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   411
out_zero:
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   412
    slave->sii.string_count = 0;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   413
    return err;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   414
}
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   415
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   416
/*****************************************************************************/
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   417
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   418
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   419
   Fetches data from a GENERAL category.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   420
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   421
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   422
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   423
int ec_slave_fetch_sii_general(
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   424
        ec_slave_t *slave, /**< EtherCAT slave */
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   425
        const uint8_t *data, /**< category data */
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   426
        size_t data_size /**< size in bytes */
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   427
        )
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   428
{
190
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   429
    unsigned int i;
876
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   430
    uint8_t flags;
190
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   431
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   432
    if (data_size != 32) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   433
        EC_SLAVE_ERR(slave, "Wrong size of general category (%zu/32).\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   434
                data_size);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   435
        return -EINVAL;
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   436
    }
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   437
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   438
    slave->sii.group = ec_slave_sii_string(slave, data[0]);
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   439
    slave->sii.image = ec_slave_sii_string(slave, data[1]);
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   440
    slave->sii.order = ec_slave_sii_string(slave, data[2]);
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   441
    slave->sii.name = ec_slave_sii_string(slave, data[3]);
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   442
190
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   443
    for (i = 0; i < 4; i++)
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   444
        slave->sii.physical_layer[i] =
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   445
            (data[4] & (0x03 << (i * 2))) >> (i * 2);
499
fb005e975181 Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   446
876
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   447
    // read CoE details
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   448
    flags = EC_READ_U8(data + 5);
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   449
    slave->sii.coe_details.enable_sdo =                 (flags >> 0) & 0x01;
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   450
    slave->sii.coe_details.enable_sdo_info =            (flags >> 1) & 0x01;
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   451
    slave->sii.coe_details.enable_pdo_assign =          (flags >> 2) & 0x01;
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   452
    slave->sii.coe_details.enable_pdo_configuration =   (flags >> 3) & 0x01;
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   453
    slave->sii.coe_details.enable_upload_at_startup =   (flags >> 4) & 0x01;
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   454
    slave->sii.coe_details.enable_sdo_complete_access = (flags >> 5) & 0x01;
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   455
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   456
    // read general flags
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   457
    flags = EC_READ_U8(data + 0x000B);
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   458
    slave->sii.general_flags.enable_safeop =  (flags >> 0) & 0x01;
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   459
    slave->sii.general_flags.enable_not_lrw = (flags >> 1) & 0x01;
8acdecb5a75e Fixed general flags on big-endian archs.
Florian Pose <fp@igh-essen.com>
parents: 873
diff changeset
   460
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   461
    slave->sii.current_on_ebus = EC_READ_S16(data + 0x0C);
835
23fd8b510803 Evaluate CoE details from general category; moved current consumption
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   462
    slave->sii.has_general = 1;
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   463
    return 0;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   464
}
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   465
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   466
/*****************************************************************************/
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   467
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   468
/** Fetches data from a SYNC MANAGER category.
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   469
 *
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   470
 * Appends the sync managers described in the category to the existing ones.
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   471
 *
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   472
 * \return 0 in case of success, else < 0
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   473
 */
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   474
int ec_slave_fetch_sii_syncs(
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   475
        ec_slave_t *slave, /**< EtherCAT slave. */
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   476
        const uint8_t *data, /**< Category data. */
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   477
        size_t data_size /**< Number of bytes. */
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   478
        )
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   479
{
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   480
    unsigned int i, count, total_count;
626
a5e838c30733 Renamed ec_sii_sync_t to ec_sync_t.
Florian Pose <fp@igh-essen.com>
parents: 625
diff changeset
   481
    ec_sync_t *sync;
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   482
    size_t memsize;
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   483
    ec_sync_t *syncs;
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   484
    uint8_t index;
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   485
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   486
    // one sync manager struct is 4 words long
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   487
    if (data_size % 8) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   488
        EC_SLAVE_ERR(slave, "Invalid SII sync manager category size %zu.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   489
                data_size);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   490
        return -EINVAL;
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   491
    }
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   492
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   493
    count = data_size / 8;
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   494
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   495
    if (count) {
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   496
        total_count = count + slave->sii.sync_count;
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
   497
        if (total_count > EC_MAX_SYNC_MANAGERS) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   498
            EC_SLAVE_ERR(slave, "Exceeded maximum number of"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   499
                    " sync managers!\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   500
            return -EOVERFLOW;
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   501
        }
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   502
        memsize = sizeof(ec_sync_t) * total_count;
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   503
        if (!(syncs = kmalloc(memsize, GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   504
            EC_SLAVE_ERR(slave, "Failed to allocate %zu bytes"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   505
                    " for sync managers.\n", memsize);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   506
            return -ENOMEM;
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   507
        }
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   508
873
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   509
        for (i = 0; i < slave->sii.sync_count; i++)
ec01ba291896 Fixed bug in copying sync managers. Now making a deep copy.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   510
            ec_sync_init_copy(syncs + i, slave->sii.syncs + i);
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   511
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   512
        // initialize new sync managers
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   513
        for (i = 0; i < count; i++, data += 8) {
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   514
            index = i + slave->sii.sync_count;
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   515
            sync = &syncs[index];
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   516
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   517
            ec_sync_init(sync, slave);
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   518
            sync->physical_start_address = EC_READ_U16(data);
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   519
            sync->default_length = EC_READ_U16(data + 2);
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   520
            sync->control_register = EC_READ_U8(data + 4);
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   521
            sync->enable = EC_READ_U8(data + 6);
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   522
        }
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   523
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   524
        if (slave->sii.syncs)
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   525
            kfree(slave->sii.syncs);
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   526
        slave->sii.syncs = syncs;
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   527
        slave->sii.sync_count = total_count;
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   528
    }
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 865
diff changeset
   529
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   530
    return 0;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   531
}
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   532
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   533
/*****************************************************************************/
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   534
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   535
/**
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   536
   Fetches data from a [RT]xPDO category.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   537
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   538
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   539
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   540
int ec_slave_fetch_sii_pdos(
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   541
        ec_slave_t *slave, /**< EtherCAT slave */
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   542
        const uint8_t *data, /**< category data */
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   543
        size_t data_size, /**< number of bytes */
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   544
        ec_direction_t dir /**< PDO direction. */
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   545
        )
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   546
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   547
    int ret;
625
ec69acbbd156 Renamed ec_sii_pdo_t and ec_sii_pdo_entry_t to ec_pdo_t and
Florian Pose <fp@igh-essen.com>
parents: 624
diff changeset
   548
    ec_pdo_t *pdo;
ec69acbbd156 Renamed ec_sii_pdo_t and ec_sii_pdo_entry_t to ec_pdo_t and
Florian Pose <fp@igh-essen.com>
parents: 624
diff changeset
   549
    ec_pdo_entry_t *entry;
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   550
    unsigned int entry_count, i;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   551
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   552
    while (data_size >= 8) {
625
ec69acbbd156 Renamed ec_sii_pdo_t and ec_sii_pdo_entry_t to ec_pdo_t and
Florian Pose <fp@igh-essen.com>
parents: 624
diff changeset
   553
        if (!(pdo = kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   554
            EC_SLAVE_ERR(slave, "Failed to allocate PDO memory.\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   555
            return -ENOMEM;
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   556
        }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   557
627
4793ca94f082 Layed out PDO structures to own files.
Florian Pose <fp@igh-essen.com>
parents: 626
diff changeset
   558
        ec_pdo_init(pdo);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 320
diff changeset
   559
        pdo->index = EC_READ_U16(data);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 320
diff changeset
   560
        entry_count = EC_READ_U8(data + 2);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 320
diff changeset
   561
        pdo->sync_index = EC_READ_U8(data + 3);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   562
        ret = ec_pdo_set_name(pdo,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   563
                ec_slave_sii_string(slave, EC_READ_U8(data + 5)));
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   564
        if (ret) {
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
   565
            ec_pdo_clear(pdo);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
   566
            kfree(pdo);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   567
            return ret;
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
   568
        }
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   569
        list_add_tail(&pdo->list, &slave->sii.pdos);
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   570
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   571
        data_size -= 8;
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   572
        data += 8;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   573
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   574
        for (i = 0; i < entry_count; i++) {
625
ec69acbbd156 Renamed ec_sii_pdo_t and ec_sii_pdo_entry_t to ec_pdo_t and
Florian Pose <fp@igh-essen.com>
parents: 624
diff changeset
   575
            if (!(entry = kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   576
                EC_SLAVE_ERR(slave, "Failed to allocate PDO entry memory.\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   577
                return -ENOMEM;
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   578
            }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   579
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
   580
            ec_pdo_entry_init(entry);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 320
diff changeset
   581
            entry->index = EC_READ_U16(data);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 320
diff changeset
   582
            entry->subindex = EC_READ_U8(data + 2);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   583
            ret = ec_pdo_entry_set_name(entry,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   584
                    ec_slave_sii_string(slave, EC_READ_U8(data + 3)));
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   585
            if (ret) {
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
   586
                ec_pdo_entry_clear(entry);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
   587
                kfree(entry);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   588
                return ret;
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
   589
            }
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 320
diff changeset
   590
            entry->bit_length = EC_READ_U8(data + 5);
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   591
            list_add_tail(&entry->list, &pdo->entries);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   592
742
03d2fe3d4a93 Improved checking of EEPROM data while reading.
Florian Pose <fp@igh-essen.com>
parents: 741
diff changeset
   593
            data_size -= 8;
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   594
            data += 8;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   595
        }
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 632
diff changeset
   596
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   597
        // if sync manager index is positive, the PDO is mapped by default
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 632
diff changeset
   598
        if (pdo->sync_index >= 0) {
762
15214036c72a Store PDO mapping source in sync manager.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   599
            ec_sync_t *sync;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 632
diff changeset
   600
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   601
            if (!(sync = ec_slave_get_sync(slave, pdo->sync_index))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   602
                EC_SLAVE_ERR(slave, "Invalid SM index %i for PDO 0x%04X.",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   603
                        pdo->sync_index, pdo->index);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   604
                return -ENOENT;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 632
diff changeset
   605
            }
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 632
diff changeset
   606
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   607
            ret = ec_pdo_list_add_pdo_copy(&sync->pdos, pdo);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   608
            if (ret)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   609
                return ret;
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 632
diff changeset
   610
        }
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   611
    }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   612
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   613
    return 0;
114
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   614
}
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   615
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   616
/*****************************************************************************/
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   617
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   618
/**
784
0a0994fdafb8 Esthetic surgery for slave.
Florian Pose <fp@igh-essen.com>
parents: 772
diff changeset
   619
   Searches the string list for an index.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   620
   \return 0 in case of success, else < 0
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   621
*/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   622
624
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   623
char *ec_slave_sii_string(
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   624
        ec_slave_t *slave, /**< EtherCAT slave */
624
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   625
        unsigned int index /**< string index */
620
4f76acbf54a0 Renamed SII fetching functions (non-functional).
Florian Pose <fp@igh-essen.com>
parents: 619
diff changeset
   626
        )
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   627
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   628
    if (!index--)
624
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   629
        return NULL;
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   630
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   631
    if (index >= slave->sii.string_count) {
1924
2917b262554b Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   632
        EC_SLAVE_DBG(slave, 1, "String %u not found.\n", index);
624
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   633
        return NULL;
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   634
    }
11332ad89f47 Simplified handling of EEPROM strings.
Florian Pose <fp@igh-essen.com>
parents: 620
diff changeset
   635
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   636
    return slave->sii.strings[index];
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   637
}
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   638
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   639
/*****************************************************************************/
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   640
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   641
/** Get the sync manager given an index.
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   642
 *
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 754
diff changeset
   643
 * \return pointer to sync manager, or NULL.
619
15becb1879fd Introduced ec_slave_get_pdo_sync().
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   644
 */
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   645
ec_sync_t *ec_slave_get_sync(
912
6630f4dbcfd2 Improved working counter output; fixed problem with slaves that have a single sync manager used for outputs.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   646
        ec_slave_t *slave, /**< EtherCAT slave. */
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   647
        uint8_t sync_index /**< Sync manager index. */
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   648
        )
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   649
{
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   650
    if (sync_index < slave->sii.sync_count) {
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   651
        return &slave->sii.syncs[sync_index];
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   652
    } else {
635
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 632
diff changeset
   653
        return NULL;
d304ef4af542 Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents: 632
diff changeset
   654
    }
619
15becb1879fd Introduced ec_slave_get_pdo_sync().
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   655
}
15becb1879fd Introduced ec_slave_get_pdo_sync().
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   656
15becb1879fd Introduced ec_slave_get_pdo_sync().
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   657
/*****************************************************************************/
15becb1879fd Introduced ec_slave_get_pdo_sync().
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   658
15becb1879fd Introduced ec_slave_get_pdo_sync().
Florian Pose <fp@igh-essen.com>
parents: 618
diff changeset
   659
/**
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   660
   Counts the total number of SDOs and entries in the dictionary.
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   661
*/
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   662
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   663
void ec_slave_sdo_dict_info(const 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
   664
                            unsigned int *sdo_count, /**< number of SDOs */
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   665
                            unsigned int *entry_count /**< total number of
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   666
                                                         entries */
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   667
                            )
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   668
{
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   669
    unsigned int sdos = 0, entries = 0;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   670
    ec_sdo_t *sdo;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   671
    ec_sdo_entry_t *entry;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   672
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   673
    list_for_each_entry(sdo, &slave->sdo_dictionary, list) {
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   674
        sdos++;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   675
        list_for_each_entry(entry, &sdo->entries, list) {
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   676
            entries++;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   677
        }
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   678
    }
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   679
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   680
    *sdo_count = sdos;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   681
    *entry_count = entries;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   682
}
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 421
diff changeset
   683
740
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   684
/*****************************************************************************/
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   685
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   686
/**
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   687
 * Get an SDO from the dictionary.
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   688
 * \returns The desired SDO, or NULL.
740
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   689
 */
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   690
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   691
ec_sdo_t *ec_slave_get_sdo(
964
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   692
        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
   693
        uint16_t index /**< SDO index */
740
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   694
        )
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   695
{
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   696
    ec_sdo_t *sdo;
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   697
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   698
    list_for_each_entry(sdo, &slave->sdo_dictionary, list) {
967
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   699
        if (sdo->index != index)
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   700
            continue;
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   701
        return sdo;
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   702
    }
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   703
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   704
    return NULL;
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   705
}
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   706
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   707
/*****************************************************************************/
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   708
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   709
/**
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   710
 * Get an SDO from the dictionary.
967
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   711
 *
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   712
 * const version.
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   713
 *
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   714
 * \returns The desired SDO, or NULL.
967
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   715
 */
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   716
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   717
const ec_sdo_t *ec_slave_get_sdo_const(
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   718
        const 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
   719
        uint16_t index /**< SDO index */
967
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   720
        )
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   721
{
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   722
    const ec_sdo_t *sdo;
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   723
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   724
    list_for_each_entry(sdo, &slave->sdo_dictionary, list) {
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   725
        if (sdo->index != index)
93807963b906 Added ec_slave_get_sdo_const().
Florian Pose <fp@igh-essen.com>
parents: 964
diff changeset
   726
            continue;
740
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   727
        return sdo;
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   728
    }
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   729
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   730
    return NULL;
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   731
}
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 735
diff changeset
   732
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 784
diff changeset
   733
/*****************************************************************************/
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   734
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   735
/** Get an SDO from the dictionary, given its position in the list.
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   736
 * \returns The desired SDO, or NULL.
964
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   737
 */
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   738
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   739
const ec_sdo_t *ec_slave_get_sdo_by_pos_const(
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   740
        const 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
   741
        uint16_t sdo_position /**< SDO list position. */
964
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   742
        )
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   743
{
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   744
    const ec_sdo_t *sdo;
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   745
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   746
    list_for_each_entry(sdo, &slave->sdo_dictionary, list) {
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   747
        if (sdo_position--)
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   748
            continue;
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   749
        return sdo;
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   750
    }
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   751
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   752
    return NULL;
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   753
}
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   754
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   755
/*****************************************************************************/
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   756
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   757
/** Get the number of SDOs in the dictionary.
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   758
 * \returns SDO count.
964
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   759
 */
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   760
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   761
uint16_t ec_slave_sdo_count(
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   762
        const ec_slave_t *slave /**< EtherCAT slave. */
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   763
        )
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   764
{
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   765
    const ec_sdo_t *sdo;
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   766
    uint16_t count = 0;
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   767
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   768
    list_for_each_entry(sdo, &slave->sdo_dictionary, list) {
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   769
        count++;
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   770
    }
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   771
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   772
    return count;
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   773
}
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   774
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   775
/*****************************************************************************/
957f21465052 Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   776
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   777
/** Finds a mapped PDO.
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   778
 * \returns The desired PDO object, or NULL.
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   779
 */
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   780
const ec_pdo_t *ec_slave_find_pdo(
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   781
        const ec_slave_t *slave, /**< Slave. */
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   782
        uint16_t index /**< PDO index to find. */
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   783
        )
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   784
{
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   785
    unsigned int i;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   786
    const ec_sync_t *sync;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   787
    const ec_pdo_t *pdo;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   788
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   789
    for (i = 0; i < slave->sii.sync_count; i++) {
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   790
        sync = &slave->sii.syncs[i];
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   791
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 876
diff changeset
   792
        if (!(pdo = ec_pdo_list_find_pdo_const(&sync->pdos, index)))
799
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   793
            continue;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   794
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   795
        return pdo;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   796
    }
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   797
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   798
    return NULL;
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   799
}
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   800
068a58b96965 Pdo configuration.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   801
/*****************************************************************************/
1186
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   802
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   803
/** Find name for a PDO and its entries.
1186
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   804
 */
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   805
void ec_slave_find_names_for_pdo(
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   806
        ec_slave_t *slave,
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   807
        ec_pdo_t *pdo
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   808
        )
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   809
{
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   810
    const ec_sdo_t *sdo;
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   811
    ec_pdo_entry_t *pdo_entry;
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   812
    const ec_sdo_entry_t *sdo_entry;
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   813
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   814
    list_for_each_entry(sdo, &slave->sdo_dictionary, list) {
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   815
        if (sdo->index == pdo->index) {
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   816
            ec_pdo_set_name(pdo, sdo->name);
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   817
        } else {
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   818
            list_for_each_entry(pdo_entry, &pdo->entries, list) {
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   819
                if (sdo->index == pdo_entry->index) {
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   820
                    sdo_entry = ec_sdo_get_entry_const(
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   821
                            sdo, pdo_entry->subindex);
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   822
                    if (sdo_entry) {
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   823
                        ec_pdo_entry_set_name(pdo_entry,
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   824
                                sdo_entry->description);
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   825
                    }
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   826
                }
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   827
            }
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   828
        }
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   829
    }
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   830
}
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   831
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   832
/*****************************************************************************/
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   833
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   834
/** Attach PDO names.
1186
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   835
 */
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   836
void ec_slave_attach_pdo_names(
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   837
        ec_slave_t *slave
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   838
        )
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   839
{
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   840
    unsigned int i;
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   841
    ec_sync_t *sync;
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   842
    ec_pdo_t *pdo;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   843
1186
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   844
    for (i = 0; i < slave->sii.sync_count; i++) {
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   845
        sync = slave->sii.syncs + i;
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   846
        list_for_each_entry(pdo, &sync->pdos.list, list) {
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   847
            ec_slave_find_names_for_pdo(slave, pdo);
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   848
        }
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   849
    }
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   850
}
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   851
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   852
/*****************************************************************************/
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   853
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   854
/** Returns the previous connected port of a given port.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   855
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   856
 * \return Port index.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   857
 */
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   858
unsigned int ec_slave_get_previous_port(
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   859
        ec_slave_t *slave, /**< EtherCAT slave. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   860
        unsigned int port_index /**< Port index. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   861
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   862
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   863
    static const unsigned int prev_table[EC_MAX_PORTS] = {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   864
        2, 3, 1, 0
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   865
    };
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   866
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   867
    if (port_index >= EC_MAX_PORTS) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   868
        EC_SLAVE_WARN(slave, "%s(port_index=%u): Invalid port index!\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   869
                __func__, port_index);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   870
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   871
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   872
    do {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   873
        port_index = prev_table[port_index];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   874
        if (slave->ports[port_index].next_slave) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   875
            return port_index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   876
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   877
    } while (port_index);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   878
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   879
    return 0;
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   880
}
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   881
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   882
/*****************************************************************************/
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   883
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   884
/** Returns the next connected port of a given port.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   885
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   886
 * \return Port index.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   887
 */
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   888
unsigned int ec_slave_get_next_port(
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   889
        ec_slave_t *slave, /**< EtherCAT slave. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   890
        unsigned int port_index /**< Port index. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   891
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   892
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   893
    static const unsigned int next_table[EC_MAX_PORTS] = {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   894
        3, 2, 0, 1
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   895
    };
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   896
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   897
    if (port_index >= EC_MAX_PORTS) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   898
        EC_SLAVE_WARN(slave, "%s(port_index=%u): Invalid port index!\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   899
                __func__, port_index);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   900
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   901
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   902
    do {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   903
        port_index = next_table[port_index];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   904
        if (slave->ports[port_index].next_slave) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   905
            return port_index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   906
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   907
    } while (port_index);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   908
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   909
    return 0;
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   910
}
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   911
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   912
/*****************************************************************************/
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   913
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   914
/** Calculates the sum of round-trip-times of connected ports 1-3.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   915
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   916
 * \return Round-trip-time in ns.
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   917
 */
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   918
uint32_t ec_slave_calc_rtt_sum(
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   919
        ec_slave_t *slave /**< EtherCAT slave. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
   920
        )
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   921
{
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   922
    uint32_t rtt_sum = 0, rtt;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   923
    unsigned int port_index = ec_slave_get_next_port(slave, 0);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   924
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   925
    while (port_index != 0) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   926
        unsigned int prev_index =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   927
            ec_slave_get_previous_port(slave, port_index);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   928
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   929
        rtt = slave->ports[port_index].receive_time -
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   930
            slave->ports[prev_index].receive_time;
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   931
        rtt_sum += rtt;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   932
        port_index = ec_slave_get_next_port(slave, port_index);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   933
    }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   934
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   935
    return rtt_sum;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   936
}
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   937
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   938
/*****************************************************************************/
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   939
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   940
/** Finds the next slave supporting DC delay measurement.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   941
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   942
 * \return Next DC slave, or NULL.
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   943
 */
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   944
ec_slave_t *ec_slave_find_next_dc_slave(
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   945
        ec_slave_t *slave /**< EtherCAT slave. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
   946
        )
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   947
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   948
    unsigned int port_index;
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   949
    ec_slave_t *dc_slave = NULL;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   950
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   951
    if (slave->base_dc_supported) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   952
        dc_slave = slave;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   953
    } else {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   954
        port_index = ec_slave_get_next_port(slave, 0);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   955
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   956
        while (port_index != 0) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   957
            ec_slave_t *next = slave->ports[port_index].next_slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   958
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   959
            if (next) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   960
                dc_slave = ec_slave_find_next_dc_slave(next);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   961
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   962
                if (dc_slave) {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   963
                    break;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   964
                }
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   965
            }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   966
            port_index = ec_slave_get_next_port(slave, port_index);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   967
        }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   968
    }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   969
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   970
    return dc_slave;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   971
}
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   972
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   973
/*****************************************************************************/
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   974
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
   975
/** Calculates the port transmission delays.
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   976
 */
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   977
void ec_slave_calc_port_delays(
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   978
        ec_slave_t *slave /**< EtherCAT slave. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
   979
        )
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   980
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   981
    unsigned int port_index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   982
    ec_slave_t *next_slave, *next_dc;
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   983
    uint32_t rtt, next_rtt_sum;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   984
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   985
    if (!slave->base_dc_supported)
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   986
        return;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   987
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   988
    port_index = ec_slave_get_next_port(slave, 0);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   989
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   990
    while (port_index != 0) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   991
        next_slave = slave->ports[port_index].next_slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   992
        next_dc = ec_slave_find_next_dc_slave(next_slave);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   993
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
   994
        if (next_dc) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   995
            unsigned int prev_port =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   996
                ec_slave_get_previous_port(slave, port_index);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   997
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   998
            rtt = slave->ports[port_index].receive_time -
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   999
                slave->ports[prev_port].receive_time;
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1000
            next_rtt_sum = ec_slave_calc_rtt_sum(next_dc);
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1001
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1002
            slave->ports[port_index].delay_to_next_dc =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1003
                (rtt - next_rtt_sum) / 2; // FIXME
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1004
            next_dc->ports[0].delay_to_next_dc =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1005
                (rtt - next_rtt_sum) / 2;
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1006
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1007
#if 0
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1008
            EC_SLAVE_DBG(slave, 1, "delay %u:%u rtt=%u"
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1009
                    " next_rtt_sum=%u delay=%u\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1010
                    slave->ring_position, port_index, rtt, next_rtt_sum,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1011
                    slave->ports[port_index].delay_to_next_dc);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1012
#endif
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1013
        }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1014
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1015
        port_index = ec_slave_get_next_port(slave, port_index);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1016
    }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1017
}
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1018
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1019
/*****************************************************************************/
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1020
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  1021
/** Recursively calculates transmission delays.
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  1022
 */
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  1023
void ec_slave_calc_transmission_delays_rec(
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1024
        ec_slave_t *slave, /**< Current slave. */
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1025
        uint32_t *delay /**< Sum of delays. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  1026
        )
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1027
{
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1028
    unsigned int i;
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1029
    ec_slave_t *next_dc;
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1030
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1031
    EC_SLAVE_DBG(slave, 1, "%s(delay = %u ns)\n", __func__, *delay);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1032
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  1033
    slave->transmission_delay = *delay;
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1034
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1035
    i = ec_slave_get_next_port(slave, 0);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1036
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1037
    while (i != 0) {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1038
        ec_slave_port_t *port = &slave->ports[i];
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1039
        next_dc = ec_slave_find_next_dc_slave(port->next_slave);
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1040
        if (next_dc) {
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1041
            *delay = *delay + port->delay_to_next_dc;
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1042
#if 0
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1043
            EC_SLAVE_DBG(slave, 1, "%u:%u %u\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1044
                    slave->ring_position, i, *delay);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1045
#endif
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1046
            ec_slave_calc_transmission_delays_rec(next_dc, delay);
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1924
diff changeset
  1047
        }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1048
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1049
        i = ec_slave_get_next_port(slave, i);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1050
    }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1051
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1052
    *delay = *delay + slave->ports[0].delay_to_next_dc;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1053
}
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1054
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  1055
/*****************************************************************************/