master/master.c
author Florian Pose <fp@igh-essen.com>
Fri, 20 Oct 2006 10:48:30 +0000
changeset 421 2b3ce4f51bd6
parent 418 7a43437bc48b
child 430 74754f45d5fa
permissions -rw-r--r--
Reconfiguration of slaves, though they are in the correct state at startup.
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 35
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: 35
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: 239
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: 239
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: 239
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: 239
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: 239
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: 239
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: 239
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: 239
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: 239
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: 239
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 239
diff changeset
    31
 *
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 35
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 master 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>
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include <linux/kernel.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include <linux/string.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include <linux/slab.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include <linux/delay.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
    47
#include "../include/ecrt.h"
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    48
#include "globals.h"
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    49
#include "master.h"
55
059a9e712aa7 Mit neuer Schnittstelle wieder lauff?hig.
Florian Pose <fp@igh-essen.com>
parents: 54
diff changeset
    50
#include "slave.h"
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    51
#include "device.h"
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
    52
#include "datagram.h"
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
    53
#include "ethernet.h"
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 35
diff changeset
    55
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
404
7f7f429e13c7 Removed clear functions from headers of kobject-classes.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
    57
void ec_master_clear(struct kobject *);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
    58
void ec_master_sync_io(ec_master_t *);
318
5f35e74124d1 Renamed ec_master_idle() to ec_master_idle_run().
Florian Pose <fp@igh-essen.com>
parents: 313
diff changeset
    59
void ec_master_idle_run(void *);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    60
void ec_master_eoe_run(unsigned long);
179
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    61
ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *);
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
    62
ssize_t ec_store_master_attribute(struct kobject *, struct attribute *,
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
    63
                                  const char *, size_t);
179
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    64
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    65
/*****************************************************************************/
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    66
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    67
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    68
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
    69
EC_SYSFS_READ_ATTR(info);
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
    70
EC_SYSFS_READ_WRITE_ATTR(eeprom_write_enable);
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
    71
