master/slave.c
author Florian Pose <fp@igh-essen.com>
Fri, 26 May 2006 14:28:49 +0000
changeset 261 44a3a5833c49
parent 260 5fe7df7f2433
child 264 76cba93ba122
permissions -rw-r--r--
Better state-dependent behaviour for EoE-capable slaves.
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
 *
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
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
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    12
 *  License, or (at your option) any later version.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    13
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    17
 *  GNU General Public License for more details.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    18
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *  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
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    31
 *
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 26
diff changeset
    32
 *****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
199
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
   \file
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    36
   EtherCAT slave methods.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    37
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    38
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    39
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    40
24
d417dd9bdc2f Wilhelms ?nderungen ?bernommen.
Florian Pose <fp@igh-essen.com>
parents: 23
diff changeset
    41
#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
    42
#include <linux/delay.h>
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    44
#include "globals.h"
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    45
#include "slave.h"
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    46
#include "command.h"
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    47
#include "master.h"
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 26
diff changeset
    49
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    51
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
    52
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    53
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    54
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
    55
int ec_slave_fetch_categories(ec_slave_t *);
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    56
ssize_t ec_show_slave_attribute(struct kobject *, struct attribute *, char *);
256
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
    57
ssize_t ec_store_slave_attribute(struct kobject *, struct attribute *,
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
    58
                                 const char *, size_t);
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    59
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    60
/*****************************************************************************/
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    61
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    62
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    63
184
2fc86cec12df Macro for SysFS attribute definition
Florian Pose <fp@igh-essen.com>
parents: 183
diff changeset
    64
EC_SYSFS_READ_ATTR(ring_position);
188
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 185
diff changeset
    65
EC_SYSFS_READ_ATTR(coupler_address);
184
2fc86cec12df Macro for SysFS attribute definition
Florian Pose <fp@igh-essen.com>
parents: 183
diff changeset
    66
EC_SYSFS_READ_ATTR(vendor_name);
2fc86cec12df Macro for SysFS attribute definition
Florian Pose <fp@igh-essen.com>
parents: 183
diff changeset
    67
EC_SYSFS_READ_ATTR(product_name);
2fc86cec12df Macro for SysFS attribute definition
Florian Pose <fp@igh-essen.com>
parents: 183
diff changeset
    68
EC_SYSFS_READ_ATTR(product_desc);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    69
EC_SYSFS_READ_ATTR(sii_desc);
185
af570302dcee Slave (special) type in SysFS
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
    70
EC_SYSFS_READ_ATTR(type);
256
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
    71
EC_SYSFS_READ_WRITE_ATTR(state);
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    72
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    73
static struct attribute *def_attrs[] = {
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    74
    &attr_ring_position,
188
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 185
diff changeset
    75
    &attr_coupler_address,
183
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
    76
    &attr_vendor_name,
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
    77
    &attr_product_name,
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
    78
    &attr_product_desc,
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    79
    &attr_sii_desc,
185
af570302dcee Slave (special) type in SysFS
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
    80
    &attr_type,
256
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
    81
    &attr_state,
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    82
    NULL,
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    83
};
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    84
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    85
static struct sysfs_ops sysfs_ops = {
256
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
    86
    .show = ec_show_slave_attribute,
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
    87
    .store = ec_store_slave_attribute
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    88
};
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    89
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    90
static struct kobj_type ktype_ec_slave = {
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    91
    .release = ec_slave_clear,
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    92
    .sysfs_ops = &sysfs_ops,
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    93
    .default_attrs = def_attrs
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    94
};
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
    95
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    96
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    97
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
    98
/*****************************************************************************/
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
    99
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   101
   Slave constructor.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   102
   \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
   103
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   104
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   105
int ec_slave_init(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   106
                  ec_master_t *master, /**< EtherCAT master */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   107
                  uint16_t ring_position, /**< ring position */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   108
                  uint16_t station_address /**< station address to configure */
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   109
                  )
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   110
{
142
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   111
    unsigned int i;
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   112
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   113
    slave->ring_position = ring_position;
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   114
    slave->station_address = station_address;
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   115
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   116
    // init kobject and add it to the hierarchy
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   117
    memset(&slave->kobj, 0x00, sizeof(struct kobject));
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   118
    kobject_init(&slave->kobj);
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   119
    slave->kobj.ktype = &ktype_ec_slave;
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   120
    slave->kobj.parent = &master->kobj;
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   121
    if (kobject_set_name(&slave->kobj, "slave%03i", slave->ring_position)) {
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   122
        EC_ERR("Failed to set kobject name.\n");
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   123
        kobject_put(&slave->kobj);
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   124
        return -1;
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   125
    }
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   126
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   127
    slave->master = master;
188
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 185
diff changeset
   128
    slave->coupler_index = 0;
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 185
diff changeset
   129
    slave->coupler_subindex = 0xFFFF;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   130
    slave->base_type = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   131
    slave->base_revision = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   132
    slave->base_build = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   133
    slave->base_fmmu_count = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   134
    slave->base_sync_count = 0;
114
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   135
    slave->sii_alias = 0;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   136
    slave->sii_vendor_id = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   137
    slave->sii_product_code = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   138
    slave->sii_revision_number = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   139
    slave->sii_serial_number = 0;
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   140
    slave->sii_rx_mailbox_offset = 0;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   141
    slave->sii_rx_mailbox_size = 0;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   142
    slave->sii_tx_mailbox_offset = 0;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   143
    slave->sii_tx_mailbox_size = 0;
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 132
diff changeset
   144
    slave->sii_mailbox_protocols = 0;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   145
    slave->type = NULL;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   146
    slave->registered = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   147
    slave->fmmu_count = 0;
121
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   148
    slave->eeprom_name = NULL;
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   149
    slave->eeprom_group = NULL;
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   150
    slave->eeprom_desc = NULL;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   151
    slave->requested_state = EC_SLAVE_STATE_UNKNOWN;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   152
    slave->current_state = EC_SLAVE_STATE_UNKNOWN;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   153
    slave->state_error = 0;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   154
    slave->online = 1;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   155
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   156
    ec_command_init(&slave->mbox_command);
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   157
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   158
    INIT_LIST_HEAD(&slave->eeprom_strings);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   159
    INIT_LIST_HEAD(&slave->eeprom_syncs);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   160
    INIT_LIST_HEAD(&slave->eeprom_pdos);
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
   161
    INIT_LIST_HEAD(&slave->sdo_dictionary);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   162
183
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
   163
    for (i = 0; i < 4; i++) {
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
   164
        slave->dl_link[i] = 0;
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
   165
        slave->dl_loop[i] = 0;
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
   166
        slave->dl_signal[i] = 0;
190
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   167
        slave->sii_physical_layer[i] = 0xFF;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   168
    }
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   169
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   170
    return 0;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   171
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   172
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   173
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   174
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   175
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   176
   Slave destructor.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   177
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   178
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   179
void ec_slave_clear(struct kobject *kobj /**< kobject of the slave */)
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   180
{
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   181
    ec_slave_t *slave;
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   182
    ec_eeprom_string_t *string, *next_str;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   183
    ec_eeprom_sync_t *sync, *next_sync;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   184
    ec_eeprom_pdo_t *pdo, *next_pdo;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   185
    ec_eeprom_pdo_entry_t *entry, *next_ent;
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
   186
    ec_sdo_t *sdo, *next_sdo;
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
   187
    ec_sdo_entry_t *en, *next_en;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   188
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   189
    slave = container_of(kobj, ec_slave_t, kobj);
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   190
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   191
    // free all string objects
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   192
    list_for_each_entry_safe(string, next_str, &slave->eeprom_strings, list) {
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   193
        list_del(&string->list);
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   194
        kfree(string);
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   195
    }
121
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   196
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   197
    // free all sync managers
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   198
    list_for_each_entry_safe(sync, next_sync, &slave->eeprom_syncs, list) {
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   199
        list_del(&sync->list);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   200
        kfree(sync);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   201
    }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   202
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   203
    // free all PDOs
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   204
    list_for_each_entry_safe(pdo, next_pdo, &slave->eeprom_pdos, list) {
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   205
        list_del(&pdo->list);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   206
        if (pdo->name) kfree(pdo->name);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   207
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   208
        // free all PDO entries
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   209
        list_for_each_entry_safe(entry, next_ent, &pdo->entries, list) {
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   210
            list_del(&entry->list);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   211
            if (entry->name) kfree(entry->name);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   212
            kfree(entry);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   213
        }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   214
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   215
        kfree(pdo);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   216
    }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   217
121
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   218
    if (slave->eeprom_name) kfree(slave->eeprom_name);
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   219
    if (slave->eeprom_group) kfree(slave->eeprom_group);
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   220
    if (slave->eeprom_desc) kfree(slave->eeprom_desc);
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
   221
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   222
    // free all SDOs
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
   223
    list_for_each_entry_safe(sdo, next_sdo, &slave->sdo_dictionary, list) {
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
   224
        list_del(&sdo->list);
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
   225
        if (sdo->name) kfree(sdo->name);
161
ddb7266d1c56 Bugfix: Discovered memory leak.
Florian Pose <fp@igh-essen.com>
parents: 160
diff changeset
   226
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   227
        // free all SDO entries
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   228
        list_for_each_entry_safe(en, next_en, &sdo->entries, list) {
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   229
            list_del(&en->list);
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   230
            kfree(en);
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   231
        }
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
   232
        kfree(sdo);
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
   233
    }
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   234
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   235
    ec_command_clear(&slave->mbox_command);
121
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   236
}
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   237
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   238
/*****************************************************************************/
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   239
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   240
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   241
   Reads all necessary information from a slave.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   242
   \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
   243
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   244
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   245
int ec_slave_fetch(ec_slave_t *slave /**< EtherCAT slave */)
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   246
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   247
    ec_command_t *command;
142
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   248
    unsigned int i;
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   249
    uint16_t dl_status;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   250
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   251
    command = &slave->master->simple_command;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   252
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   253
    // read base data
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   254
    if (ec_command_nprd(command, slave->station_address, 0x0000, 6)) return -1;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   255
    if (unlikely(ec_master_simple_io(slave->master, command))) {
142
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   256
        EC_ERR("Reading base data from slave %i failed!\n",
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   257
               slave->ring_position);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   258
        return -1;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   259
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   260
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   261
    slave->base_type =       EC_READ_U8 (command->data);
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   262
    slave->base_revision =   EC_READ_U8 (command->data + 1);
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   263
    slave->base_build =      EC_READ_U16(command->data + 2);
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   264
    slave->base_fmmu_count = EC_READ_U8 (command->data + 4);
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   265
    slave->base_sync_count = EC_READ_U8 (command->data + 5);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   266
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   267
    if (slave->base_fmmu_count > EC_MAX_FMMUS)
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   268
        slave->base_fmmu_count = EC_MAX_FMMUS;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   269
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   270
    // read data link status
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   271
    if (ec_command_nprd(command, slave->station_address, 0x0110, 2)) return -1;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   272
    if (unlikely(ec_master_simple_io(slave->master, command))) {
142
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   273
        EC_ERR("Reading DL status from slave %i failed!\n",
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   274
               slave->ring_position);
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   275
        return -1;
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   276
    }
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   277
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   278
    dl_status = EC_READ_U16(command->data);
183
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
   279
    for (i = 0; i < 4; i++) {
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
   280
        slave->dl_link[i] = dl_status & (1 << (4 + i)) ? 1 : 0;
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
   281
        slave->dl_loop[i] = dl_status & (1 << (8 + i * 2)) ? 1 : 0;
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
   282
        slave->dl_signal[i] = dl_status & (1 << (9 + i * 2)) ? 1 : 0;
142
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   283
    }
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   284
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   285
    // read EEPROM data
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   286
    if (ec_slave_sii_read16(slave, 0x0004, &slave->sii_alias))
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   287
        return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   288
    if (ec_slave_sii_read32(slave, 0x0008, &slave->sii_vendor_id))
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   289
        return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   290
    if (ec_slave_sii_read32(slave, 0x000A, &slave->sii_product_code))
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   291
        return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   292
    if (ec_slave_sii_read32(slave, 0x000C, &slave->sii_revision_number))
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   293
        return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   294
    if (ec_slave_sii_read32(slave, 0x000E, &slave->sii_serial_number))
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   295
        return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   296
    if (ec_slave_sii_read16(slave, 0x0018, &slave->sii_rx_mailbox_offset))
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   297
        return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   298
    if (ec_slave_sii_read16(slave, 0x0019, &slave->sii_rx_mailbox_size))
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   299
        return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   300
    if (ec_slave_sii_read16(slave, 0x001A, &slave->sii_tx_mailbox_offset))
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   301
        return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   302
    if (ec_slave_sii_read16(slave, 0x001B, &slave->sii_tx_mailbox_size))
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   303
        return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   304
    if (ec_slave_sii_read16(slave, 0x001C, &slave->sii_mailbox_protocols))
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   305
        return -1;
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 132
diff changeset
   306
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   307
    if (unlikely(ec_slave_fetch_categories(slave))) {
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   308
        EC_ERR("Failed to fetch category data!\n");
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   309
        return -1;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   310
    }
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   311
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   312
    return 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   313
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   314
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   315
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   316
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   317
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   318
   Reads 16 bit from the slave information interface (SII).
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   319
   \return 0 in case of success, else < 0
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   320
*/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   321
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   322
int ec_slave_sii_read16(ec_slave_t *slave,
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   323
                        /**< EtherCAT slave */
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   324
                        uint16_t offset,
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   325
                        /**< address of the SII register to read */
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   326
                        uint16_t *target
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   327
                        /**< target memory */
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   328
                        )
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   329
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   330
    ec_command_t *command;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   331
    cycles_t start, end, timeout;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   332
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   333
    command = &slave->master->simple_command;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   334
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   335
    // initiate read operation
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   336
    if (ec_command_npwr(command, slave->station_address, 0x502, 6)) return -1;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   337
    EC_WRITE_U8 (command->data,     0x00); // read-only access
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   338
    EC_WRITE_U8 (command->data + 1, 0x01); // request read operation
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   339
    EC_WRITE_U32(command->data + 2, offset);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   340
    if (unlikely(ec_master_simple_io(slave->master, command))) {
89
e91ef35c36db Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   341
        EC_ERR("SII-read failed on slave %i!\n", slave->ring_position);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   342
        return -1;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   343
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   344
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   345
    start = get_cycles();
119
b2de89096010 Verschiedene Timeouts verl?ngert.
Florian Pose <fp@igh-essen.com>
parents: 118
diff changeset
   346
    timeout = (cycles_t) 100 * cpu_khz; // 100ms
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   347
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   348
    while (1)
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   349
    {
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   350
        udelay(10);
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   351
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   352
        if (ec_command_nprd(command, slave->station_address, 0x502, 10))
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   353
            return -1;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   354
        if (unlikely(ec_master_simple_io(slave->master, command))) {
89
e91ef35c36db Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   355
            EC_ERR("Getting SII-read status failed on slave %i!\n",
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   356
                   slave->ring_position);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   357
            return -1;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   358
        }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   359
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   360
        end = get_cycles();
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   361
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   362
        // check for "busy bit"
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   363
        if (likely((EC_READ_U8(command->data + 1) & 0x81) == 0)) {
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   364
            *target = EC_READ_U16(command->data + 6);
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   365
            return 0;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   366
        }
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   367
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   368
        if (unlikely((end - start) >= timeout)) {
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   369
            EC_ERR("SII-read. Slave %i timed out!\n", slave->ring_position);
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   370
            return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   371
        }
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   372
    }
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   373
}
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   374
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   375
/*****************************************************************************/
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   376
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   377
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   378
   Reads 32 bit from the slave information interface (SII).
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   379
   \return 0 in case of success, else < 0
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   380
*/
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   381
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   382
int ec_slave_sii_read32(ec_slave_t *slave,
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   383
                        /**< EtherCAT slave */
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   384
                        uint16_t offset,
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   385
                        /**< address of the SII register to read */
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   386
                        uint32_t *target
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   387
                        /**< target memory */
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   388
                        )
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   389
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   390
    ec_command_t *command;
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   391
    cycles_t start, end, timeout;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   392
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   393
    command = &slave->master->simple_command;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   394
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   395
    // initiate read operation
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   396
    if (ec_command_npwr(command, slave->station_address, 0x502, 6)) return -1;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   397
    EC_WRITE_U8 (command->data,     0x00); // read-only access
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   398
    EC_WRITE_U8 (command->data + 1, 0x01); // request read operation
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   399
    EC_WRITE_U32(command->data + 2, offset);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   400
    if (unlikely(ec_master_simple_io(slave->master, command))) {
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   401
        EC_ERR("SII-read failed on slave %i!\n", slave->ring_position);
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   402
        return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   403
    }
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   404
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   405
    start = get_cycles();
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   406
    timeout = (cycles_t) 100 * cpu_khz; // 100ms
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   407
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   408
    while (1)
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   409
    {
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   410
        udelay(10);
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   411
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   412
        if (ec_command_nprd(command, slave->station_address, 0x502, 10))
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   413
            return -1;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   414
        if (unlikely(ec_master_simple_io(slave->master, command))) {
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   415
            EC_ERR("Getting SII-read status failed on slave %i!\n",
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   416
                   slave->ring_position);
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   417
            return -1;
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   418
        }
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   419
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   420
        end = get_cycles();
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   421
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   422
        // check "busy bit"
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   423
        if (likely((EC_READ_U8(command->data + 1) & 0x81) == 0)) {
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   424
            *target = EC_READ_U32(command->data + 6);
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   425
            return 0;
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   426
        }
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   427
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   428
        if (unlikely((end - start) >= timeout)) {
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   429
            EC_ERR("SII-read. Slave %i timed out!\n", slave->ring_position);
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   430
            return -1;
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   431
        }
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   432
    }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   433
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   434
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   435
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   436
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   437
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   438
   Writes 16 bit of data to the slave information interface (SII).
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   439
   \return 0 in case of success, else < 0
114
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   440
*/
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   441
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   442
int ec_slave_sii_write16(ec_slave_t *slave,
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   443
                         /**< EtherCAT slave */
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   444
                         uint16_t offset,
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   445
                         /**< address of the SII register to write */
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   446
                         uint16_t value
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   447
                         /**< new value */
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   448
                         )
114
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   449
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   450
    ec_command_t *command;
114
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   451
    cycles_t start, end, timeout;
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   452
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   453
    command = &slave->master->simple_command;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   454
114
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   455
    EC_INFO("SII-write (slave %i, offset 0x%04X, value 0x%04X)\n",
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   456
            slave->ring_position, offset, value);
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   457
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   458
    // initiate write operation
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   459
    if (ec_command_npwr(command, slave->station_address, 0x502, 8)) return -1;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   460
    EC_WRITE_U8 (command->data,     0x01); // enable write access
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   461
    EC_WRITE_U8 (command->data + 1, 0x02); // request write operation
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   462
    EC_WRITE_U32(command->data + 2, offset);
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   463
    EC_WRITE_U16(command->data + 6, value);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   464
    if (unlikely(ec_master_simple_io(slave->master, command))) {
114
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   465
        EC_ERR("SII-write failed on slave %i!\n", slave->ring_position);
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   466
        return -1;
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   467
    }
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   468
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   469
    start = get_cycles();
119
b2de89096010 Verschiedene Timeouts verl?ngert.
Florian Pose <fp@igh-essen.com>
parents: 118
diff changeset
   470
    timeout = (cycles_t) 100 * cpu_khz; // 100ms
114
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   471
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   472
    while (1)
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   473
    {
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   474
        udelay(10);
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   475
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   476
        if (ec_command_nprd(command, slave->station_address, 0x502, 2))
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   477
            return -1;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   478
        if (unlikely(ec_master_simple_io(slave->master, command))) {
114
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   479
            EC_ERR("Getting SII-write status failed on slave %i!\n",
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   480
                   slave->ring_position);
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   481
            return -1;
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   482
        }
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   483
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   484
        end = get_cycles();
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   485
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   486
        // check "busy bit"
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   487
        if (likely((EC_READ_U8(command->data + 1) & 0x82) == 0)) {
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   488
            if (EC_READ_U8(command->data + 1) & 0x40) {
114
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   489
                EC_ERR("SII-write failed!\n");
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   490
                return -1;
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   491
            }
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   492
            else {
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   493
                EC_INFO("SII-write succeeded!\n");
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   494
                return 0;
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   495
            }
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   496
        }
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   497
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   498
        if (unlikely((end - start) >= timeout)) {
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   499
            EC_ERR("SII-write: Slave %i timed out!\n", slave->ring_position);
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   500
            return -1;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   501
        }
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   502
    }
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   503
}
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   504
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   505
/*****************************************************************************/
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   506
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   507
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   508
   Fetches data from slave's EEPROM.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   509
   \return 0 in case of success, else < 0
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   510
   \todo memory allocation
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   511
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   512
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   513
int ec_slave_fetch_categories(ec_slave_t *slave /**< EtherCAT slave */)
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   514
{
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   515
    uint16_t word_offset, cat_type, word_count;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   516
    uint32_t value;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   517
    uint8_t *cat_data;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   518
    unsigned int i;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   519
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   520
    word_offset = 0x0040;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   521
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   522
    if (!(cat_data = (uint8_t *) kmalloc(0x10000, GFP_KERNEL))) {
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   523
        EC_ERR("Failed to allocate 64k bytes for category data.\n");
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   524
        return -1;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   525
    }
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   526
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   527
    while (1) {
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   528
        // read category type
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   529
        if (ec_slave_sii_read32(slave, word_offset, &value)) {
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   530
            EC_ERR("Unable to read category header.\n");
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   531
            goto out_free;
118
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
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   534
        // last category?
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   535
        if ((value & 0xFFFF) == 0xFFFF) break;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   536
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   537
        cat_type = value & 0x7FFF;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   538
        word_count = (value >> 16) & 0xFFFF;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   539
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   540
        // fetch category data
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   541
        for (i = 0; i < word_count; i++) {
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   542
            if (ec_slave_sii_read32(slave, word_offset + 2 + i, &value)) {
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   543
                EC_ERR("Unable to read category data word %i.\n", i);
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   544
                goto out_free;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   545
            }
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   546
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   547
            cat_data[i * 2]     = (value >> 0) & 0xFF;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   548
            cat_data[i * 2 + 1] = (value >> 8) & 0xFF;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   549
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   550
            // read second word "on the fly"
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   551
            if (i + 1 < word_count) {
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   552
                i++;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   553
                cat_data[i * 2]     = (value >> 16) & 0xFF;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   554
                cat_data[i * 2 + 1] = (value >> 24) & 0xFF;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   555
            }
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   556
        }
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   557
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   558
        switch (cat_type)
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   559
        {
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   560
            case 0x000A:
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   561
                if (ec_slave_fetch_strings(slave, cat_data))
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   562
                    goto out_free;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   563
                break;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   564
            case 0x001E:
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   565
                if (ec_slave_fetch_general(slave, cat_data))
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   566
                    goto out_free;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   567
                break;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   568
            case 0x0028:
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   569
                break;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   570
            case 0x0029:
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   571
                if (ec_slave_fetch_sync(slave, cat_data, word_count))
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   572
                    goto out_free;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   573
                break;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   574
            case 0x0032:
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   575
                if (ec_slave_fetch_pdo(slave, cat_data, word_count, EC_TX_PDO))
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   576
                    goto out_free;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   577
                break;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   578
            case 0x0033:
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   579
                if (ec_slave_fetch_pdo(slave, cat_data, word_count, EC_RX_PDO))
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   580
                    goto out_free;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   581
                break;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   582
            default:
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   583
                EC_WARN("Unknown category type 0x%04X in slave %i.\n",
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   584
                        cat_type, slave->ring_position);
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   585
        }
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   586
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   587
        word_offset += 2 + word_count;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   588
    }
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   589
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   590
    kfree(cat_data);
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   591
    return 0;
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   592
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   593
 out_free:
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   594
    kfree(cat_data);
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   595
    return -1;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   596
}
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   597
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   598
/*****************************************************************************/
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   599
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   600
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   601
   Fetches data from a STRING category.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   602
   \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
   603
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   604
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   605
int ec_slave_fetch_strings(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   606
                           const uint8_t *data /**< category data */
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   607
                           )
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   608
{
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   609
    unsigned int string_count, i;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   610
    size_t size;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   611
    off_t offset;
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   612
    ec_eeprom_string_t *string;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   613
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   614
    string_count = data[0];
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   615
    offset = 1;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   616
    for (i = 0; i < string_count; i++) {
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   617
        size = data[offset];
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   618
        // allocate memory for string structure and data at a single blow
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   619
        if (!(string = (ec_eeprom_string_t *)
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   620
              kmalloc(sizeof(ec_eeprom_string_t) + size + 1, GFP_KERNEL))) {
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   621
            EC_ERR("Failed to allocate string memory.\n");
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   622
            return -1;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   623
        }
121
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   624
        string->size = size;
161
ddb7266d1c56 Bugfix: Discovered memory leak.
Florian Pose <fp@igh-essen.com>
parents: 160
diff changeset
   625
        // string memory appended to string structure
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   626
        string->data = (char *) string + sizeof(ec_eeprom_string_t);
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   627
        memcpy(string->data, data + offset + 1, size);
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   628
        string->data[size] = 0x00;
121
1cd6f7a47b72 Bugfix: Absturz behoben, EEPROM-Infos.
Florian Pose <fp@igh-essen.com>
parents: 119
diff changeset
   629
        list_add_tail(&string->list, &slave->eeprom_strings);
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   630
        offset += 1 + size;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   631
    }
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   632
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   633
    return 0;
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   634
}
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   635
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   636
/*****************************************************************************/
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   637
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   638
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   639
   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
   640
   \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
   641
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   642
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   643
int ec_slave_fetch_general(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   644
                           const uint8_t *data /**< category data */
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   645
                           )
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   646
{
190
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   647
    unsigned int i;
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   648
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   649
    if (ec_slave_locate_string(slave, data[0], &slave->eeprom_group))
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   650
        return -1;
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   651
    if (ec_slave_locate_string(slave, data[1], &slave->eeprom_name))
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   652
        return -1;
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   653
    if (ec_slave_locate_string(slave, data[3], &slave->eeprom_desc))
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   654
        return -1;
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   655
190
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   656
    for (i = 0; i < 4; i++)
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   657
        slave->sii_physical_layer[i] =
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   658
            (data[4] & (0x03 << (i * 2))) >> (i * 2);
190
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   659
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   660
    return 0;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   661
}
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   662
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   663
/*****************************************************************************/
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   664
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   665
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   666
   Fetches data from a SYNC MANAGER category.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   667
   \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
   668
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   669
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   670
int ec_slave_fetch_sync(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   671
                        const uint8_t *data, /**< category data */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   672
                        size_t word_count /**< number of words */
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   673
                        )
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   674
{
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   675
    unsigned int sync_count, i;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   676
    ec_eeprom_sync_t *sync;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   677
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   678
    sync_count = word_count / 4; // sync manager struct is 4 words long
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   679
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   680
    for (i = 0; i < sync_count; i++, data += 8) {
127
e67c80a76de4 Code aufger?umt und kleines Speicherleck entdeckt.
Florian Pose <fp@igh-essen.com>
parents: 126
diff changeset
   681
        if (!(sync = (ec_eeprom_sync_t *)
e67c80a76de4 Code aufger?umt und kleines Speicherleck entdeckt.
Florian Pose <fp@igh-essen.com>
parents: 126
diff changeset
   682
              kmalloc(sizeof(ec_eeprom_sync_t), GFP_KERNEL))) {
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   683
            EC_ERR("Failed to allocate Sync-Manager memory.\n");
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   684
            return -1;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   685
        }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   686
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   687
        sync->index = i;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   688
        sync->physical_start_address = *((uint16_t *) (data + 0));
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   689
        sync->length                 = *((uint16_t *) (data + 2));
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   690
        sync->control_register       = data[4];
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   691
        sync->enable                 = data[6];
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   692
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   693
        list_add_tail(&sync->list, &slave->eeprom_syncs);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   694
    }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   695
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   696
    return 0;
118
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   697
}
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   698
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   699
/*****************************************************************************/
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   700
dc71ce4cc641 Kategorie-Daten aus EEPROM lesen.
Florian Pose <fp@igh-essen.com>
parents: 114
diff changeset
   701
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   702
   Fetches data from a [RT]XPDO category.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   703
   \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
   704
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   705
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   706
int ec_slave_fetch_pdo(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   707
                       const uint8_t *data, /**< category data */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   708
                       size_t word_count, /**< number of words */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   709
                       ec_pdo_type_t pdo_type /**< PDO type */
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   710
                       )
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   711
{
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   712
    ec_eeprom_pdo_t *pdo;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   713
    ec_eeprom_pdo_entry_t *entry;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   714
    unsigned int entry_count, i;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   715
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   716
    while (word_count >= 4) {
127
e67c80a76de4 Code aufger?umt und kleines Speicherleck entdeckt.
Florian Pose <fp@igh-essen.com>
parents: 126
diff changeset
   717
        if (!(pdo = (ec_eeprom_pdo_t *)
e67c80a76de4 Code aufger?umt und kleines Speicherleck entdeckt.
Florian Pose <fp@igh-essen.com>
parents: 126
diff changeset
   718
              kmalloc(sizeof(ec_eeprom_pdo_t), GFP_KERNEL))) {
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   719
            EC_ERR("Failed to allocate PDO memory.\n");
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   720
            return -1;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   721
        }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   722
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   723
        INIT_LIST_HEAD(&pdo->entries);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   724
        pdo->type = pdo_type;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   725
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   726
        pdo->index = *((uint16_t *) data);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   727
        entry_count = data[2];
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   728
        pdo->sync_manager = data[3];
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   729
        pdo->name = NULL;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   730
        ec_slave_locate_string(slave, data[5], &pdo->name);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   731
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   732
        list_add_tail(&pdo->list, &slave->eeprom_pdos);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   733
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   734
        word_count -= 4;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   735
        data += 8;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   736
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   737
        for (i = 0; i < entry_count; i++) {
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   738
            if (!(entry = (ec_eeprom_pdo_entry_t *)
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   739
                  kmalloc(sizeof(ec_eeprom_pdo_entry_t), GFP_KERNEL))) {
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   740
                EC_ERR("Failed to allocate PDO entry memory.\n");
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   741
                return -1;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   742
            }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   743
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   744
            entry->index = *((uint16_t *) data);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   745
            entry->subindex = data[2];
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   746
            entry->name = NULL;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   747
            ec_slave_locate_string(slave, data[3], &entry->name);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   748
            entry->bit_length = data[5];
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   749
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   750
            list_add_tail(&entry->list, &pdo->entries);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   751
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   752
            word_count -= 4;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   753
            data += 8;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   754
        }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   755
    }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   756
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   757
    return 0;
114
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   758
}
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   759
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   760
/*****************************************************************************/
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   761
e4b4b5a85e75 Slave alias implementiert.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   762
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   763
   Searches the string list for an index and allocates a new string.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   764
   \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
   765
   \todo documentation
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   766
*/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   767
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   768
int ec_slave_locate_string(ec_slave_t *slave, /**< EtherCAT slave */
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   769
                           unsigned int index, /**< string index */
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   770
                           char **ptr /**< Address of the string pointer */
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   771
                           )
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   772
{
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   773
    ec_eeprom_string_t *string;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   774
    char *err_string;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   775
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   776
    // Erst alten Speicher freigeben
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   777
    if (*ptr) {
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   778
        kfree(*ptr);
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   779
        *ptr = NULL;
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   780
    }
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   781
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   782
    // Index 0 bedeutet "nicht belegt"
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   783
    if (!index) return 0;
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   784
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   785
    // EEPROM-String mit Index finden und kopieren
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   786
    list_for_each_entry(string, &slave->eeprom_strings, list) {
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   787
        if (--index) continue;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   788
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   789
        if (!(*ptr = (char *) kmalloc(string->size + 1, GFP_KERNEL))) {
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   790
            EC_ERR("Unable to allocate string memory.\n");
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   791
            return -1;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   792
        }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   793
        memcpy(*ptr, string->data, string->size + 1);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   794
        return 0;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   795
    }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   796
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   797
    EC_WARN("String %i not found in slave %i.\n", index, slave->ring_position);
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   798
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   799
    err_string = "(string not found)";
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   800
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   801
    if (!(*ptr = (char *) kmalloc(strlen(err_string) + 1, GFP_KERNEL))) {
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   802
        EC_ERR("Unable to allocate string memory.\n");
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   803
        return -1;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   804
    }
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   805
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
   806
    memcpy(*ptr, err_string, strlen(err_string) + 1);
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   807
    return 0;
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   808
}
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   809
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   810
/*****************************************************************************/
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   811
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
   812
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   813
   Acknowledges an error after a state transition.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   814
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   815
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   816
void ec_slave_state_ack(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   817
                        uint8_t state /**< previous state */
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   818
                        )
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   819
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   820
    ec_command_t *command;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   821
    cycles_t start, end, timeout;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   822
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   823
    command = &slave->master->simple_command;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   824
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   825
    if (ec_command_npwr(command, slave->station_address, 0x0120, 2)) return;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   826
    EC_WRITE_U16(command->data, state | EC_ACK);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   827
    if (unlikely(ec_master_simple_io(slave->master, command))) {
163
a1eea08070e1 Fixed state acknowledgement.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   828
        EC_WARN("Acknowledge sending failed on slave %i!\n",
a1eea08070e1 Fixed state acknowledgement.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   829
                slave->ring_position);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   830
        return;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   831
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   832
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   833
    start = get_cycles();
119
b2de89096010 Verschiedene Timeouts verl?ngert.
Florian Pose <fp@igh-essen.com>
parents: 118
diff changeset
   834
    timeout = (cycles_t) 10 * cpu_khz; // 10ms
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   835
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   836
    while (1)
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   837
    {
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   838
        udelay(100); // wait a little bit...
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   839
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   840
        if (ec_command_nprd(command, slave->station_address, 0x0130, 2))
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   841
            return;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   842
        if (unlikely(ec_master_simple_io(slave->master, command))) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   843
            slave->current_state = EC_SLAVE_STATE_UNKNOWN;
163
a1eea08070e1 Fixed state acknowledgement.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   844
            EC_WARN("Acknowledge checking failed on slave %i!\n",
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   845
                    slave->ring_position);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   846
            return;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   847
        }
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   848
163
a1eea08070e1 Fixed state acknowledgement.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   849
        end = get_cycles();
a1eea08070e1 Fixed state acknowledgement.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   850
a1eea08070e1 Fixed state acknowledgement.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   851
        if (likely(EC_READ_U8(command->data) == state)) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   852
            slave->current_state = state;
163
a1eea08070e1 Fixed state acknowledgement.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   853
            EC_INFO("Acknowleged state 0x%02X on slave %i.\n", state,
a1eea08070e1 Fixed state acknowledgement.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   854
                    slave->ring_position);
a1eea08070e1 Fixed state acknowledgement.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   855
            return;
a1eea08070e1 Fixed state acknowledgement.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   856
        }
a1eea08070e1 Fixed state acknowledgement.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   857
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   858
        if (unlikely((end - start) >= timeout)) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   859
            slave->current_state = EC_SLAVE_STATE_UNKNOWN;
164
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   860
            EC_WARN("Failed to acknowledge state 0x%02X on slave %i"
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   861
                    " - Timeout!\n", state, slave->ring_position);
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   862
            return;
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   863
        }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   864
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   865
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   866
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   867
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   868
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   869
/**
164
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   870
   Reads the AL status code of a slave and displays it.
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   871
   If the AL status code is not supported, or if no error occurred (both
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   872
   resulting in code = 0), nothing is displayed.
164
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   873
*/
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   874
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   875
void ec_slave_read_al_status_code(ec_slave_t *slave /**< EtherCAT slave */)
164
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   876
{
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   877
    ec_command_t *command;
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   878
    uint16_t code;
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   879
    const ec_code_msg_t *al_msg;
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   880
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   881
    command = &slave->master->simple_command;
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   882
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   883
    if (ec_command_nprd(command, slave->station_address, 0x0134, 2)) return;
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   884
    if (unlikely(ec_master_simple_io(slave->master, command))) {
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   885
        EC_WARN("Failed to read AL status code on slave %i!\n",
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   886
                slave->ring_position);
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   887
        return;
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   888
    }
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   889
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   890
    if (!(code = EC_READ_U16(command->data))) return;
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   891
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   892
    for (al_msg = al_status_messages; al_msg->code; al_msg++) {
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   893
        if (al_msg->code == code) {
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   894
            EC_ERR("AL status message 0x%04X: \"%s\".\n",
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   895
                   al_msg->code, al_msg->message);
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   896
            return;
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   897
        }
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   898
    }
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   899
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   900
    EC_ERR("Unknown AL status code 0x%04X.\n", code);
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   901
}
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   902
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   903
/*****************************************************************************/
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   904
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   905
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   906
   Does a state transition.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   907
   \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
   908
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   909
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   910
int ec_slave_state_change(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   911
                          uint8_t state /**< new state */
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   912
                          )
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   913
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   914
    ec_command_t *command;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   915
    cycles_t start, end, timeout;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   916
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   917
    command = &slave->master->simple_command;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   918
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   919
    slave->requested_state = state;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   920
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   921
    if (ec_command_npwr(command, slave->station_address, 0x0120, 2)) return -1;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   922
    EC_WRITE_U16(command->data, state);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   923
    if (unlikely(ec_master_simple_io(slave->master, command))) {
164
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   924
        EC_ERR("Failed to set state 0x%02X on slave %i!\n",
89
e91ef35c36db Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   925
               state, slave->ring_position);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   926
        return -1;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   927
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   928
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   929
    start = get_cycles();
119
b2de89096010 Verschiedene Timeouts verl?ngert.
Florian Pose <fp@igh-essen.com>
parents: 118
diff changeset
   930
    timeout = (cycles_t) 10 * cpu_khz; // 10ms
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   931
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   932
    while (1)
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   933
    {
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   934
        udelay(100); // wait a little bit
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   935
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   936
        if (ec_command_nprd(command, slave->station_address, 0x0130, 2))
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   937
            return -1;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   938
        if (unlikely(ec_master_simple_io(slave->master, command))) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   939
            slave->current_state = EC_SLAVE_STATE_UNKNOWN;
164
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   940
            EC_ERR("Failed to check state 0x%02X on slave %i!\n",
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   941
                   state, slave->ring_position);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   942
            return -1;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   943
        }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   944
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   945
        end = get_cycles();
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   946
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   947
        if (unlikely(EC_READ_U8(command->data) & 0x10)) { // state change error
164
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   948
            EC_ERR("Failed to set state 0x%02X - Slave %i refused state change"
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   949
                   " (code 0x%02X)!\n", state, slave->ring_position,
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   950
                   EC_READ_U8(command->data));
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   951
            slave->current_state = EC_READ_U8(command->data);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   952
            state = slave->current_state & 0x0F;
164
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   953
            ec_slave_read_al_status_code(slave);
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   954
            ec_slave_state_ack(slave, state);
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   955
            return -1;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   956
        }
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
   957
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   958
        if (likely(EC_READ_U8(command->data) == (state & 0x0F))) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   959
            slave->current_state = state;
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   960
            return 0; // state change successful
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   961
        }
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   962
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   963
        if (unlikely((end - start) >= timeout)) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
   964
            slave->current_state = EC_SLAVE_STATE_UNKNOWN;
164
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
   965
            EC_ERR("Failed to check state 0x%02X of slave %i - Timeout!\n",
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   966
                   state, slave->ring_position);
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   967
            return -1;
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   968
        }
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   969
    }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   970
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   971
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   972
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   973
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   974
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   975
   Prepares an FMMU configuration.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   976
   Configuration data for the FMMU is saved in the slave structure and is
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   977
   written to the slave in ecrt_master_activate().
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   978
   The FMMU configuration is done in a way, that the complete data range
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   979
   of the corresponding sync manager is covered. Seperate FMMUs arce configured
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   980
   for each domain.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   981
   If the FMMU configuration is already prepared, the function returns with
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   982
   success.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   983
   \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
   984
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   985
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   986
int ec_slave_prepare_fmmu(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   987
                          const ec_domain_t *domain, /**< domain */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   988
                          const ec_sync_t *sync  /**< sync manager */
160
7ddf8367196a Renamed slave_set_fmmu() to slave_prepare_fmmu().
Florian Pose <fp@igh-essen.com>
parents: 157
diff changeset
   989
                          )
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   990
{
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   991
    unsigned int i;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   992
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   993
    // FMMU configuration already prepared?
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   994
    for (i = 0; i < slave->fmmu_count; i++)
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   995
        if (slave->fmmus[i].domain == domain && slave->fmmus[i].sync == sync)
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   996
            return 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   997
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
   998
    // reserve new FMMU...
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 89
diff changeset
   999
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1000
    if (slave->fmmu_count >= slave->base_fmmu_count) {
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
  1001
        EC_ERR("Slave %i FMMU limit reached!\n", slave->ring_position);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1002
        return -1;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1003
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1004
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1005
    slave->fmmus[slave->fmmu_count].domain = domain;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1006
    slave->fmmus[slave->fmmu_count].sync = sync;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1007
    slave->fmmus[slave->fmmu_count].logical_start_address = 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1008
    slave->fmmu_count++;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1009
    slave->registered = 1;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1010
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1011
    return 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1012
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1013
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1014
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1015
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1016
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1017
   Outputs all information about a certain slave.
140
b09658e50d6f Verbosity level in ecrt_master_print().
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
  1018
   Verbosity:
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1019
   - 0: Only slave types and addresses
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1020
   - 1: with EEPROM information
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1021
   - >1: with SDO dictionaries
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1022
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1023
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1024
void ec_slave_print(const ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1025
                    unsigned int verbosity /**< verbosity level */
140
b09658e50d6f Verbosity level in ecrt_master_print().
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
  1026
                    )
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1027
{
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
  1028
    ec_eeprom_sync_t *sync;
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
  1029
    ec_eeprom_pdo_t *pdo;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
  1030
    ec_eeprom_pdo_entry_t *pdo_entry;
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
  1031
    ec_sdo_t *sdo;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
  1032
    ec_sdo_entry_t *sdo_entry;
142
e933f1adb550 Link Status ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1033
    int first, i;
126
bbc963b9fead Restliche EEPROM-Daten ausgelesen.
Florian Pose <fp@igh-essen.com>
parents: 124
diff changeset
  1034
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1035
    if (slave->type) {
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1036
        EC_INFO("%i) %s %s: %s\n", slave->ring_position,
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
  1037
                slave->type->vendor_name, slave->type->product_name,
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
  1038
                slave->type->description);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1039
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
  1040
    else {
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1041
        EC_INFO("%i) UNKNOWN SLAVE: vendor 0x%08X, product 0x%08X\n",
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1042
                slave->ring_position, slave->sii_vendor_id,
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1043
                slave->sii_product_code);
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1044
    }
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1045
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1046
    if (!verbosity) return;
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1047
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1048
    EC_INFO("  Station address: 0x%04X\n", slave->station_address);
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1049
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1050
    EC_INFO("  Data link status:\n");
183
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1051
    for (i = 0; i < 4; i++) {
190
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1052
        EC_INFO("    Port %i (", i);
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1053
        switch (slave->sii_physical_layer[i]) {
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1054
            case 0x00:
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1055
                printk("EBUS");
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1056
                break;
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1057
            case 0x01:
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1058
                printk("100BASE-TX");
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1059
                break;
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1060
            case 0x02:
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1061
                printk("100BASE-FX");
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1062
                break;
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1063
            default:
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1064
                printk("unknown");
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1065
        }
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1066
        printk(")\n");
4e32bcc6b361 Now fetching port physical layer from EEPROM
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1067
        EC_INFO("      link %s, loop %s, %s\n",
183
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1068
                slave->dl_link[i] ? "up" : "down",
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1069
                slave->dl_loop[i] ? "closed" : "open",
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1070
                slave->dl_signal[i] ? "signal detected" : "no signal");
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1071
    }
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1072
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1073
    EC_INFO("  Base information:\n");
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1074
    EC_INFO("    Type %u, revision %i, build %i\n",
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1075
            slave->base_type, slave->base_revision, slave->base_build);
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1076
    EC_INFO("    Supported FMMUs: %i, sync managers: %i\n",
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1077
            slave->base_fmmu_count, slave->base_sync_count);
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1078
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1079
    if (slave->sii_mailbox_protocols) {
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1080
        EC_INFO("  Mailbox communication:\n");
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1081
        EC_INFO("    RX mailbox: 0x%04X/%i, TX mailbox: 0x%04X/%i\n",
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1082
                slave->sii_rx_mailbox_offset, slave->sii_rx_mailbox_size,
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1083
                slave->sii_tx_mailbox_offset, slave->sii_tx_mailbox_size);
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1084
        EC_INFO("    Supported protocols: ");
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1085
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1086
        first = 1;
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1087
        if (slave->sii_mailbox_protocols & EC_MBOX_AOE) {
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1088
            printk("AoE");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1089
            first = 0;
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1090
        }
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1091
        if (slave->sii_mailbox_protocols & EC_MBOX_EOE) {
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1092
            if (!first) printk(", ");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1093
            printk("EoE");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1094
            first = 0;
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1095
        }
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1096
        if (slave->sii_mailbox_protocols & EC_MBOX_COE) {
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1097
            if (!first) printk(", ");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1098
            printk("CoE");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1099
            first = 0;
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1100
        }
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1101
        if (slave->sii_mailbox_protocols & EC_MBOX_FOE) {
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1102
            if (!first) printk(", ");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1103
            printk("FoE");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1104
            first = 0;
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1105
        }
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1106
        if (slave->sii_mailbox_protocols & EC_MBOX_SOE) {
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1107
            if (!first) printk(", ");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1108
            printk("SoE");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1109
            first = 0;
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1110
        }
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1111
        if (slave->sii_mailbox_protocols & EC_MBOX_VOE) {
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1112
            if (!first) printk(", ");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1113
            printk("VoE");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1114
        }
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1115
        printk("\n");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1116
    }
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1117
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1118
    EC_INFO("  EEPROM data:\n");
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1119
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1120
    if (slave->sii_alias)
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1121
        EC_INFO("    Configured station alias: 0x%04X (%i)\n",
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1122
                slave->sii_alias, slave->sii_alias);
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1123
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1124
    EC_INFO("    Vendor-ID: 0x%08X, Product code: 0x%08X\n",
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1125
            slave->sii_vendor_id, slave->sii_product_code);
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1126
    EC_INFO("    Revision number: 0x%08X, Serial number: 0x%08X\n",
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1127
            slave->sii_revision_number, slave->sii_serial_number);
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1128
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1129
    if (slave->eeprom_name)
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1130
        EC_INFO("    Name: %s\n", slave->eeprom_name);
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1131
    if (slave->eeprom_group)
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1132
        EC_INFO("    Group: %s\n", slave->eeprom_group);
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1133
    if (slave->eeprom_desc)
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1134
        EC_INFO("    Description: %s\n", slave->eeprom_desc);
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1135
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1136
    if (!list_empty(&slave->eeprom_syncs)) {
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1137
        EC_INFO("    Sync-Managers:\n");
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1138
        list_for_each_entry(sync, &slave->eeprom_syncs, list) {
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1139
            EC_INFO("      %i: 0x%04X, length %i, control 0x%02X, %s\n",
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1140
                    sync->index, sync->physical_start_address,
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1141
                    sync->length, sync->control_register,
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1142
                    sync->enable ? "enable" : "disable");
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1143
        }
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1144
    }
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1145
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1146
    list_for_each_entry(pdo, &slave->eeprom_pdos, list) {
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1147
        EC_INFO("    %s \"%s\" (0x%04X), -> Sync-Manager %i\n",
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1148
                pdo->type == EC_RX_PDO ? "RXPDO" : "TXPDO",
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1149
                pdo->name ? pdo->name : "???",
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1150
                pdo->index, pdo->sync_manager);
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1151
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1152
        list_for_each_entry(pdo_entry, &pdo->entries, list) {
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1153
            EC_INFO("      \"%s\" 0x%04X:%X, %i Bit\n",
147
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1154
                    pdo_entry->name ? pdo_entry->name : "???",
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1155
                    pdo_entry->index, pdo_entry->subindex,
a355b587b4bc Ausgaben verbessert, Mini-Modul angepasst.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
  1156
                    pdo_entry->bit_length);
140
b09658e50d6f Verbosity level in ecrt_master_print().
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
  1157
        }
b09658e50d6f Verbosity level in ecrt_master_print().
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
  1158
    }
b09658e50d6f Verbosity level in ecrt_master_print().
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
  1159
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1160
    if (verbosity < 2) return;
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1161
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1162
    if (!list_empty(&slave->sdo_dictionary)) {
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1163
        EC_INFO("    SDO-Dictionary:\n");
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1164
        list_for_each_entry(sdo, &slave->sdo_dictionary, list) {
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1165
            EC_INFO("      0x%04X \"%s\"\n", sdo->index,
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1166
                    sdo->name ? sdo->name : "");
175
2e4b18203ade Altered CoE "Get object description response" fields
Florian Pose <fp@igh-essen.com>
parents: 164
diff changeset
  1167
            EC_INFO("        Object code: 0x%02X\n", sdo->object_code);
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1168
            list_for_each_entry(sdo_entry, &sdo->entries, list) {
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1169
                EC_INFO("        0x%04X:%i \"%s\", type 0x%04X, %i bits\n",
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1170
                        sdo->index, sdo_entry->subindex,
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1171
                        sdo_entry->name ? sdo_entry->name : "",
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 155
diff changeset
  1172
                        sdo_entry->data_type, sdo_entry->bit_length);
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
  1173
            }
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
  1174
        }
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
  1175
    }
123
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
  1176
}
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
  1177
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
  1178
/*****************************************************************************/
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
  1179
4d5dc58d48e2 Weitere EEPROM-Daten.
Florian Pose <fp@igh-essen.com>
parents: 122
diff changeset
  1180
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1181
   Outputs the values of the CRC faoult counters and resets them.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1182
   \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
  1183
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1184
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1185
int ec_slave_check_crc(ec_slave_t *slave /**< EtherCAT slave */)
74
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1186
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1187
    ec_command_t *command;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1188
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1189
    command = &slave->master->simple_command;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1190
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1191
    if (ec_command_nprd(command, slave->station_address, 0x0300, 4)) return -1;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
  1192
    if (unlikely(ec_master_simple_io(slave->master, command))) {
89
e91ef35c36db Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
  1193
        EC_WARN("Reading CRC fault counters failed on slave %i!\n",
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
  1194
                slave->ring_position);
74
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1195
        return -1;
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1196
    }
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1197
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1198
    if (!EC_READ_U32(command->data)) return 0; // no CRC faults
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1199
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1200
    if (EC_READ_U8(command->data))
132
63a5b40eb7da CRC-Counter nach ESC-Datasheet implementiert.
Florian Pose <fp@igh-essen.com>
parents: 127
diff changeset
  1201
        EC_WARN("%3i RX-error%s on slave %i, channel A.\n",
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1202
                EC_READ_U8(command->data),
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1203
                EC_READ_U8(command->data) == 1 ? "" : "s",
132
63a5b40eb7da CRC-Counter nach ESC-Datasheet implementiert.
Florian Pose <fp@igh-essen.com>
parents: 127
diff changeset
  1204
                slave->ring_position);
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1205
    if (EC_READ_U8(command->data + 1))
132
63a5b40eb7da CRC-Counter nach ESC-Datasheet implementiert.
Florian Pose <fp@igh-essen.com>
parents: 127
diff changeset
  1206
        EC_WARN("%3i invalid frame%s on slave %i, channel A.\n",
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1207
                EC_READ_U8(command->data + 1),
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1208
                EC_READ_U8(command->data + 1) == 1 ? "" : "s",
132
63a5b40eb7da CRC-Counter nach ESC-Datasheet implementiert.
Florian Pose <fp@igh-essen.com>
parents: 127
diff changeset
  1209
                slave->ring_position);
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1210
    if (EC_READ_U8(command->data + 2))
132
63a5b40eb7da CRC-Counter nach ESC-Datasheet implementiert.
Florian Pose <fp@igh-essen.com>
parents: 127
diff changeset
  1211
        EC_WARN("%3i RX-error%s on slave %i, channel B.\n",
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1212
                EC_READ_U8(command->data + 2),
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1213
                EC_READ_U8(command->data + 2) == 1 ? "" : "s",
132
63a5b40eb7da CRC-Counter nach ESC-Datasheet implementiert.
Florian Pose <fp@igh-essen.com>
parents: 127
diff changeset
  1214
                slave->ring_position);
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1215
    if (EC_READ_U8(command->data + 3))
132
63a5b40eb7da CRC-Counter nach ESC-Datasheet implementiert.
Florian Pose <fp@igh-essen.com>
parents: 127
diff changeset
  1216
        EC_WARN("%3i invalid frame%s on slave %i, channel B.\n",
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1217
                EC_READ_U8(command->data + 3),
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1218
                EC_READ_U8(command->data + 3) == 1 ? "" : "s",
132
63a5b40eb7da CRC-Counter nach ESC-Datasheet implementiert.
Florian Pose <fp@igh-essen.com>
parents: 127
diff changeset
  1219
                slave->ring_position);
74
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1220
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1221
    // reset CRC counters
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1222
    if (ec_command_npwr(command, slave->station_address, 0x0300, 4)) return -1;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 142
diff changeset
  1223
    EC_WRITE_U32(command->data, 0x00000000);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
  1224
    if (unlikely(ec_master_simple_io(slave->master, command))) {
89
e91ef35c36db Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
  1225
        EC_WARN("Resetting CRC fault counters failed on slave %i!\n",
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
  1226
                slave->ring_position);
74
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1227
        return -1;
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1228
    }
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1229
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1230
    return 0;
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1231
}
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1232
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1233
/*****************************************************************************/
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1234
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 132
diff changeset
  1235
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1236
   Formats attribute data for SysFS read access.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1237
   \return number of bytes to read
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1238
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1239
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1240
ssize_t ec_show_slave_attribute(struct kobject *kobj, /**< slave's kobject */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1241
                                struct attribute *attr, /**< attribute */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 190
diff changeset
  1242
                                char *buffer /**< memory to store data */
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
  1243
                                )
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
  1244
{
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
  1245
    ec_slave_t *slave = container_of(kobj, ec_slave_t, kobj);
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
  1246
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
  1247
    if (attr == &attr_ring_position) {
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
  1248
        return sprintf(buffer, "%i\n", slave->ring_position);
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
  1249
    }
188
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 185
diff changeset
  1250
    else if (attr == &attr_coupler_address) {
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 185
diff changeset
  1251
        return sprintf(buffer, "%i:%i\n", slave->coupler_index,
c0e49f4a1c07 Better calc. of coupler address; coupler address in SysFS; better output of ec_list
Florian Pose <fp@igh-essen.com>
parents: 185
diff changeset
  1252
                       slave->coupler_subindex);
183
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1253
    }
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1254
    else if (attr == &attr_vendor_name) {
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1255
        if (slave->type)
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1256
            return sprintf(buffer, "%s\n", slave->type->vendor_name);
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1257
    }
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1258
    else if (attr == &attr_product_name) {
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1259
        if (slave->type)
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1260
            return sprintf(buffer, "%s\n", slave->type->product_name);
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1261
    }
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1262
    else if (attr == &attr_product_desc) {
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1263
        if (slave->type)
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1264
            return sprintf(buffer, "%s\n", slave->type->description);
8ae1e011e96c More slave fields in SysFS; DL link status for 4 ports
Florian Pose <fp@igh-essen.com>
parents: 182
diff changeset
  1265
    }
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
  1266
    else if (attr == &attr_sii_desc) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
  1267
        if (slave->eeprom_desc)
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
  1268
            return sprintf(buffer, "%s\n", slave->eeprom_desc);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
  1269
    }
185
af570302dcee Slave (special) type in SysFS
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
  1270
    else if (attr == &attr_type) {
af570302dcee Slave (special) type in SysFS
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
  1271
        if (slave->type) {
af570302dcee Slave (special) type in SysFS
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
  1272
            if (slave->type->special == EC_TYPE_BUS_COUPLER)
af570302dcee Slave (special) type in SysFS
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
  1273
                return sprintf(buffer, "coupler\n");
af570302dcee Slave (special) type in SysFS
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
  1274
            else
af570302dcee Slave (special) type in SysFS
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
  1275
                return sprintf(buffer, "normal\n");
af570302dcee Slave (special) type in SysFS
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
  1276
        }
af570302dcee Slave (special) type in SysFS
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
  1277
    }
256
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1278
    else if (attr == &attr_state) {
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1279
        switch (slave->current_state) {
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1280
            case EC_SLAVE_STATE_INIT:
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1281
                return sprintf(buffer, "INIT\n");
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1282
            case EC_SLAVE_STATE_PREOP:
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1283
                return sprintf(buffer, "PREOP\n");
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1284
            case EC_SLAVE_STATE_SAVEOP:
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1285
                return sprintf(buffer, "SAVEOP\n");
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1286
            case EC_SLAVE_STATE_OP:
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1287
                return sprintf(buffer, "OP\n");
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1288
            default:
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1289
                return sprintf(buffer, "UNKNOWN\n");
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1290
        }
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1291
    }
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
  1292
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
  1293
    return 0;
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
  1294
}
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
  1295
256
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1296
/*****************************************************************************/
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1297
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1298
/**
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1299
   Formats attribute data for SysFS write access.
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1300
   \return number of bytes processed, or negative error code
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1301
*/
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1302
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1303
ssize_t ec_store_slave_attribute(struct kobject *kobj, /**< slave's kobject */
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1304
                                 struct attribute *attr, /**< attribute */
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1305
                                 const char *buffer, /**< memory with data */
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1306
                                 size_t size /**< size of data to store */
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1307
                                 )
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1308
{
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1309
    ec_slave_t *slave = container_of(kobj, ec_slave_t, kobj);
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1310
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1311
    if (attr == &attr_state) {
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1312
        if (!strcmp(buffer, "INIT\n")) {
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1313
            slave->requested_state = EC_SLAVE_STATE_INIT;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
  1314
            slave->state_error = 0;
256
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1315
            return size;
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1316
        }
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1317
        else if (!strcmp(buffer, "PREOP\n")) {
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1318
            slave->requested_state = EC_SLAVE_STATE_PREOP;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
  1319
            slave->state_error = 0;
256
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1320
            return size;
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1321
        }
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1322
        else if (!strcmp(buffer, "SAVEOP\n")) {
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1323
            slave->requested_state = EC_SLAVE_STATE_SAVEOP;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
  1324
            slave->state_error = 0;
256
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1325
            return size;
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1326
        }
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1327
        else if (!strcmp(buffer, "OP\n")) {
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1328
            slave->requested_state = EC_SLAVE_STATE_OP;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 256
diff changeset
  1329
            slave->state_error = 0;
256
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1330
            return size;
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1331
        }
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1332
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1333
        EC_ERR("Failed to set slave state!\n");
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1334
    }
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1335
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1336
    return -EINVAL;
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1337
}
dc71aee17f8a SysFS write access for slave state.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
  1338
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1339
/******************************************************************************
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1340
 *  Realtime interface
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1341
 *****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1342
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1343
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1344
   Writes the "configured station alias" to the slave's EEPROM.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1345
   \return 0 in case of success, else < 0
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1346
   \ingroup RealtimeInterface
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1347
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1348
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1349
int ecrt_slave_write_alias(ec_slave_t *slave, /**< EtherCAT slave */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1350
                           uint16_t alias /**< new alias */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1351
                           )
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1352
{
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1353
    return ec_slave_sii_write16(slave, 0x0004, alias);
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1354
}
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1355
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1356
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1357
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1358
/**< \cond */
164
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 163
diff changeset
  1359
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 136
diff changeset
  1360
EXPORT_SYMBOL(ecrt_slave_write_alias);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 136
diff changeset
  1361
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1362
/**< \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1363
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1364
/*****************************************************************************/