EC_SYSFS_READ_WRITE_ATTR(debug_level);
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    72
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    73
static struct attribute *ec_def_attrs[] = {
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
    74
    &attr_info,
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
    75
    &attr_eeprom_write_enable,
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
    76
    &attr_debug_level,
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    77
    NULL,
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    78
};
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    79
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    80
static struct sysfs_ops ec_sysfs_ops = {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    81
    .show = &ec_show_master_attribute,
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
    82
    .store = ec_store_master_attribute
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    83
};
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    84
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    85
static struct kobj_type ktype_ec_master = {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    86
    .release = ec_master_clear,
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    87
    .sysfs_ops = &ec_sysfs_ops,
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    88
    .default_attrs = ec_def_attrs
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    89
};
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    90
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    91
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    92
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    93
/*****************************************************************************/
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    94
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    96
   Master constructor.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    97
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    98
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    99
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   100
int ec_master_init(ec_master_t *master, /**< EtherCAT master */
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   101
                   unsigned int index, /**< master index */
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   102
                   unsigned int eoeif_count, /**< number of EoE interfaces */
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   103
                   dev_t dev_num /**< number for XML cdev's */
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   104
                   )
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   105
{
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   106
    ec_eoe_t *eoe, *next_eoe;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   107
    unsigned int i;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   108
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   109
    EC_INFO("Initializing master %i.\n", index);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   110
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   111
    master->index = index;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   112
    master->device = NULL;
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   113
    init_MUTEX(&master->device_sem);
378
8fe6cd43787a Replaced master's reserved flag by atomic_t available.
Florian Pose <fp@igh-essen.com>
parents: 377
diff changeset
   114
    atomic_set(&master->available, 1);
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 179
diff changeset
   115
    INIT_LIST_HEAD(&master->slaves);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   116
    INIT_LIST_HEAD(&master->datagram_queue);
95
0066de7a456d Domains als Liste verwaltet.
Florian Pose <fp@igh-essen.com>
parents: 94
diff changeset
   117
    INIT_LIST_HEAD(&master->domains);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   118
    INIT_LIST_HEAD(&master->eoe_handlers);
318
5f35e74124d1 Renamed ec_master_idle() to ec_master_idle_run().
Florian Pose <fp@igh-essen.com>
parents: 313
diff changeset
   119
    INIT_WORK(&master->idle_work, ec_master_idle_run, (void *) master);
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   120
    init_timer(&master->eoe_timer);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   121
    master->eoe_timer.function = ec_master_eoe_run;
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   122
    master->eoe_timer.data = (unsigned long) master;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   123
    master->internal_lock = SPIN_LOCK_UNLOCKED;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   124
    master->eoe_running = 0;
326
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   125
    master->eoe_checked = 0;
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   126
    for (i = 0; i < HZ; i++) {
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   127
        master->idle_cycle_times[i] = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   128
        master->eoe_cycle_times[i] = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   129
    }
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   130
    master->idle_cycle_time_pos = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   131
    master->eoe_cycle_time_pos = 0;
415
0918aa9bfd0b Do net reset debug level on master reset.
Florian Pose <fp@igh-essen.com>
parents: 414
diff changeset
   132
    master->debug_level = 0;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   133
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   134
    // create workqueue
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   135
    if (!(master->workqueue = create_singlethread_workqueue("EtherCAT"))) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   136
        EC_ERR("Failed to create master workqueue.\n");
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   137
        goto out_return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   138
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   139
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   140
    // init XML character device
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   141
    if (ec_xmldev_init(&master->xmldev, master, dev_num)) {
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   142
        EC_ERR("Failed to init XML character device.\n");
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   143
        goto out_clear_wq;
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   144
    }
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   145
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   146
    // create EoE handlers
321
64e20e6e9d0b Renamed master parameter ec_eoe_devices to ec_eoeif_count.
Florian Pose <fp@igh-essen.com>
parents: 318
diff changeset
   147
    for (i = 0; i < eoeif_count; i++) {
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   148
        if (!(eoe = (ec_eoe_t *) kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   149
            EC_ERR("Failed to allocate EoE-Object.\n");
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   150
            goto out_clear_eoe;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   151
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   152
        if (ec_eoe_init(eoe)) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   153
            kfree(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   154
            goto out_clear_eoe;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   155
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   156
        list_add_tail(&eoe->list, &master->eoe_handlers);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   157
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   158
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   159
    // create state machine object
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   160
    if (ec_fsm_init(&master->fsm, master)) goto out_clear_eoe;
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   161
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   162
    // init kobject and add it to the hierarchy
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   163
    memset(&master->kobj, 0x00, sizeof(struct kobject));
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   164
    kobject_init(&master->kobj);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   165
    master->kobj.ktype = &ktype_ec_master;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   166
    if (kobject_set_name(&master->kobj, "ethercat%i", index)) {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   167
        EC_ERR("Failed to set kobj name.\n");
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   168
        kobject_put(&master->kobj);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   169
        return -1;
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   170
    }
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   171
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   172
    ec_master_reset(master);
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   173
    return 0;
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   174
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   175
 out_clear_eoe:
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   176
    list_for_each_entry_safe(eoe, next_eoe, &master->eoe_handlers, list) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   177
        list_del(&eoe->list);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   178
        ec_eoe_clear(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   179
        kfree(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   180
    }
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   181
    ec_xmldev_clear(&master->xmldev);
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   182
 out_clear_wq:
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   183
    destroy_workqueue(master->workqueue);
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   184
 out_return:
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   185
    return -1;
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 35
diff changeset
   188
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   191
   Master destructor.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   192
   Removes all pending datagrams, clears the slave list, clears all domains
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   193
   and frees the device.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   194
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   196
void ec_master_clear(struct kobject *kobj /**< kobject of the master */)
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   197
{
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   198
    ec_master_t *master = container_of(kobj, ec_master_t, kobj);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   199
    ec_eoe_t *eoe, *next_eoe;
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   200
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   201
    EC_INFO("Clearing master %i...\n", master->index);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   202
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   203
    ec_master_reset(master);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   204
    ec_fsm_clear(&master->fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   205
    destroy_workqueue(master->workqueue);
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   206
    ec_xmldev_clear(&master->xmldev);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   207
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   208
    // clear EoE objects
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   209
    list_for_each_entry_safe(eoe, next_eoe, &master->eoe_handlers, list) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   210
        list_del(&eoe->list);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   211
        ec_eoe_clear(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   212
        kfree(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   213
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   214
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   215
    if (master->device) {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   216
        ec_device_clear(master->device);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   217
        kfree(master->device);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   218
    }
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   219
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   220
    EC_INFO("Master %i cleared.\n", master->index);
418
7a43437bc48b Fixed memory leak in master and slave destructors.
Florian Pose <fp@igh-essen.com>
parents: 415
diff changeset
   221
7a43437bc48b Fixed memory leak in master and slave destructors.
Florian Pose <fp@igh-essen.com>
parents: 415
diff changeset
   222
    kfree(master);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   223
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   224
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   225
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   226
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   227
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   228
   Resets the master.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   229
   Note: This function has to be called, everytime ec_master_release() is
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   230
   called, to free the slave list, domains etc.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   231
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   232
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   233
void ec_master_reset(ec_master_t *master /**< EtherCAT master */)
56
36d1fa37f5e1 Bugfix im Master, ec_master_reset() und laufendes Beispiel in rt.
Florian Pose <fp@igh-essen.com>
parents: 55
diff changeset
   234
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   235
    ec_datagram_t *datagram, *next_c;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   236
    ec_domain_t *domain, *next_d;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   237
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   238
    ec_master_eoe_stop(master);
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   239
    ec_master_idle_stop(master);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   240
    ec_master_clear_slaves(master);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   241
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   242
    // empty datagram queue
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   243
    list_for_each_entry_safe(datagram, next_c,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   244
                             &master->datagram_queue, queue) {
345
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   245
        datagram->state = EC_DATAGRAM_ERROR;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   246
        list_del_init(&datagram->queue);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   247
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   248
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   249
    // clear domains
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   250
    list_for_each_entry_safe(domain, next_d, &master->domains, list) {
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   251
        list_del(&domain->list);
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   252
        kobject_del(&domain->kobj);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   253
        kobject_put(&domain->kobj);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   254
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   255
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   256
    master->datagram_index = 0;
130
69c2645300ee Watch-Kommando
Florian Pose <fp@igh-essen.com>
parents: 129
diff changeset
   257
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   258
    master->stats.timeouts = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   259
    master->stats.corrupted = 0;
332
e16093374dfd New statistic outputs to avoid blasting the logs.
Florian Pose <fp@igh-essen.com>
parents: 331
diff changeset
   260
    master->stats.skipped = 0;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   261
    master->stats.unmatched = 0;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   262
    master->stats.output_jiffies = 0;
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   263
305
03aab3068f08 Renamed IDLE mode to ORPHANED mode.
Florian Pose <fp@igh-essen.com>
parents: 303
diff changeset
   264
    master->mode = EC_MASTER_MODE_ORPHANED;
204
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
   265
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
   266
    master->request_cb = NULL;
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
   267
    master->release_cb = NULL;
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
   268
    master->cb_data = NULL;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   269
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   270
    master->eeprom_write_enable = 0;
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   271
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   272
    ec_fsm_reset(&master->fsm);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   273
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   274
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   275
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   276
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   277
/**
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   278
   Clears all slaves.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   279
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   280
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   281
void ec_master_clear_slaves(ec_master_t *master)
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   282
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   283
    ec_slave_t *slave, *next_slave;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   284
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   285
    list_for_each_entry_safe(slave, next_slave, &master->slaves, list) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   286
        list_del(&slave->list);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   287
        kobject_del(&slave->kobj);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   288
        kobject_put(&slave->kobj);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   289
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   290
    master->slave_count = 0;
74
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   291
}
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   292
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   293
/*****************************************************************************/
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   294
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   295
/**
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   296
   Places a datagram in the datagram queue.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   297
*/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   298
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   299
void ec_master_queue_datagram(ec_master_t *master, /**< EtherCAT master */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   300
                              ec_datagram_t *datagram /**< datagram */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   301
                              )
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   302
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   303
    ec_datagram_t *queued_datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   304
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   305
    // check, if the datagram is already queued
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   306
    list_for_each_entry(queued_datagram, &master->datagram_queue, queue) {
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   307
        if (queued_datagram == datagram) {
332
e16093374dfd New statistic outputs to avoid blasting the logs.
Florian Pose <fp@igh-essen.com>
parents: 331
diff changeset
   308
            master->stats.skipped++;
e16093374dfd New statistic outputs to avoid blasting the logs.
Florian Pose <fp@igh-essen.com>
parents: 331
diff changeset
   309
            ec_master_output_stats(master);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   310
            datagram->state = EC_DATAGRAM_QUEUED;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   311
            return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   312
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   313
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   314
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   315
    list_add_tail(&datagram->queue, &master->datagram_queue);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   316
    datagram->state = EC_DATAGRAM_QUEUED;
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   317
    datagram->cycles_queued = get_cycles();
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   318
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   319
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   320
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   321
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   322
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   323
   Sends the datagrams in the queue.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   324
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   325
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   326
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   327
void ec_master_send_datagrams(ec_master_t *master /**< EtherCAT master */)
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   328
{
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   329
    ec_datagram_t *datagram, *next;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   330
    size_t datagram_size;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   331
    uint8_t *frame_data, *cur_data;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   332
    void *follows_word;
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   333
    cycles_t cycles_start, cycles_sent, cycles_end;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   334
    unsigned long jiffies_sent;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   335
    unsigned int frame_count, more_datagrams_waiting;
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   336
    struct list_head sent_datagrams;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   337
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   338
    cycles_start = get_cycles();
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   339
    frame_count = 0;
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   340
    INIT_LIST_HEAD(&sent_datagrams);
208
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
   341
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   342
    if (unlikely(master->debug_level > 1))
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   343
        EC_DBG("ec_master_send_datagrams\n");
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   344
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   345
    do {
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   346
        // fetch pointer to transmit socket buffer
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   347
        frame_data = ec_device_tx_data(master->device);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   348
        cur_data = frame_data + EC_FRAME_HEADER_SIZE;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   349
        follows_word = NULL;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   350
        more_datagrams_waiting = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   351
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   352
        // fill current frame with datagrams
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   353
        list_for_each_entry(datagram, &master->datagram_queue, queue) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   354
            if (datagram->state != EC_DATAGRAM_QUEUED) continue;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   355
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   356
            // does the current datagram fit in the frame?
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   357
            datagram_size = EC_DATAGRAM_HEADER_SIZE + datagram->data_size
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   358
                + EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   359
            if (cur_data - frame_data + datagram_size > ETH_DATA_LEN) {
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   360
                more_datagrams_waiting = 1;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   361
                break;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   362
            }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   363
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   364
            list_add_tail(&datagram->sent, &sent_datagrams);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   365
            datagram->index = master->datagram_index++;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   366
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   367
            if (unlikely(master->debug_level > 1))
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   368
                EC_DBG("adding datagram 0x%02X\n", datagram->index);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   369
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   370
            // set "datagram following" flag in previous frame
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   371
            if (follows_word)
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   372
                EC_WRITE_U16(follows_word, EC_READ_U16(follows_word) | 0x8000);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   373
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   374
            // EtherCAT datagram header
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   375
            EC_WRITE_U8 (cur_data,     datagram->type);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   376
            EC_WRITE_U8 (cur_data + 1, datagram->index);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   377
            EC_WRITE_U32(cur_data + 2, datagram->address.logical);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   378
            EC_WRITE_U16(cur_data + 6, datagram->data_size & 0x7FF);
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   379
            EC_WRITE_U16(cur_data + 8, 0x0000);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   380
            follows_word = cur_data + 6;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   381
            cur_data += EC_DATAGRAM_HEADER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   382
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   383
            // EtherCAT datagram data
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   384
            memcpy(cur_data, datagram->data, datagram->data_size);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   385
            cur_data += datagram->data_size;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   386
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   387
            // EtherCAT datagram footer
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   388
            EC_WRITE_U16(cur_data, 0x0000); // reset working counter
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   389
            cur_data += EC_DATAGRAM_FOOTER_SIZE;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   390
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   391
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   392
        if (list_empty(&sent_datagrams)) {
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   393
            if (unlikely(master->debug_level > 1))
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   394
                EC_DBG("nothing to send.\n");
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   395
            break;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   396
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   397
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   398
        // EtherCAT frame header
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   399
        EC_WRITE_U16(frame_data, ((cur_data - frame_data
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   400
                                   - EC_FRAME_HEADER_SIZE) & 0x7FF) | 0x1000);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   401
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   402
        // pad frame
211
c684b6b7adaf Using kernel Ethernet constants.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
   403
        while (cur_data - frame_data < ETH_ZLEN - ETH_HLEN)
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   404
            EC_WRITE_U8(cur_data++, 0x00);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   405
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   406
        if (unlikely(master->debug_level > 1))
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   407
            EC_DBG("frame size: %i\n", cur_data - frame_data);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   408
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   409
        // send frame
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   410
        ec_device_send(master->device, cur_data - frame_data);
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   411
        cycles_sent = get_cycles();
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   412
        jiffies_sent = jiffies;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   413
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   414
        // set datagram states and sending timestamps
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   415
        list_for_each_entry_safe(datagram, next, &sent_datagrams, sent) {
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   416
            datagram->state = EC_DATAGRAM_SENT;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   417
            datagram->cycles_sent = cycles_sent;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   418
            datagram->jiffies_sent = jiffies_sent;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   419
            list_del_init(&datagram->sent); // empty list of sent datagrams
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   420
        }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   421
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   422
        frame_count++;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   423
    }
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   424
    while (more_datagrams_waiting);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   425
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   426
    if (unlikely(master->debug_level > 1)) {
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   427
        cycles_end = get_cycles();
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   428
        EC_DBG("ec_master_send_datagrams sent %i frames in %ius.\n",
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   429
               frame_count,
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   430
               (unsigned int) (cycles_end - cycles_start) * 1000 / cpu_khz);
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   431
    }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   432
}
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   433
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   434
/*****************************************************************************/
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   435
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   436
/**
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   437
   Processes a received frame.
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   438
   This function is called by the network driver for every received frame.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   439
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   440
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   441
331
17f58fe99511 Renamed ec_master_receive() to ec_master_receive_datagrams().
Florian Pose <fp@igh-essen.com>
parents: 330
diff changeset
   442
void ec_master_receive_datagrams(ec_master_t *master, /**< EtherCAT master */
17f58fe99511 Renamed ec_master_receive() to ec_master_receive_datagrams().
Florian Pose <fp@igh-essen.com>
parents: 330
diff changeset
   443
                                 const uint8_t *frame_data, /**< frame data */
17f58fe99511 Renamed ec_master_receive() to ec_master_receive_datagrams().
Florian Pose <fp@igh-essen.com>
parents: 330
diff changeset
   444
                                 size_t size /**< size of the received data */
17f58fe99511 Renamed ec_master_receive() to ec_master_receive_datagrams().
Florian Pose <fp@igh-essen.com>
parents: 330
diff changeset
   445
                                 )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   446
{
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   447
    size_t frame_size, data_size;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   448
    uint8_t datagram_type, datagram_index;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   449
    unsigned int cmd_follows, matched;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   450
    const uint8_t *cur_data;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   451
    ec_datagram_t *datagram;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   452
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   453
    if (unlikely(size < EC_FRAME_HEADER_SIZE)) {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   454
        master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   455
        ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   456
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   457
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   458
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   459
    cur_data = frame_data;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   460
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   461
    // check length of entire frame
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   462
    frame_size = EC_READ_U16(cur_data) & 0x07FF;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   463
    cur_data += EC_FRAME_HEADER_SIZE;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   464
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   465
    if (unlikely(frame_size > size)) {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   466
        master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   467
        ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   468
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   469
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   470
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   471
    cmd_follows = 1;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   472
    while (cmd_follows) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   473
        // process datagram header
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   474
        datagram_type  = EC_READ_U8 (cur_data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   475
        datagram_index = EC_READ_U8 (cur_data + 1);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   476
        data_size      = EC_READ_U16(cur_data + 6) & 0x07FF;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   477
        cmd_follows    = EC_READ_U16(cur_data + 6) & 0x8000;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   478
        cur_data += EC_DATAGRAM_HEADER_SIZE;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   479
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   480
        if (unlikely(cur_data - frame_data
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   481
                     + data_size + EC_DATAGRAM_FOOTER_SIZE > size)) {
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   482
            master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   483
            ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   484
            return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   485
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   486
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   487
        // search for matching datagram in the queue
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   488
        matched = 0;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   489
        list_for_each_entry(datagram, &master->datagram_queue, queue) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   490
            if (datagram->state == EC_DATAGRAM_SENT
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   491
                && datagram->type == datagram_type
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   492
                && datagram->index == datagram_index
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   493
                && datagram->data_size == data_size) {
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   494
                matched = 1;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   495
                break;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   496
            }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   497
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   498
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   499
        // no matching datagram was found
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   500
        if (!matched) {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   501
            master->stats.unmatched++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   502
            ec_master_output_stats(master);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   503
            cur_data += data_size + EC_DATAGRAM_FOOTER_SIZE;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   504
            continue;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   505
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   506
345
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   507
        // copy received data into the datagram memory
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   508
        memcpy(datagram->data, cur_data, data_size);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   509
        cur_data += data_size;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   510
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   511
        // set the datagram's working counter
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   512
        datagram->working_counter = EC_READ_U16(cur_data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   513
        cur_data += EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   514
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   515
        // dequeue the received datagram
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   516
        datagram->state = EC_DATAGRAM_RECEIVED;
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   517
        datagram->cycles_received = master->device->cycles_isr;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   518
        datagram->jiffies_received = master->device->jiffies_isr;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   519
        list_del_init(&datagram->queue);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   520
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   521
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   522
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   523
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   524
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   525
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   526
   Scans the EtherCAT bus for slaves.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   527
   Creates a list of slave structures for further processing.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   528
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   529
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   530
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   531
int ec_master_bus_scan(ec_master_t *master /**< EtherCAT master */)
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   532
{
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   533
    ec_fsm_t *fsm = &master->fsm;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   534
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   535
    ec_fsm_startup(fsm); // init startup state machine
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   536
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   537
    do {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   538
        ec_fsm_execute(fsm);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   539
        ec_master_sync_io(master);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   540
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   541
    while (ec_fsm_startup_running(fsm));
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   542
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   543
    if (!ec_fsm_startup_success(fsm)) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   544
        ec_master_clear_slaves(master);
90
044e97bce4bd Rahmen jetzt zustandslos.
Florian Pose <fp@igh-essen.com>
parents: 89
diff changeset
   545
        return -1;
044e97bce4bd Rahmen jetzt zustandslos.
Florian Pose <fp@igh-essen.com>
parents: 89
diff changeset
   546
    }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   547
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   548
    return 0;
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   549
}
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   550
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   551
/*****************************************************************************/
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   552
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   553
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   554
   Output statistics in cyclic mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   555
   This function outputs statistical data on demand, but not more often than
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   556
   necessary. The output happens at most once a second.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   557
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   558
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   559
void ec_master_output_stats(ec_master_t *master /**< EtherCAT master */)
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   560
{
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   561
    if (unlikely(jiffies - master->stats.output_jiffies >= HZ)) {
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   562
        master->stats.output_jiffies = jiffies;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   563
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   564
        if (master->stats.timeouts) {
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   565
            EC_WARN("%i datagram%s TIMED OUT!\n", master->stats.timeouts,
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   566
                    master->stats.timeouts == 1 ? "" : "s");
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   567
            master->stats.timeouts = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   568
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   569
        if (master->stats.corrupted) {
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   570
            EC_WARN("%i frame%s CORRUPTED!\n", master->stats.corrupted,
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   571
                    master->stats.corrupted == 1 ? "" : "s");
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   572
            master->stats.corrupted = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   573
        }
332
e16093374dfd New statistic outputs to avoid blasting the logs.
Florian Pose <fp@igh-essen.com>
parents: 331
diff changeset
   574
        if (master->stats.skipped) {
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   575
            EC_WARN("%i datagram%s SKIPPED!\n", master->stats.skipped,
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   576
                    master->stats.skipped == 1 ? "" : "s");
332
e16093374dfd New statistic outputs to avoid blasting the logs.
Florian Pose <fp@igh-essen.com>
parents: 331
diff changeset
   577
            master->stats.skipped = 0;
e16093374dfd New statistic outputs to avoid blasting the logs.
Florian Pose <fp@igh-essen.com>
parents: 331
diff changeset
   578
        }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   579
        if (master->stats.unmatched) {
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   580
            EC_WARN("%i datagram%s UNMATCHED!\n", master->stats.unmatched,
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   581
                    master->stats.unmatched == 1 ? "" : "s");
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   582
            master->stats.unmatched = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   583
        }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   584
    }
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   585
}
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   586
68
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   587
/*****************************************************************************/
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   588
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   589
/**
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   590
   Starts the Idle mode.
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   591
*/
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   592
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   593
void ec_master_idle_start(ec_master_t *master /**< EtherCAT master */)
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   594
{
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   595
    if (master->mode == EC_MASTER_MODE_IDLE) return;
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   596
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   597
    if (master->mode == EC_MASTER_MODE_OPERATION) {
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   598
        EC_ERR("ec_master_idle_start: Master already running!\n");
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   599
        return;
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   600
    }
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   601
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   602
    EC_INFO("Starting Idle mode.\n");
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   603
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   604
    master->mode = EC_MASTER_MODE_IDLE;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   605
    ec_fsm_reset(&master->fsm);
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   606
    queue_delayed_work(master->workqueue, &master->idle_work, 1);
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   607
}
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   608
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   609
/*****************************************************************************/
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   610
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   611
/**
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   612
   Stops the Idle mode.
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   613
*/
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   614
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   615
void ec_master_idle_stop(ec_master_t *master /**< EtherCAT master */)
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   616
{
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   617
    if (master->mode != EC_MASTER_MODE_IDLE) return;
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   618
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   619
    ec_master_eoe_stop(master);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   620
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   621
    EC_INFO("Stopping Idle mode.\n");
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   622
    master->mode = EC_MASTER_MODE_ORPHANED; // this is important for the
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   623
                                            // IDLE work function to not
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   624
                                            // queue itself again
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   625
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   626
    if (!cancel_delayed_work(&master->idle_work)) {
236
34d7ce41e9db Started freerun state machine development.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
   627
        flush_workqueue(master->workqueue);
34d7ce41e9db Started freerun state machine development.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
   628
    }
34d7ce41e9db Started freerun state machine development.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
   629
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   630
    ec_master_clear_slaves(master);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   631
}
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   632
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   633
/*****************************************************************************/
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   634
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   635
/**
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   636
   Idle mode function.
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   637
*/
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   638
318
5f35e74124d1 Renamed ec_master_idle() to ec_master_idle_run().
Florian Pose <fp@igh-essen.com>
parents: 313
diff changeset
   639
void ec_master_idle_run(void *data /**< master pointer */)
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   640
{
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   641
    ec_master_t *master = (ec_master_t *) data;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   642
    cycles_t cycles_start, cycles_end;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   643
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   644
    // aquire master lock
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   645
    spin_lock_bh(&master->internal_lock);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   646
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   647
    cycles_start = get_cycles();
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   648
    ecrt_master_receive(master);
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   649
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   650
    // execute master state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   651
    ec_fsm_execute(&master->fsm);
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   652
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   653
    ecrt_master_send(master);
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   654
    cycles_end = get_cycles();
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   655
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   656
    // release master lock
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   657
    spin_unlock_bh(&master->internal_lock);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   658
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   659
    master->idle_cycle_times[master->idle_cycle_time_pos]
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   660
        = (u32) (cycles_end - cycles_start) * 1000 / cpu_khz;
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   661
    master->idle_cycle_time_pos++;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   662
    master->idle_cycle_time_pos %= HZ;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   663
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   664
    if (master->mode == EC_MASTER_MODE_IDLE)
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   665
        queue_delayed_work(master->workqueue, &master->idle_work, 1);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   666
}
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   667
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   668
/*****************************************************************************/
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   669
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   670
/**
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   671
   Initializes a sync manager configuration page with EEPROM data.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   672
   The referenced memory (\a data) must be at least EC_SYNC_SIZE bytes.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   673
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   674
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   675
void ec_sync_config(const ec_sii_sync_t *sync, /**< sync manager */
275
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 274
diff changeset
   676
                    const ec_slave_t *slave, /**< EtherCAT slave */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   677
                    uint8_t *data /**> configuration memory */
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   678
                    )
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   679
{
275
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 274
diff changeset
   680
    size_t sync_size;
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 274
diff changeset
   681
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 274
diff changeset
   682
    sync_size = ec_slave_calc_sync_size(slave, sync);
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 274
diff changeset
   683
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   684
    if (slave->master->debug_level) {
414
60cd2fcc71ee Added enable bit to sync manager debugging.
Florian Pose <fp@igh-essen.com>
parents: 413
diff changeset
   685
        EC_DBG("Slave %3i, SM %i: Addr 0x%04X, Size %3i, Ctrl 0x%02X, En %i\n",
413
a7144fdf14f5 Improved SM and FMMU debugging output.
Florian Pose <fp@igh-essen.com>
parents: 412
diff changeset
   686
               slave->ring_position, sync->index, sync->physical_start_address,
414
60cd2fcc71ee Added enable bit to sync manager debugging.
Florian Pose <fp@igh-essen.com>
parents: 413
diff changeset
   687
               sync_size, sync->control_register, sync->enable);
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   688
    }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   689
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   690
    EC_WRITE_U16(data,     sync->physical_start_address);
298
d491d1f84ebc Prefer EEPROM sync manager information for config.
Florian Pose <fp@igh-essen.com>
parents: 295
diff changeset
   691
    EC_WRITE_U16(data + 2, sync_size);
136
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   692
    EC_WRITE_U8 (data + 4, sync->control_register);
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   693
    EC_WRITE_U8 (data + 5, 0x00); // status byte (read only)
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   694
    EC_WRITE_U16(data + 6, sync->enable ? 0x0001 : 0x0000); // enable
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   695
}
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   696
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   697
/*****************************************************************************/
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   698
a03a684cac89 Dynamische Mailbox-Kommunikation, auch mit unbekannten Slaves.
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   699
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   700
   Initializes an FMMU configuration page.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   701
   The referenced memory (\a data) must be at least EC_FMMU_SIZE bytes.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   702
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   703
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   704
void ec_fmmu_config(const ec_fmmu_t *fmmu, /**< FMMU */
275
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 274
diff changeset
   705
                    const ec_slave_t *slave, /**< EtherCAT slave */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   706
                    uint8_t *data /**> configuration memory */
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   707
                    )
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   708
{
275
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 274
diff changeset
   709
    size_t sync_size;
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 274
diff changeset
   710
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 274
diff changeset
   711
    sync_size = ec_slave_calc_sync_size(slave, fmmu->sync);
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 274
diff changeset
   712
412
2e50ddc3e777 Added FMMU debugging.
Florian Pose <fp@igh-essen.com>
parents: 408
diff changeset
   713
    if (slave->master->debug_level) {
413
a7144fdf14f5 Improved SM and FMMU debugging output.
Florian Pose <fp@igh-essen.com>
parents: 412
diff changeset
   714
        EC_DBG("Slave %3i, FMMU %2i:"
a7144fdf14f5 Improved SM and FMMU debugging output.
Florian Pose <fp@igh-essen.com>
parents: 412
diff changeset
   715
               " LogAddr 0x%08X, Size %3i, PhysAddr 0x%04X, Dir %s\n",
a7144fdf14f5 Improved SM and FMMU debugging output.
Florian Pose <fp@igh-essen.com>
parents: 412
diff changeset
   716
               slave->ring_position, fmmu->index, fmmu->logical_start_address,
a7144fdf14f5 Improved SM and FMMU debugging output.
Florian Pose <fp@igh-essen.com>
parents: 412
diff changeset
   717
               sync_size, fmmu->sync->physical_start_address,
a7144fdf14f5 Improved SM and FMMU debugging output.
Florian Pose <fp@igh-essen.com>
parents: 412
diff changeset
   718
               ((fmmu->sync->control_register & 0x04) ? "out" : "in"));
412
2e50ddc3e777 Added FMMU debugging.
Florian Pose <fp@igh-essen.com>
parents: 408
diff changeset
   719
    }
2e50ddc3e777 Added FMMU debugging.
Florian Pose <fp@igh-essen.com>
parents: 408
diff changeset
   720
77
677967864795 EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents: 74
diff changeset
   721
    EC_WRITE_U32(data,      fmmu->logical_start_address);
275
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 274
diff changeset
   722
    EC_WRITE_U16(data + 4,  sync_size); // size of fmmu
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   723
    EC_WRITE_U8 (data + 6,  0x00); // logical start bit
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   724
    EC_WRITE_U8 (data + 7,  0x07); // logical end bit
77
677967864795 EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents: 74
diff changeset
   725
    EC_WRITE_U16(data + 8,  fmmu->sync->physical_start_address);
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   726
    EC_WRITE_U8 (data + 10, 0x00); // physical start bit
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   727
    EC_WRITE_U8 (data + 11, ((fmmu->sync->control_register & 0x04)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   728
                             ? 0x02 : 0x01));
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   729
    EC_WRITE_U16(data + 12, 0x0001); // enable
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   730
    EC_WRITE_U16(data + 14, 0x0000); // reserved
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   731
}
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   732
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   733
/*****************************************************************************/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   734
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   735
/**
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   736
   Formats master information for SysFS read access.
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   737
   \return number of bytes written
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   738
*/
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   739
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   740
ssize_t ec_master_info(ec_master_t *master, /**< EtherCAT master */
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   741
                       char *buffer /**< memory to store data */
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   742
                       )
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   743
{
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   744
    off_t off = 0;
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
   745
    ec_eoe_t *eoe;
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   746
    uint32_t cur, sum, min, max, pos, i;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   747
382
72500991bcc3 Altered master version string.
Florian Pose <fp@igh-essen.com>
parents: 381
diff changeset
   748
    off += sprintf(buffer + off, "\nVersion: " EC_MASTER_VERSION);
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   749
    off += sprintf(buffer + off, "\nMode: ");
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   750
    switch (master->mode) {
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   751
        case EC_MASTER_MODE_ORPHANED:
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   752
            off += sprintf(buffer + off, "ORPHANED");
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   753
            break;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   754
        case EC_MASTER_MODE_IDLE:
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   755
            off += sprintf(buffer + off, "IDLE");
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   756
            break;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   757
        case EC_MASTER_MODE_OPERATION:
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   758
            off += sprintf(buffer + off, "OPERATION");
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   759
            break;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   760
    }
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   761
339
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 337
diff changeset
   762
    off += sprintf(buffer + off, "\nSlaves: %i\n",
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   763
                   master->slave_count);
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   764
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   765
    off += sprintf(buffer + off, "\nTiming (min/avg/max) [us]:\n");
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   766
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   767
    sum = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   768
    min = 0xFFFFFFFF;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   769
    max = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   770
    pos = master->idle_cycle_time_pos;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   771
    for (i = 0; i < HZ; i++) {
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   772
        cur = master->idle_cycle_times[(i + pos) % HZ];
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   773
        sum += cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   774
        if (cur < min) min = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   775
        if (cur > max) max = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   776
    }
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   777
    off += sprintf(buffer + off, "  Idle cycle: %u / %u.%u / %u\n",
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   778
                   min, sum / HZ, (sum * 100 / HZ) % 100, max);
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   779
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   780
    sum = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   781
    min = 0xFFFFFFFF;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   782
    max = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   783
    pos = master->eoe_cycle_time_pos;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   784
    for (i = 0; i < HZ; i++) {
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   785
        cur = master->eoe_cycle_times[(i + pos) % HZ];
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   786
        sum += cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   787
        if (cur < min) min = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   788
        if (cur > max) max = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   789
    }
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   790
    off += sprintf(buffer + off, "  EoE cycle: %u / %u.%u / %u\n",
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   791
                   min, sum / HZ, (sum * 100 / HZ) % 100, max);
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   792
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
   793
    if (!list_empty(&master->eoe_handlers))
339
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 337
diff changeset
   794
        off += sprintf(buffer + off, "\nEoE statistics (RX/TX) [bps]:\n");
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
   795
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
341
f8aa65e05ff4 Added EoE rate in KB/s to master info.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   796
        off += sprintf(buffer + off, "  %s: %u / %u (%u KB/s)\n",
f8aa65e05ff4 Added EoE rate in KB/s to master info.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   797
                       eoe->dev->name, eoe->rx_rate, eoe->tx_rate,
f8aa65e05ff4 Added EoE rate in KB/s to master info.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   798
                       ((eoe->rx_rate + eoe->tx_rate) / 8 + 512) / 1024);
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
   799
    }
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
   800
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   801
    off += sprintf(buffer + off, "\n");
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   802
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   803
    return off;
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   804
}
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   805
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   806
/*****************************************************************************/
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   807
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   808
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   809
   Formats attribute data for SysFS read access.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   810
   \return number of bytes to read
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   811
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   812
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   813
ssize_t ec_show_master_attribute(struct kobject *kobj, /**< kobject */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   814
                                 struct attribute *attr, /**< attribute */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   815
                                 char *buffer /**< memory to store data */
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   816
                                 )
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   817
{
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   818
    ec_master_t *master = container_of(kobj, ec_master_t, kobj);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   819
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   820
    if (attr == &attr_info) {
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   821
        return ec_master_info(master, buffer);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   822
    }
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   823
    else if (attr == &attr_debug_level) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   824
        return sprintf(buffer, "%i\n", master->debug_level);
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   825
    }
313
ba324d82dfd3 Reading of eeprom_write_enable.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
   826
    else if (attr == &attr_eeprom_write_enable) {
ba324d82dfd3 Reading of eeprom_write_enable.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
   827
        return sprintf(buffer, "%i\n", master->eeprom_write_enable);
ba324d82dfd3 Reading of eeprom_write_enable.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
   828
    }
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   829
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   830
    return 0;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   831
}
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   832
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   833
/*****************************************************************************/
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   834
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   835
/**
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   836
   Formats attribute data for SysFS write access.
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   837
   \return number of bytes processed, or negative error code
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   838
*/
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   839
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   840
ssize_t ec_store_master_attribute(struct kobject *kobj, /**< slave's kobject */
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   841
                                  struct attribute *attr, /**< attribute */
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   842
                                  const char *buffer, /**< memory with data */
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   843
                                  size_t size /**< size of data to store */
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   844
                                  )
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   845
{
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   846
    ec_master_t *master = container_of(kobj, ec_master_t, kobj);
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   847
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   848
    if (attr == &attr_eeprom_write_enable) {
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   849
        if (!strcmp(buffer, "1\n")) {
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   850
            master->eeprom_write_enable = 1;
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   851
            EC_INFO("Slave EEPROM writing enabled.\n");
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   852
            return size;
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   853
        }
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   854
        else if (!strcmp(buffer, "0\n")) {
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   855
            master->eeprom_write_enable = 0;
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   856
            EC_INFO("Slave EEPROM writing disabled.\n");
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   857
            return size;
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   858
        }
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   859
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   860
        EC_ERR("Invalid value for eeprom_write_enable!\n");
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   861
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   862
        if (master->eeprom_write_enable) {
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   863
            master->eeprom_write_enable = 0;
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   864
            EC_INFO("Slave EEPROM writing disabled.\n");
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   865
        }
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   866
    }
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   867
    else if (attr == &attr_debug_level) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   868
        if (!strcmp(buffer, "0\n")) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   869
            master->debug_level = 0;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   870
        }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   871
        else if (!strcmp(buffer, "1\n")) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   872
            master->debug_level = 1;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   873
        }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   874
        else if (!strcmp(buffer, "2\n")) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   875
            master->debug_level = 2;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   876
        }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   877
        else {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   878
            EC_ERR("Invalid debug level value!\n");
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   879
            return -EINVAL;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   880
        }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   881
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   882
        EC_INFO("Master debug level set to %i.\n", master->debug_level);
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   883
        return size;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   884
    }
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   885
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   886
    return -EINVAL;
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   887
}
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   888
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   889
/*****************************************************************************/
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   890
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   891
/**
326
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   892
   Starts Ethernet-over-EtherCAT processing on demand.
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   893
*/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   894
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   895
void ec_master_eoe_start(ec_master_t *master /**< EtherCAT master */)
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   896
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   897
    ec_eoe_t *eoe;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   898
    ec_slave_t *slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   899
    unsigned int coupled, found;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   900
326
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   901
    if (master->eoe_running || master->eoe_checked) return;
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   902
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   903
    master->eoe_checked = 1;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   904
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   905
    // if the locking callbacks are not set in operation mode,
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   906
    // the EoE timer my not be started.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   907
    if (master->mode == EC_MASTER_MODE_OPERATION
326
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   908
        && (!master->request_cb || !master->release_cb)) {
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   909
        EC_INFO("No EoE processing because of missing locking callbacks.\n");
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   910
        return;
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   911
    }
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   912
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   913
    // decouple all EoE handlers
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   914
    list_for_each_entry(eoe, &master->eoe_handlers, list)
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   915
        eoe->slave = NULL;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   916
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   917
    // couple a free EoE handler to every EoE-capable slave
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   918
    coupled = 0;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   919
    list_for_each_entry(slave, &master->slaves, list) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   920
        if (!(slave->sii_mailbox_protocols & EC_MBOX_EOE)) continue;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   921
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   922
        found = 0;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   923
        list_for_each_entry(eoe, &master->eoe_handlers, list) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   924
            if (eoe->slave) continue;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   925
            eoe->slave = slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   926
            found = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   927
            coupled++;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   928
            EC_INFO("Coupling device %s to slave %i.\n",
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   929
                    eoe->dev->name, slave->ring_position);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   930
            if (eoe->opened) slave->requested_state = EC_SLAVE_STATE_OP;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   931
            else slave->requested_state = EC_SLAVE_STATE_INIT;
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 278
diff changeset
   932
            slave->error_flag = 0;
253
6dd3e49dbb85 Fixed bug with coupling multiple EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 252
diff changeset
   933
            break;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   934
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   935
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   936
        if (!found) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   937
            EC_WARN("No EoE handler for slave %i!\n", slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   938
            slave->requested_state = EC_SLAVE_STATE_INIT;
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 278
diff changeset
   939
            slave->error_flag = 0;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   940
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   941
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   942
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   943
    if (!coupled) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   944
        EC_INFO("No EoE handlers coupled.\n");
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   945
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   946
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   947
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   948
    EC_INFO("Starting EoE processing.\n");
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   949
    master->eoe_running = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   950
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   951
    // start EoE processing
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   952
    master->eoe_timer.expires = jiffies + 10;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   953
    add_timer(&master->eoe_timer);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   954
    return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   955
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   956
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   957
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   958
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   959
/**
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   960
   Stops the Ethernet-over-EtherCAT processing.
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   961
*/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   962
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   963
void ec_master_eoe_stop(ec_master_t *master /**< EtherCAT master */)
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   964
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   965
    ec_eoe_t *eoe;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   966
326
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   967
    master->eoe_checked = 0;
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   968
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   969
    if (!master->eoe_running) return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   970
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   971
    EC_INFO("Stopping EoE processing.\n");
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   972
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   973
    del_timer_sync(&master->eoe_timer);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   974
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   975
    // decouple all EoE handlers
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   976
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   977
        if (eoe->slave) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   978
            eoe->slave->requested_state = EC_SLAVE_STATE_INIT;
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 278
diff changeset
   979
            eoe->slave->error_flag = 0;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   980
            eoe->slave = NULL;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   981
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   982
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   983
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   984
    master->eoe_running = 0;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   985
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   986
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   987
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   988
/**
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   989
   Does the Ethernet-over-EtherCAT processing.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   990
*/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   991
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   992
void ec_master_eoe_run(unsigned long data /**< master pointer */)
206
60a10d85c20b Prepared EoE processing with workqueue.
Florian Pose <fp@igh-essen.com>
parents: 204
diff changeset
   993
{
60a10d85c20b Prepared EoE processing with workqueue.
Florian Pose <fp@igh-essen.com>
parents: 204
diff changeset
   994
    ec_master_t *master = (ec_master_t *) data;
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   995
    ec_eoe_t *eoe;
235
f973808540a6 No master locking, if no EoE devices are "up".
Florian Pose <fp@igh-essen.com>
parents: 228
diff changeset
   996
    unsigned int active = 0;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   997
    cycles_t cycles_start, cycles_end;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   998
    unsigned long restart_jiffies;
235
f973808540a6 No master locking, if no EoE devices are "up".
Florian Pose <fp@igh-essen.com>
parents: 228
diff changeset
   999
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1000
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
235
f973808540a6 No master locking, if no EoE devices are "up".
Florian Pose <fp@igh-essen.com>
parents: 228
diff changeset
  1001
        if (ec_eoe_active(eoe)) active++;
f973808540a6 No master locking, if no EoE devices are "up".
Florian Pose <fp@igh-essen.com>
parents: 228
diff changeset
  1002
    }
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1003
    if (!active) goto queue_timer;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1004
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1005
    // aquire master lock...
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1006
    if (master->mode == EC_MASTER_MODE_OPERATION) {
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1007
        // request_cb must return 0, if the lock has been aquired!
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1008
        if (master->request_cb(master->cb_data))
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1009
            goto queue_timer;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1010
    }
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
  1011
    else if (master->mode == EC_MASTER_MODE_IDLE) {
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1012
        spin_lock(&master->internal_lock);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1013
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1014
    else
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1015
        goto queue_timer;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1016
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1017
    // actual EoE processing
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1018
    cycles_start = get_cycles();
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1019
    ecrt_master_receive(master);
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1020
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1021
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1022
        ec_eoe_run(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1023
    }
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1024
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1025
    ecrt_master_send(master);
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1026
    cycles_end = get_cycles();
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1027
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1028
    // release lock...
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1029
    if (master->mode == EC_MASTER_MODE_OPERATION) {
228
ec516cfa207e Added EC_EOE_FREQUENCY
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
  1030
        master->release_cb(master->cb_data);
ec516cfa207e Added EC_EOE_FREQUENCY
Florian Pose <fp@igh-essen.com>
parents: 226
diff changeset
  1031
    }
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
  1032
    else if (master->mode == EC_MASTER_MODE_IDLE) {
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1033
        spin_unlock(&master->internal_lock);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1034
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1035
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1036
    master->eoe_cycle_times[master->eoe_cycle_time_pos]
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1037
        = (u32) (cycles_end - cycles_start) * 1000 / cpu_khz;
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1038
    master->eoe_cycle_time_pos++;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1039
    master->eoe_cycle_time_pos %= HZ;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1040
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1041
 queue_timer:
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1042
    restart_jiffies = HZ / EC_EOE_FREQUENCY;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1043
    if (!restart_jiffies) restart_jiffies = 1;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1044
    master->eoe_timer.expires += restart_jiffies;
208
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
  1045
    add_timer(&master->eoe_timer);
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1046
}
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1047
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1048
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1049
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1050
/**
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1051
   Calculates Advanced Position Adresses.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1052
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1053
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1054
void ec_master_calc_addressing(ec_master_t *master /**< EtherCAT master */)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1055
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1056
    uint16_t coupler_index, coupler_subindex;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1057
    uint16_t reverse_coupler_index, current_coupler_index;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1058
    ec_slave_t *slave;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1059
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1060
    coupler_index = 0;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1061
    reverse_coupler_index = 0xFFFF;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1062
    current_coupler_index = 0x0000;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1063
    coupler_subindex = 0;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1064
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1065
    list_for_each_entry(slave, &master->slaves, list) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1066
        if (ec_slave_is_coupler(slave)) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1067
            if (slave->sii_alias)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1068
                current_coupler_index = reverse_coupler_index--;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1069
            else
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1070
                current_coupler_index = coupler_index++;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1071
            coupler_subindex = 0;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1072
        }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1073
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1074
        slave->coupler_index = current_coupler_index;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1075
        slave->coupler_subindex = coupler_subindex;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1076
        coupler_subindex++;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1077
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1078
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1079
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1080
/*****************************************************************************/
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1081
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1082
/**
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1083
   Measures the time, a frame is on the bus.
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1084
   \return 0 in case of success, else < 0
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1085
*/
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1086
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1087
int ec_master_measure_bus_time(ec_master_t *master)
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1088
{
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1089
    ec_datagram_t datagram;
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1090
    uint32_t cur, sum, min, max, i;
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1091
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1092
    ec_datagram_init(&datagram);
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1093
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1094
    if (ec_datagram_brd(&datagram, 0x130, 2)) {
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1095
        EC_ERR("Failed to allocate datagram for bus time measuring.\n");
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1096
        ec_datagram_clear(&datagram);
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1097
        return -1;
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1098
    }
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1099
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1100
    ecrt_master_receive(master);
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1101
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1102
    sum = 0;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1103
    min = 0xFFFFFFFF;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1104
    max = 0;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1105
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1106
    for (i = 0; i < 100; i++) {
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1107
        ec_master_queue_datagram(master, &datagram);
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1108
        ecrt_master_send(master);
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1109
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1110
        while (1) {
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1111
            ecrt_master_receive(master);
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1112
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1113
            if (datagram.state == EC_DATAGRAM_RECEIVED) {
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1114
                break;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1115
            }
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1116
            else if (datagram.state == EC_DATAGRAM_ERROR) {
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1117
                EC_WARN("Failed to measure bus time.\n");
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1118
                goto error;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1119
            }
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1120
            else if (datagram.state == EC_DATAGRAM_TIMED_OUT) {
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1121
                EC_WARN("Timeout while measuring bus time.\n");
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1122
                goto error;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1123
            }
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1124
        }
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1125
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1126
        cur = (unsigned int) (datagram.cycles_received
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1127
                              - datagram.cycles_sent) * 1000 / cpu_khz;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1128
        sum += cur;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1129
        if (cur > max) max = cur;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1130
        if (cur < min) min = cur;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1131
    }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1132
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1133
    EC_INFO("Bus time is (min/avg/max) %u / %u.%u / %u us.\n",
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1134
            min, sum / 100, sum % 100, max);
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1135
    ec_datagram_clear(&datagram);
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1136
    return 0;
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1137
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1138
  error:
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1139
    ec_datagram_clear(&datagram);
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1140
    return -1;
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1141
}
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1142
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1143
/******************************************************************************
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1144
 *  Realtime interface
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1145
 *****************************************************************************/
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1146
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1147
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1148
   Creates a domain.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1149
   \return pointer to new domain on success, else NULL
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1150
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1151
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1152
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1153
ec_domain_t *ecrt_master_create_domain(ec_master_t *master /**< master */)
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1154
{
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1155
    ec_domain_t *domain, *last_domain;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1156
    unsigned int index;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1157
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1158
    if (!(domain = (ec_domain_t *) kmalloc(sizeof(ec_domain_t), GFP_KERNEL))) {
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 82
diff changeset
  1159
        EC_ERR("Error allocating domain memory!\n");
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1160
        goto out_return;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1161
    }
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1162
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1163
    if (list_empty(&master->domains)) index = 0;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1164
    else {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1165
        last_domain = list_entry(master->domains.prev, ec_domain_t, list);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1166
        index = last_domain->index + 1;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1167
    }
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1168
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1169
    if (ec_domain_init(domain, master, index)) {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1170
        EC_ERR("Failed to init domain.\n");
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1171
        goto out_return;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1172
    }
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1173
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1174
    if (kobject_add(&domain->kobj)) {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1175
        EC_ERR("Failed to add domain kobject.\n");
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1176
        goto out_put;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1177
    }
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1178
95
0066de7a456d Domains als Liste verwaltet.
Florian Pose <fp@igh-essen.com>
parents: 94
diff changeset
  1179
    list_add_tail(&domain->list, &master->domains);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1180
    return domain;
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1181
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1182
 out_put:
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1183
    kobject_put(&domain->kobj);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1184
 out_return:
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1185
    return NULL;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1186
}
61
cd014255f94f register_slave_list() und Bugfix in deactivate_slaves()
Florian Pose <fp@igh-essen.com>
parents: 58
diff changeset
  1187
74
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1188
/*****************************************************************************/
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1189
61
cd014255f94f register_slave_list() und Bugfix in deactivate_slaves()
Florian Pose <fp@igh-essen.com>
parents: 58
diff changeset
  1190
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1191
   Configures all slaves and leads them to the OP state.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1192
   Does the complete configuration and activation for all slaves. Sets sync
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1193
   managers and FMMUs, and does the appropriate transitions, until the slave
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1194
   is operational.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1195
   \return 0 in case of success, else < 0
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1196
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1197
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1198
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1199
int ecrt_master_activate(ec_master_t *master /**< EtherCAT master */)
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1200
{
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1201
    uint32_t domain_offset;
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 82
diff changeset
  1202
    ec_domain_t *domain;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1203
    ec_fsm_t *fsm = &master->fsm;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1204
    ec_slave_t *slave;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1205
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1206
    // allocate all domains
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1207
    domain_offset = 0;
95
0066de7a456d Domains als Liste verwaltet.
Florian Pose <fp@igh-essen.com>
parents: 94
diff changeset
  1208
    list_for_each_entry(domain, &master->domains, list) {
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1209
        if (ec_domain_alloc(domain, domain_offset)) {
95
0066de7a456d Domains als Liste verwaltet.
Florian Pose <fp@igh-essen.com>
parents: 94
diff changeset
  1210
            EC_ERR("Failed to allocate domain %X!\n", (u32) domain);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1211
            return -1;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1212
        }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1213
        domain_offset += domain->data_size;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1214
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1215
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1216
    // determine initial states.
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 179
diff changeset
  1217
    list_for_each_entry(slave, &master->slaves, list) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1218
        if (ec_slave_is_coupler(slave) || slave->registered) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1219
            slave->requested_state = EC_SLAVE_STATE_OP;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1220
        }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1221
        else {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1222
            slave->requested_state = EC_SLAVE_STATE_PREOP;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1223
        }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1224
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1225
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1226
    ec_fsm_configuration(fsm); // init configuration state machine
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1227
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1228
    do {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1229
        ec_fsm_execute(fsm);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1230
        ec_master_sync_io(master);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1231
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1232
    while (ec_fsm_configuration_running(fsm));
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1233
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1234
    if (!ec_fsm_configuration_success(fsm)) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1235
        return -1;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1236
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1237
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1238
    ec_fsm_reset(&master->fsm); // prepare for operation state machine
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1239
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1240
    return 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1241
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1242
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1243
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1244
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1245
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1246
   Resets all slaves to INIT state.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1247
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1248
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1249
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1250
void ecrt_master_deactivate(ec_master_t *master /**< EtherCAT master */)
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1251
{
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1252
    ec_fsm_t *fsm = &master->fsm;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1253
    ec_slave_t *slave;
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 179
diff changeset
  1254
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 179
diff changeset
  1255
    list_for_each_entry(slave, &master->slaves, list) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1256
        slave->requested_state = EC_SLAVE_STATE_INIT;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1257
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1258
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1259
    ec_fsm_configuration(fsm); // init configuration state machine
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1260
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1261
    do {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1262
        ec_fsm_execute(fsm);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1263
        ec_master_sync_io(master);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1264
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1265
    while (ec_fsm_configuration_running(fsm));
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
  1266
}
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 133
diff changeset
  1267
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1268
/*****************************************************************************/
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1269
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1270
/**
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1271
   Sends queued datagrams and waits for their reception.
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1272
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1273
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1274
void ec_master_sync_io(ec_master_t *master /**< EtherCAT master */)
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1275
{
345
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1276
    ec_datagram_t *datagram;
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1277
    unsigned int datagrams_waiting;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1278
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1279
    // send datagrams
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1280
    ecrt_master_send(master);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1281
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1282
    while (1) { // active waiting
345
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1283
        ecrt_master_receive(master); // receive and dequeue datagrams
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1284
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1285
        // count number of datagrams still waiting for response
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1286
        datagrams_waiting = 0;
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1287
        list_for_each_entry(datagram, &master->datagram_queue, queue) {
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1288
            datagrams_waiting++;
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1289
        }
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1290
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1291
        // if there are no more datagrams waiting, abort loop.
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1292
        if (!datagrams_waiting) break;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1293
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1294
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1295
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1296
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1297
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1298
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1299
   Asynchronous sending of datagrams.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1300
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1301
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1302
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1303
void ecrt_master_send(ec_master_t *master /**< EtherCAT master */)
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1304
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1305
    ec_datagram_t *datagram, *n;
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1306
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1307
    if (unlikely(!master->device->link_state)) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1308
        // link is down, no datagram can be sent
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1309
        list_for_each_entry_safe(datagram, n, &master->datagram_queue, queue) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1310
            datagram->state = EC_DATAGRAM_ERROR;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1311
            list_del_init(&datagram->queue);
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1312
        }
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1313
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1314
        // query link state
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1315
        ec_device_call_isr(master->device);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1316
        return;
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1317
    }
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1318
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1319
    // send frames
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1320
    ec_master_send_datagrams(master);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1321
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1322
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1323
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1324
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1325
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1326
   Asynchronous receiving of datagrams.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1327
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1328
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1329
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1330
void ecrt_master_receive(ec_master_t *master /**< EtherCAT master */)
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1331
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1332
    ec_datagram_t *datagram, *next;
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1333
    cycles_t cycles_timeout;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1334
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1335
    // receive datagrams
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1336
    ec_device_call_isr(master->device);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1337
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1338
    cycles_timeout = (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000);
208
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
  1339
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1340
    // dequeue all datagrams that timed out
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1341
    list_for_each_entry_safe(datagram, next, &master->datagram_queue, queue) {
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1342
        switch (datagram->state) {
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1343
            case EC_DATAGRAM_QUEUED:
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1344
                if (master->device->cycles_isr
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1345
                    - datagram->cycles_queued > cycles_timeout) {
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1346
                    list_del_init(&datagram->queue);
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1347
                    datagram->state = EC_DATAGRAM_TIMED_OUT;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1348
                    master->stats.timeouts++;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1349
                    ec_master_output_stats(master);
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1350
                }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1351
                break;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1352
            case EC_DATAGRAM_SENT:
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1353
                if (master->device->cycles_isr
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1354
                    - datagram->cycles_sent > cycles_timeout) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1355
                    list_del_init(&datagram->queue);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1356
                    datagram->state = EC_DATAGRAM_TIMED_OUT;
208
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
  1357
                    master->stats.timeouts++;
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
  1358
                    ec_master_output_stats(master);
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
  1359
                }
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1360
                break;
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1361
            default:
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1362
                break;
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1363
        }
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1364
    }
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1365
}
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1366
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1367
/*****************************************************************************/
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1368
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1369
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1370
   Prepares synchronous IO.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1371
   Queues all domain datagrams and sends them. Then waits a certain time, so
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1372
   that ecrt_master_receive() can be called securely.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1373
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1374
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1375
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1376
void ecrt_master_prepare(ec_master_t *master /**< EtherCAT master */)
106
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1377
{
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1378
    ec_domain_t *domain;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1379
    cycles_t cycles_start, cycles_end, cycles_timeout;
106
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1380
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1381
    // queue datagrams of all domains
106
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1382
    list_for_each_entry(domain, &master->domains, list)
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1383
        ec_domain_queue(domain);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1384
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1385
    ecrt_master_send(master);
106
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1386
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1387
    cycles_start = get_cycles();
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1388
    cycles_timeout = (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000);
106
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1389
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1390
    // active waiting
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 111
diff changeset
  1391
    while (1) {
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1392
        udelay(100);
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1393
        cycles_end = get_cycles();
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1394
        if (cycles_end - cycles_start >= cycles_timeout) break;
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 111
diff changeset
  1395
    }
106
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1396
}
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1397
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1398
/*****************************************************************************/
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1399
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1400
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1401
   Does all cyclic master work.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1402
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1403
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1404
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1405
void ecrt_master_run(ec_master_t *master /**< EtherCAT master */)
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1406
{
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1407
    // output statistics
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1408
    ec_master_output_stats(master);
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1409
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
  1410
    // execute master state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
  1411
    ec_fsm_execute(&master->fsm);
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1412
}
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1413
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1414
/*****************************************************************************/
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1415
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1416
/**
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1417
   Translates an ASCII coded bus-address to a slave pointer.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1418
   These are the valid addressing schemes:
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1419
   - \a "X" = the X. slave on the bus,
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1420
   - \a "X:Y" = the Y. slave after the X. branch (bus coupler),
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1421
   - \a "#X" = the slave with alias X,
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1422
   - \a "#X:Y" = the Y. slave after the branch (bus coupler) with alias X.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1423
   X and Y are zero-based indices and may be provided in hexadecimal or octal
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1424
   notation (with respective prefix).
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1425
   \return pointer to the slave on success, else NULL
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1426
   \ingroup RealtimeInterface
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1427
*/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1428
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1429
ec_slave_t *ecrt_master_get_slave(const ec_master_t *master, /**< Master */
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1430
                                  const char *address /**< address string */
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1431
                                  )
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1432
{
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1433
    unsigned long first, second;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1434
    char *remainder, *remainder2;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1435
    unsigned int alias_requested, alias_found;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1436
    ec_slave_t *alias_slave = NULL, *slave;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1437
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1438
    if (!address || address[0] == 0) return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1439
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1440
    alias_requested = 0;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1441
    if (address[0] == '#') {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1442
        alias_requested = 1;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1443
        address++;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1444
    }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1445
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1446
    first = simple_strtoul(address, &remainder, 0);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1447
    if (remainder == address) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1448
        EC_ERR("Slave address \"%s\" - First number empty!\n", address);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1449
        return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1450
    }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1451
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1452
    if (alias_requested) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1453
        alias_found = 0;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1454
        list_for_each_entry(alias_slave, &master->slaves, list) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1455
            if (alias_slave->sii_alias == first) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1456
                alias_found = 1;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1457
                break;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1458
            }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1459
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1460
        if (!alias_found) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1461
            EC_ERR("Slave address \"%s\" - Alias not found!\n", address);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1462
            return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1463
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1464
    }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1465
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1466
    if (!remainder[0]) { // absolute position
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1467
        if (alias_requested) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1468
            return alias_slave;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1469
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1470
        else {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1471
            list_for_each_entry(slave, &master->slaves, list) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1472
                if (slave->ring_position == first) return slave;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1473
            }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1474
            EC_ERR("Slave address \"%s\" - Absolute position invalid!\n",
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1475
                   address);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1476
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1477
    }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1478
    else if (remainder[0] == ':') { // field position
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1479
        remainder++;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1480
        second = simple_strtoul(remainder, &remainder2, 0);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1481
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1482
        if (remainder2 == remainder) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1483
            EC_ERR("Slave address \"%s\" - Second number empty!\n", address);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1484
            return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1485
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1486
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1487
        if (remainder2[0]) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1488
            EC_ERR("Slave address \"%s\" - Invalid trailer!\n", address);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1489
            return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1490
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1491
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1492
        if (alias_requested) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1493
            if (!ec_slave_is_coupler(alias_slave)) {
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1494
                EC_ERR("Slave address \"%s\": Alias slave must be bus coupler"
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1495
                       " in colon mode.\n", address);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1496
                return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1497
            }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1498
            list_for_each_entry(slave, &master->slaves, list) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1499
                if (slave->coupler_index == alias_slave->coupler_index
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1500
                    && slave->coupler_subindex == second)
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1501
                    return slave;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1502
            }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1503
            EC_ERR("Slave address \"%s\" - Bus coupler %i has no %lu. slave"
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1504
                   " following!\n", address, alias_slave->ring_position,
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1505
                   second);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1506
            return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1507
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1508
        else {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1509
            list_for_each_entry(slave, &master->slaves, list) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1510
                if (slave->coupler_index == first
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1511
                    && slave->coupler_subindex == second) return slave;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1512
            }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1513
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1514
    }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1515
    else
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1516
        EC_ERR("Slave address \"%s\" - Invalid format!\n", address);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1517
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1518
    return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1519
}
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1520
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1521
/*****************************************************************************/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1522
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1523
/**
204
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1524
   Sets the locking callbacks.
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
  1525
   The request_cb function must return zero, to allow another instance
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
  1526
   (the EoE process for example) to access the master. Non-zero means,
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
  1527
   that access is forbidden at this time.
204
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1528
   \ingroup RealtimeInterface
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1529
*/
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1530
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1531
void ecrt_master_callbacks(ec_master_t *master, /**< EtherCAT master */
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1532
                           int (*request_cb)(void *), /**< request lock CB */
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1533
                           void (*release_cb)(void *), /**< release lock CB */
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1534
                           void *cb_data /**< data parameter */
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1535
                           )
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1536
{
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1537
    master->request_cb = request_cb;
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1538
    master->release_cb = release_cb;
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1539
    master->cb_data = cb_data;
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1540
}
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1541
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1542
/*****************************************************************************/
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1543
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1544
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1545
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1546
EXPORT_SYMBOL(ecrt_master_create_domain);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1547
EXPORT_SYMBOL(ecrt_master_activate);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1548
EXPORT_SYMBOL(ecrt_master_deactivate);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1549
EXPORT_SYMBOL(ecrt_master_prepare);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1550
EXPORT_SYMBOL(ecrt_master_send);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1551
EXPORT_SYMBOL(ecrt_master_receive);
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1552
EXPORT_SYMBOL(ecrt_master_run);
206
60a10d85c20b Prepared EoE processing with workqueue.
Florian Pose <fp@igh-essen.com>
parents: 204
diff changeset
  1553
EXPORT_SYMBOL(ecrt_master_callbacks);
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 136
diff changeset
  1554
EXPORT_SYMBOL(ecrt_master_get_slave);
42
a22a202d0f42 Domains, Warten beim Senden, 10kHz.
Florian Pose <fp@igh-essen.com>
parents: 39
diff changeset
  1555
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1556
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1557
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1558
/*****************************************************************************/