master/master.c
author Florian Pose <fp@igh-essen.com>
Thu, 08 Mar 2007 13:02:42 +0000
changeset 637 d5d04c868e0e
parent 612 aede068f9a74
child 639 aa23c48dca2d
permissions -rw-r--r--
Removed ecrt_master_run(), removed datagram queueing from state
machines, added datagram injection, two different master thread
functions.
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 *);
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
    58
void ec_master_destroy_domains(ec_master_t *);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
    59
void ec_master_sync_io(ec_master_t *);
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
    60
static int ec_master_idle_thread(ec_master_t *);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
    61
static int ec_master_operation_thread(ec_master_t *);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    62
void ec_master_eoe_run(unsigned long);
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
    63
void ec_master_check_sdo(unsigned long);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
    64
int ec_master_measure_bus_time(ec_master_t *);
179
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    65
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
    66
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
    67
                                  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
    68
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    69
/*****************************************************************************/
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    70
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    71
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    72
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
    73
EC_SYSFS_READ_ATTR(info);
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
    74
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
    75
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    76
static struct attribute *ec_def_attrs[] = {
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
    77
    &attr_info,
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
    78
    &attr_debug_level,
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    79
    NULL,
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    80
};
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    81
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    82
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
    83
    .show = &ec_show_master_attribute,
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
    84
    .store = ec_store_master_attribute
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    85
};
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    86
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    87
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
    88
    .release = ec_master_clear,
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    89
    .sysfs_ops = &ec_sysfs_ops,
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    90
    .default_attrs = ec_def_attrs
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    91
};
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    92
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    93
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    94
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    95
/*****************************************************************************/
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    96
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    98
   Master constructor.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    99
   \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
   100
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   101
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   102
int ec_master_init(ec_master_t *master, /**< EtherCAT master */
576
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   103
        struct kobject *module_kobj, /**< kobject of the master module */
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   104
        unsigned int index, /**< master index */
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   105
        const ec_device_id_t *main_id, /**< ID of main device */
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   106
        const ec_device_id_t *backup_id, /**< ID of main device */
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   107
        unsigned int eoeif_count /**< number of EoE interfaces */
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   108
        )
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   109
{
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   110
    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
   111
    unsigned int i;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   112
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   113
    atomic_set(&master->available, 1);
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   114
    master->index = index;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   115
573
cdee4ea90ce9 Introduced device IDs; removed comment lines from 8139too; removed
Florian Pose <fp@igh-essen.com>
parents: 571
diff changeset
   116
    master->main_device_id = main_id;
cdee4ea90ce9 Introduced device IDs; removed comment lines from 8139too; removed
Florian Pose <fp@igh-essen.com>
parents: 571
diff changeset
   117
    master->backup_device_id = backup_id;
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   118
    init_MUTEX(&master->device_sem);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   119
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   120
    master->mode = EC_MASTER_MODE_ORPHANED;
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   121
    master->injection_seq_fsm = 0;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   122
    master->injection_seq_rt = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   123
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 179
diff changeset
   124
    INIT_LIST_HEAD(&master->slaves);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   125
    master->slave_count = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   126
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   127
    INIT_LIST_HEAD(&master->datagram_queue);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   128
    master->datagram_index = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   129
95
0066de7a456d Domains als Liste verwaltet.
Florian Pose <fp@igh-essen.com>
parents: 94
diff changeset
   130
    INIT_LIST_HEAD(&master->domains);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   131
    master->debug_level = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   132
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   133
    master->stats.timeouts = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   134
    master->stats.corrupted = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   135
    master->stats.skipped = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   136
    master->stats.unmatched = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   137
    master->stats.output_jiffies = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   138
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   139
    for (i = 0; i < HZ; i++) {
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   140
        master->idle_cycle_times[i] = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   141
        master->eoe_cycle_times[i] = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   142
    }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   143
    master->idle_cycle_time_pos = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   144
    master->eoe_cycle_time_pos = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   145
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   146
    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
   147
    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
   148
    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
   149
    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
   150
    master->eoe_checked = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   151
    INIT_LIST_HEAD(&master->eoe_handlers);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   152
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   153
    master->internal_lock = SPIN_LOCK_UNLOCKED;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   154
    master->request_cb = NULL;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   155
    master->release_cb = NULL;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   156
    master->cb_data = NULL;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   157
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 597
diff changeset
   158
    INIT_LIST_HEAD(&master->eeprom_requests);
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 597
diff changeset
   159
    init_MUTEX(&master->eeprom_sem);
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 597
diff changeset
   160
    init_waitqueue_head(&master->eeprom_queue);
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 597
diff changeset
   161
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   162
    master->sdo_request = NULL;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   163
    master->sdo_seq_user = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   164
    master->sdo_seq_master = 0;
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   165
    init_MUTEX(&master->sdo_sem);
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   166
    init_timer(&master->sdo_timer);
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   167
    master->sdo_timer.function = ec_master_check_sdo;
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   168
    master->sdo_timer.data = (unsigned long) master;
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   169
    init_completion(&master->sdo_complete);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   170
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   171
    // init devices
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   172
    if (ec_device_init(&master->main_device, master))
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   173
        goto out_return;
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   174
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   175
    if (ec_device_init(&master->backup_device, master))
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   176
        goto out_clear_main;
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   177
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   178
    // 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
   179
    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
   180
        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
   181
            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
   182
            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
   183
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   184
        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
   185
            kfree(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   186
            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
   187
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   188
        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
   189
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   190
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   191
    // init state machine datagram
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   192
    ec_datagram_init(&master->fsm_datagram);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   193
    if (ec_datagram_prealloc(&master->fsm_datagram, EC_MAX_DATA_SIZE)) {
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   194
        EC_ERR("Failed to allocate FSM datagram.\n");
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   195
        goto out_clear_eoe;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   196
    }
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   197
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   198
    // create state machine object
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   199
    ec_fsm_master_init(&master->fsm, master, &master->fsm_datagram);
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   200
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   201
    // 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
   202
    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
   203
    kobject_init(&master->kobj);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   204
    master->kobj.ktype = &ktype_ec_master;
576
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   205
    master->kobj.parent = module_kobj;
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   206
    
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   207
    if (kobject_set_name(&master->kobj, "master%i", index)) {
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   208
        EC_ERR("Failed to set master kobject name.\n");
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   209
        kobject_put(&master->kobj);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   210
        return -1;
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   211
    }
576
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   212
    
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 483
diff changeset
   213
    if (kobject_add(&master->kobj)) {
576
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   214
        EC_ERR("Failed to add master kobject.\n");
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 483
diff changeset
   215
        kobject_put(&master->kobj);
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 483
diff changeset
   216
        return -1;
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 483
diff changeset
   217
    }
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   218
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   219
    return 0;
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   220
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   221
out_clear_eoe:
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   222
    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
   223
        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
   224
        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
   225
        kfree(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   226
    }
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   227
    ec_device_clear(&master->backup_device);
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   228
out_clear_main:
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   229
    ec_device_clear(&master->main_device);
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   230
out_return:
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   231
    return -1;
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 35
diff changeset
   234
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   237
   Master destructor.
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   238
   Clears the kobj-hierarchy bottom up and frees the master.
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   239
*/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   240
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   241
void ec_master_destroy(ec_master_t *master /**< EtherCAT master */)
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   242
{
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   243
    ec_master_destroy_slaves(master);
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   244
    ec_master_destroy_domains(master);
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   245
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   246
    // destroy self
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   247
    kobject_del(&master->kobj);
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   248
    kobject_put(&master->kobj); // free master
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   249
}
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   250
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   251
/*****************************************************************************/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   252
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   253
/**
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   254
   Clear and free master.
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   255
   This method is called by the kobject,
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   256
   once there are no more references to it.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   257
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   258
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   259
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
   260
{
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   261
    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
   262
    ec_eoe_t *eoe, *next_eoe;
483
1a507e9ab735 Minor change in master.c.
Florian Pose <fp@igh-essen.com>
parents: 481
diff changeset
   263
    ec_datagram_t *datagram, *next_datagram;
1a507e9ab735 Minor change in master.c.
Florian Pose <fp@igh-essen.com>
parents: 481
diff changeset
   264
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 597
diff changeset
   265
    // list of EEPROM requests is empty,
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 597
diff changeset
   266
    // otherwise master could not be cleared.
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 597
diff changeset
   267
483
1a507e9ab735 Minor change in master.c.
Florian Pose <fp@igh-essen.com>
parents: 481
diff changeset
   268
    // dequeue all datagrams
1a507e9ab735 Minor change in master.c.
Florian Pose <fp@igh-essen.com>
parents: 481
diff changeset
   269
    list_for_each_entry_safe(datagram, next_datagram,
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   270
                             &master->datagram_queue, queue) {
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   271
        datagram->state = EC_DATAGRAM_ERROR;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   272
        list_del_init(&datagram->queue);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   273
    }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   274
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   275
    ec_fsm_master_clear(&master->fsm);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   276
    ec_datagram_clear(&master->fsm_datagram);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   277
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   278
    // clear EoE objects
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   279
    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
   280
        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
   281
        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
   282
        kfree(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   283
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   284
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   285
    ec_device_clear(&master->backup_device);
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   286
    ec_device_clear(&master->main_device);
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   287
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   288
    EC_INFO("Master %i freed.\n", master->index);
418
7a43437bc48b Fixed memory leak in master and slave destructors.
Florian Pose <fp@igh-essen.com>
parents: 415
diff changeset
   289
7a43437bc48b Fixed memory leak in master and slave destructors.
Florian Pose <fp@igh-essen.com>
parents: 415
diff changeset
   290
    kfree(master);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   291
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   292
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   293
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   294
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   295
/**
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   296
   Destroy all slaves.
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   297
*/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   298
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   299
void ec_master_destroy_slaves(ec_master_t *master)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   300
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   301
    ec_slave_t *slave, *next_slave;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   302
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   303
    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
   304
        list_del(&slave->list);
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   305
        ec_slave_destroy(slave);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   306
    }
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   307
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   308
    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
   309
}
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   310
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   311
/*****************************************************************************/
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   312
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   313
/**
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   314
   Destroy all domains.
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   315
*/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   316
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   317
void ec_master_destroy_domains(ec_master_t *master)
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   318
{
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   319
    ec_domain_t *domain, *next_d;
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   320
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   321
    list_for_each_entry_safe(domain, next_d, &master->domains, list) {
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   322
        list_del(&domain->list);
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   323
        ec_domain_destroy(domain);
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   324
    }
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   325
}
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   326
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   327
/*****************************************************************************/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   328
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   329
/**
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   330
   Flushes the SDO request queue.
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   331
*/
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   332
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   333
void ec_master_flush_sdo_requests(ec_master_t *master)
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   334
{
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   335
    del_timer_sync(&master->sdo_timer);
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   336
    complete(&master->sdo_complete);
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   337
    master->sdo_request = NULL;
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   338
    master->sdo_seq_user = 0;
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   339
    master->sdo_seq_master = 0;
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   340
}
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   341
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   342
/*****************************************************************************/
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   343
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 418
diff changeset
   344
/**
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   345
   Internal locking callback.
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   346
*/
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   347
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   348
int ec_master_request_cb(void *master /**< callback data */)
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   349
{
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   350
    spin_lock(&((ec_master_t *) master)->internal_lock);
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   351
    return 0;
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   352
}
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   353
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   354
/*****************************************************************************/
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   355
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   356
/**
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   357
   Internal unlocking callback.
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   358
*/
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   359
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   360
void ec_master_release_cb(void *master /**< callback data */)
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   361
{
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   362
    spin_unlock(&((ec_master_t *) master)->internal_lock);
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   363
}
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   364
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   365
/*****************************************************************************/
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   366
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   367
/**
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   368
 * Starts the master thread.
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   369
*/
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   370
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   371
int ec_master_thread_start(ec_master_t *master /**< EtherCAT master */)
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   372
{
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   373
    int (*thread_func)(ec_master_t *);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   374
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   375
    switch (master->mode) {
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   376
        case EC_MASTER_MODE_IDLE:
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   377
            thread_func = ec_master_idle_thread;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   378
            break;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   379
        case EC_MASTER_MODE_OPERATION:
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   380
            thread_func = ec_master_operation_thread;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   381
            break;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   382
        default:
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   383
            EC_ERR("Invalid master mode while starting thread!\n");
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   384
            return -1;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   385
    }
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   386
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   387
    init_completion(&master->thread_exit);
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   388
540
a729667dea1e Minor changes in master thread messages.
Florian Pose <fp@igh-essen.com>
parents: 533
diff changeset
   389
    EC_INFO("Starting master thread.\n");
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   390
    if (!(master->thread_id = kernel_thread((int (*)(void *)) thread_func,
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   391
                    master, CLONE_KERNEL)))
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   392
        return -1;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   393
    
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   394
    return 0;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   395
}
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   396
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   397
/*****************************************************************************/
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   398
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   399
/**
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   400
 * Stops the master thread.
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   401
*/
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   402
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   403
void ec_master_thread_stop(ec_master_t *master /**< EtherCAT master */)
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   404
{
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   405
    if (master->thread_id) {
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   406
        kill_proc(master->thread_id, SIGTERM, 1);
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   407
        wait_for_completion(&master->thread_exit);
540
a729667dea1e Minor changes in master thread messages.
Florian Pose <fp@igh-essen.com>
parents: 533
diff changeset
   408
        EC_INFO("Master thread exited.\n");
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   409
    }    
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   410
}
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   411
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   412
/*****************************************************************************/
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   413
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   414
/**
527
3eea08638522 Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 525
diff changeset
   415
 * Transition function from ORPHANED to IDLE mode.
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   416
*/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   417
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   418
int ec_master_enter_idle_mode(ec_master_t *master /**< EtherCAT master */)
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   419
{
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   420
    master->request_cb = ec_master_request_cb;
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   421
    master->release_cb = ec_master_release_cb;
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   422
    master->cb_data = master;
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   423
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   424
    master->mode = EC_MASTER_MODE_IDLE;
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   425
    if (ec_master_thread_start(master)) {
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   426
        master->mode = EC_MASTER_MODE_ORPHANED;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   427
        return -1;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   428
    }
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   429
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   430
    return 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   431
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   432
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   433
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   434
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   435
/**
527
3eea08638522 Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 525
diff changeset
   436
 * Transition function from IDLE to ORPHANED mode.
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   437
*/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   438
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   439
void ec_master_leave_idle_mode(ec_master_t *master /**< EtherCAT master */)
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   440
{
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   441
    master->mode = EC_MASTER_MODE_ORPHANED;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   442
    
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   443
    ec_master_eoe_stop(master);
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   444
    ec_master_thread_stop(master);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   445
    ec_master_flush_sdo_requests(master);
589
492148a329e7 Destroy slaves when leaving idle mode.
Florian Pose <fp@igh-essen.com>
parents: 579
diff changeset
   446
    ec_master_destroy_slaves(master);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   447
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   448
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   449
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   450
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   451
/**
527
3eea08638522 Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 525
diff changeset
   452
 * Transition function from IDLE to OPERATION mode.
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   453
*/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   454
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   455
int ec_master_enter_operation_mode(ec_master_t *master /**< EtherCAT master */)
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   456
{
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   457
    ec_slave_t *slave;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   458
518
b6a1426ba724 Fixed race: Stop EoE processing when entering or leaving operation mode.
Florian Pose <fp@igh-essen.com>
parents: 517
diff changeset
   459
    ec_master_eoe_stop(master); // stop EoE timer
524
5ffcb9b9f17d Fixed blocking of EoE processing while entering or leaving operational mode.
Florian Pose <fp@igh-essen.com>
parents: 518
diff changeset
   460
    master->eoe_checked = 1; // prevent from starting again by FSM
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   461
    ec_master_thread_stop(master);
518
b6a1426ba724 Fixed race: Stop EoE processing when entering or leaving operation mode.
Florian Pose <fp@igh-essen.com>
parents: 517
diff changeset
   462
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   463
    master->mode = EC_MASTER_MODE_OPERATION;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   464
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   465
    // wait for FSM datagram
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   466
    if (master->fsm_datagram.state == EC_DATAGRAM_SENT) {
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   467
        while (get_cycles() - master->fsm_datagram.cycles_sent
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   468
               < (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000)) {}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   469
        ecrt_master_receive(master);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   470
    }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   471
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   472
    // finish running IDLE FSM
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   473
    if (ec_fsm_master_running(&master->fsm)) {
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   474
        while (ec_fsm_master_exec(&master->fsm)) {
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   475
            ec_master_queue_datagram(master, &master->fsm_datagram);
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
   476
            ec_master_sync_io(master);
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
   477
        }
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   478
    }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   479
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   480
    if (master->debug_level) {
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   481
        if (ec_master_measure_bus_time(master)) {
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   482
            EC_ERR("Bus time measuring failed!\n");
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   483
            goto out_idle;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   484
        }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   485
    }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   486
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   487
    // set initial slave states
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   488
    list_for_each_entry(slave, &master->slaves, list) {
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   489
        if (ec_slave_is_coupler(slave)) {
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   490
            ec_slave_request_state(slave, EC_SLAVE_STATE_OP);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   491
        }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   492
        else {
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   493
            ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   494
        }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   495
    }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   496
524
5ffcb9b9f17d Fixed blocking of EoE processing while entering or leaving operational mode.
Florian Pose <fp@igh-essen.com>
parents: 518
diff changeset
   497
    master->eoe_checked = 0; // allow starting EoE again
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
   498
    master->pdo_slaves_offline = 0; // assume all PDO slaves online
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   499
    master->injection_seq_fsm = 0;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   500
    master->injection_seq_rt = 0;
518
b6a1426ba724 Fixed race: Stop EoE processing when entering or leaving operation mode.
Florian Pose <fp@igh-essen.com>
parents: 517
diff changeset
   501
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   502
    return 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   503
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   504
 out_idle:
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   505
    master->mode = EC_MASTER_MODE_IDLE;
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   506
    if (ec_master_thread_start(master)) {
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   507
        EC_WARN("Failed to start master thread again!\n");
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   508
    }
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   509
    return -1;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   510
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   511
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   512
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   513
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   514
/**
527
3eea08638522 Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 525
diff changeset
   515
 * Transition function from OPERATION to IDLE mode.
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   516
*/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   517
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   518
void ec_master_leave_operation_mode(ec_master_t *master
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   519
                                    /**< EtherCAT master */)
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   520
{
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   521
    ec_slave_t *slave;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   522
    ec_fsm_master_t *fsm = &master->fsm;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   523
    ec_fsm_slave_t fsm_slave;
449
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   524
518
b6a1426ba724 Fixed race: Stop EoE processing when entering or leaving operation mode.
Florian Pose <fp@igh-essen.com>
parents: 517
diff changeset
   525
    ec_master_eoe_stop(master); // stop EoE timer
524
5ffcb9b9f17d Fixed blocking of EoE processing while entering or leaving operational mode.
Florian Pose <fp@igh-essen.com>
parents: 518
diff changeset
   526
    master->eoe_checked = 1; // prevent from starting again by FSM
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   527
    ec_master_thread_stop(master); // stop master thread
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   528
    master->injection_seq_fsm = 0;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   529
    master->injection_seq_rt = 0;
518
b6a1426ba724 Fixed race: Stop EoE processing when entering or leaving operation mode.
Florian Pose <fp@igh-essen.com>
parents: 517
diff changeset
   530
449
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   531
    // wait for FSM datagram
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   532
    if (master->fsm_datagram.state == EC_DATAGRAM_SENT) {
500
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
   533
        // active waiting
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   534
        while (get_cycles() - master->fsm_datagram.cycles_sent
500
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
   535
               < (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000));
449
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   536
        ecrt_master_receive(master);
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   537
    }
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   538
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
   539
    // finish running master FSM
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   540
    if (ec_fsm_master_running(fsm)) {
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   541
        while (ec_fsm_master_exec(fsm)) {
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   542
            ec_master_queue_datagram(master, &master->fsm_datagram);
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
   543
            ec_master_sync_io(master);
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
   544
        }
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
   545
    }
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
   546
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   547
    ec_fsm_slave_init(&fsm_slave, &master->fsm_datagram);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   548
    
449
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   549
    // set states for all slaves
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   550
    list_for_each_entry(slave, &master->slaves, list) {
467
2274de57ca84 Remove estimated sync manager sizes when leaving operation mode.
Florian Pose <fp@igh-essen.com>
parents: 462
diff changeset
   551
        ec_slave_reset(slave);
449
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   552
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
   553
550
f94a9f1bcaea Fixed bug causing unloading of realtime module being very slow after topology change.
Florian Pose <fp@igh-essen.com>
parents: 549
diff changeset
   554
        // don't try to set PREOP for slaves that don't respond,
f94a9f1bcaea Fixed bug causing unloading of realtime module being very slow after topology change.
Florian Pose <fp@igh-essen.com>
parents: 549
diff changeset
   555
        // because of 3 second timeout.
610
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 601
diff changeset
   556
        if (slave->online_state == EC_SLAVE_OFFLINE) {
550
f94a9f1bcaea Fixed bug causing unloading of realtime module being very slow after topology change.
Florian Pose <fp@igh-essen.com>
parents: 549
diff changeset
   557
            if (master->debug_level)
f94a9f1bcaea Fixed bug causing unloading of realtime module being very slow after topology change.
Florian Pose <fp@igh-essen.com>
parents: 549
diff changeset
   558
                EC_DBG("Skipping to configure offline slave %i.\n",
f94a9f1bcaea Fixed bug causing unloading of realtime module being very slow after topology change.
Florian Pose <fp@igh-essen.com>
parents: 549
diff changeset
   559
                        slave->ring_position);
f94a9f1bcaea Fixed bug causing unloading of realtime module being very slow after topology change.
Florian Pose <fp@igh-essen.com>
parents: 549
diff changeset
   560
            continue;
f94a9f1bcaea Fixed bug causing unloading of realtime module being very slow after topology change.
Florian Pose <fp@igh-essen.com>
parents: 549
diff changeset
   561
        }
f94a9f1bcaea Fixed bug causing unloading of realtime module being very slow after topology change.
Florian Pose <fp@igh-essen.com>
parents: 549
diff changeset
   562
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   563
        ec_fsm_slave_start_conf(&fsm_slave, slave);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   564
        while (ec_fsm_slave_exec(&fsm_slave)) {
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   565
            ec_master_queue_datagram(master, &master->fsm_datagram);
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
   566
            ec_master_sync_io(master);
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
   567
        }
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   568
    }
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   569
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   570
    ec_fsm_slave_clear(&fsm_slave);
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   571
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   572
    ec_master_destroy_domains(master);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   573
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   574
    master->request_cb = ec_master_request_cb;
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   575
    master->release_cb = ec_master_release_cb;
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   576
    master->cb_data = master;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   577
518
b6a1426ba724 Fixed race: Stop EoE processing when entering or leaving operation mode.
Florian Pose <fp@igh-essen.com>
parents: 517
diff changeset
   578
    master->eoe_checked = 0; // allow EoE again
b6a1426ba724 Fixed race: Stop EoE processing when entering or leaving operation mode.
Florian Pose <fp@igh-essen.com>
parents: 517
diff changeset
   579
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   580
    master->mode = EC_MASTER_MODE_IDLE;
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   581
    if (ec_master_thread_start(master)) {
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   582
        EC_WARN("Failed to start master thread!\n");
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   583
    }
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   584
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   585
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   586
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   587
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   588
/**
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   589
   Places a datagram in the datagram queue.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   590
*/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   591
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   592
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
   593
                              ec_datagram_t *datagram /**< datagram */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   594
                              )
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   595
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   596
    ec_datagram_t *queued_datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   597
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   598
    // check, if the datagram is already queued
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   599
    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
   600
        if (queued_datagram == datagram) {
332
e16093374dfd New statistic outputs to avoid blasting the logs.
Florian Pose <fp@igh-essen.com>
parents: 331
diff changeset
   601
            master->stats.skipped++;
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   602
            if (master->debug_level)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   603
                EC_DBG("skipping datagram %x.\n", (unsigned int) datagram);
332
e16093374dfd New statistic outputs to avoid blasting the logs.
Florian Pose <fp@igh-essen.com>
parents: 331
diff changeset
   604
            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
   605
            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
   606
            return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   607
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   608
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   609
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   610
    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
   611
    datagram->state = EC_DATAGRAM_QUEUED;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   612
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   613
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   614
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   615
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   616
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   617
   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
   618
   \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
   619
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   620
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   621
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
   622
{
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   623
    ec_datagram_t *datagram, *next;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   624
    size_t datagram_size;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   625
    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
   626
    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
   627
    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
   628
    unsigned long jiffies_sent;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   629
    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
   630
    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
   631
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   632
    cycles_start = get_cycles();
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   633
    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
   634
    INIT_LIST_HEAD(&sent_datagrams);
208
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
   635
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   636
    if (unlikely(master->debug_level > 1))
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   637
        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
   638
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   639
    do {
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   640
        // fetch pointer to transmit socket buffer
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   641
        frame_data = ec_device_tx_data(&master->main_device);
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   642
        cur_data = frame_data + EC_FRAME_HEADER_SIZE;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   643
        follows_word = NULL;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   644
        more_datagrams_waiting = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   645
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   646
        // fill current frame with datagrams
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   647
        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
   648
            if (datagram->state != EC_DATAGRAM_QUEUED) continue;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   649
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   650
            // does the current datagram fit in the frame?
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   651
            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
   652
                + EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   653
            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
   654
                more_datagrams_waiting = 1;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   655
                break;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   656
            }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   657
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   658
            list_add_tail(&datagram->sent, &sent_datagrams);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   659
            datagram->index = master->datagram_index++;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   660
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   661
            if (unlikely(master->debug_level > 1))
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   662
                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
   663
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   664
            // set "datagram following" flag in previous frame
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   665
            if (follows_word)
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   666
                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
   667
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   668
            // EtherCAT datagram header
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   669
            EC_WRITE_U8 (cur_data,     datagram->type);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   670
            EC_WRITE_U8 (cur_data + 1, datagram->index);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   671
            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
   672
            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
   673
            EC_WRITE_U16(cur_data + 8, 0x0000);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   674
            follows_word = cur_data + 6;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   675
            cur_data += EC_DATAGRAM_HEADER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   676
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   677
            // EtherCAT datagram data
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   678
            memcpy(cur_data, datagram->data, datagram->data_size);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   679
            cur_data += datagram->data_size;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   680
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   681
            // EtherCAT datagram footer
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   682
            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
   683
            cur_data += EC_DATAGRAM_FOOTER_SIZE;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   684
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   685
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   686
        if (list_empty(&sent_datagrams)) {
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   687
            if (unlikely(master->debug_level > 1))
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   688
                EC_DBG("nothing to send.\n");
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   689
            break;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   690
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   691
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   692
        // EtherCAT frame header
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   693
        EC_WRITE_U16(frame_data, ((cur_data - frame_data
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   694
                                   - EC_FRAME_HEADER_SIZE) & 0x7FF) | 0x1000);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   695
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   696
        // pad frame
211
c684b6b7adaf Using kernel Ethernet constants.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
   697
        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
   698
            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
   699
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   700
        if (unlikely(master->debug_level > 1))
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   701
            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
   702
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   703
        // send frame
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   704
        ec_device_send(&master->main_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
   705
        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
   706
        jiffies_sent = jiffies;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   707
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   708
        // 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
   709
        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
   710
            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
   711
            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
   712
            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
   713
            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
   714
        }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   715
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   716
        frame_count++;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   717
    }
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   718
    while (more_datagrams_waiting);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   719
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   720
    if (unlikely(master->debug_level > 1)) {
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   721
        cycles_end = get_cycles();
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   722
        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
   723
               frame_count,
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   724
               (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
   725
    }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   726
}
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   727
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   728
/*****************************************************************************/
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   729
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   730
/**
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   731
   Processes a received frame.
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   732
   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
   733
   \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
   734
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   735
331
17f58fe99511 Renamed ec_master_receive() to ec_master_receive_datagrams().
Florian Pose <fp@igh-essen.com>
parents: 330
diff changeset
   736
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
   737
                                 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
   738
                                 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
   739
                                 )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   740
{
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   741
    size_t frame_size, data_size;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   742
    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
   743
    unsigned int cmd_follows, matched;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   744
    const uint8_t *cur_data;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   745
    ec_datagram_t *datagram;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   746
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   747
    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
   748
        master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   749
        ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   750
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   751
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   752
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   753
    cur_data = frame_data;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   754
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   755
    // 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
   756
    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
   757
    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
   758
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   759
    if (unlikely(frame_size > size)) {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   760
        master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   761
        ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   762
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   763
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   764
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   765
    cmd_follows = 1;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   766
    while (cmd_follows) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   767
        // process datagram header
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   768
        datagram_type  = EC_READ_U8 (cur_data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   769
        datagram_index = EC_READ_U8 (cur_data + 1);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   770
        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
   771
        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
   772
        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
   773
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   774
        if (unlikely(cur_data - frame_data
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   775
                     + 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
   776
            master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   777
            ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   778
            return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   779
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   780
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   781
        // 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
   782
        matched = 0;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   783
        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
   784
            if (datagram->state == EC_DATAGRAM_SENT
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   785
                && datagram->type == datagram_type
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   786
                && datagram->index == datagram_index
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   787
                && 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
   788
                matched = 1;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   789
                break;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   790
            }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   791
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   792
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   793
        // 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
   794
        if (!matched) {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   795
            master->stats.unmatched++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   796
            ec_master_output_stats(master);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   797
            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
   798
            continue;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   799
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   800
345
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   801
        // copy received data into the datagram memory
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   802
        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
   803
        cur_data += data_size;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   804
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   805
        // set the datagram's working counter
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   806
        datagram->working_counter = EC_READ_U16(cur_data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   807
        cur_data += EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   808
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   809
        // 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
   810
        datagram->state = EC_DATAGRAM_RECEIVED;
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   811
        datagram->cycles_received = master->main_device.cycles_poll;
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   812
        datagram->jiffies_received = master->main_device.jiffies_poll;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   813
        list_del_init(&datagram->queue);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   814
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   815
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   816
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   817
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   818
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   819
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   820
   Output statistics in cyclic mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   821
   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
   822
   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
   823
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   824
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   825
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
   826
{
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   827
    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
   828
        master->stats.output_jiffies = jiffies;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   829
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   830
        if (master->stats.timeouts) {
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   831
            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
   832
                    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
   833
            master->stats.timeouts = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   834
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   835
        if (master->stats.corrupted) {
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   836
            EC_WARN("%i frame%s CORRUPTED!\n", master->stats.corrupted,
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   837
                    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
   838
            master->stats.corrupted = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   839
        }
332
e16093374dfd New statistic outputs to avoid blasting the logs.
Florian Pose <fp@igh-essen.com>
parents: 331
diff changeset
   840
        if (master->stats.skipped) {
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   841
            EC_WARN("%i datagram%s SKIPPED!\n", master->stats.skipped,
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   842
                    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
   843
            master->stats.skipped = 0;
e16093374dfd New statistic outputs to avoid blasting the logs.
Florian Pose <fp@igh-essen.com>
parents: 331
diff changeset
   844
        }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   845
        if (master->stats.unmatched) {
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   846
            EC_WARN("%i datagram%s UNMATCHED!\n", master->stats.unmatched,
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   847
                    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
   848
            master->stats.unmatched = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   849
        }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   850
    }
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   851
}
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   852
68
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   853
/*****************************************************************************/
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   854
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   855
/**
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   856
 * Master kernel thread function for IDLE mode.
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   857
 */
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   858
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   859
static int ec_master_idle_thread(ec_master_t *master)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   860
{
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   861
    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
   862
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   863
    daemonize("EtherCAT-IDLE");
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   864
    allow_signal(SIGTERM);
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   865
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   866
    while (!signal_pending(current) && master->mode == EC_MASTER_MODE_IDLE) {
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   867
        cycles_start = get_cycles();
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   868
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   869
        if (ec_fsm_master_running(&master->fsm)) {
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   870
            // receive
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   871
            spin_lock_bh(&master->internal_lock);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   872
            ecrt_master_receive(master);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   873
            spin_unlock_bh(&master->internal_lock);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   874
        }
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   875
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   876
        // execute master state machine
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   877
        if (ec_fsm_master_exec(&master->fsm)) {
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   878
            // queue and send
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   879
            ec_master_queue_datagram(master, &master->fsm_datagram);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   880
            spin_lock_bh(&master->internal_lock);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   881
            ecrt_master_send(master);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   882
            spin_unlock_bh(&master->internal_lock);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   883
        }
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   884
        
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   885
        cycles_end = get_cycles();
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   886
        master->idle_cycle_times[master->idle_cycle_time_pos]
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   887
            = (u32) (cycles_end - cycles_start) * 1000 / cpu_khz;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   888
        master->idle_cycle_time_pos++;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   889
        master->idle_cycle_time_pos %= HZ;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   890
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   891
        set_current_state(TASK_INTERRUPTIBLE);
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   892
        schedule_timeout(1);
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   893
    }
518
b6a1426ba724 Fixed race: Stop EoE processing when entering or leaving operation mode.
Florian Pose <fp@igh-essen.com>
parents: 517
diff changeset
   894
    
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   895
    master->thread_id = 0;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   896
    complete_and_exit(&master->thread_exit, 0);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   897
}
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   898
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   899
/*****************************************************************************/
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   900
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   901
/**
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   902
 * Master kernel thread function for IDLE mode.
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   903
 */
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   904
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   905
static int ec_master_operation_thread(ec_master_t *master)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   906
{
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   907
    cycles_t cycles_start, cycles_end;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   908
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   909
    daemonize("EtherCAT-OP");
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   910
    allow_signal(SIGTERM);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   911
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   912
    while (!signal_pending(current) &&
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   913
            master->mode == EC_MASTER_MODE_OPERATION) {
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   914
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   915
        if (master->injection_seq_rt != master->injection_seq_fsm ||
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   916
                master->fsm_datagram.state == EC_DATAGRAM_SENT ||
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   917
                master->fsm_datagram.state == EC_DATAGRAM_QUEUED)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   918
            goto schedule;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   919
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   920
        cycles_start = get_cycles();
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   921
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   922
        // output statistics
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   923
        ec_master_output_stats(master);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   924
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   925
        // execute master state machine
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   926
        if (ec_fsm_master_exec(&master->fsm)) {
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   927
            // inject datagram
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   928
            master->injection_seq_fsm++;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   929
        }
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   930
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   931
        cycles_end = get_cycles();
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   932
        master->idle_cycle_times[master->idle_cycle_time_pos]
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   933
            = (u32) (cycles_end - cycles_start) * 1000 / cpu_khz;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   934
        master->idle_cycle_time_pos++;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   935
        master->idle_cycle_time_pos %= HZ;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   936
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   937
schedule:
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   938
        set_current_state(TASK_INTERRUPTIBLE);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   939
        schedule_timeout(1);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   940
    }
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   941
    
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   942
    master->thread_id = 0;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   943
    complete_and_exit(&master->thread_exit, 0);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   944
}
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   945
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   946
/*****************************************************************************/
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   947
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   948
ssize_t ec_master_device_info(const ec_device_t *device,
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   949
        const ec_device_id_t *dev_id,
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   950
        char *buffer)
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   951
{
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   952
    unsigned int frames_lost;
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   953
    off_t off = 0;
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   954
    
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   955
    off += ec_device_id_print(dev_id, buffer + off);
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   956
    
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   957
    if (device->dev) {
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   958
        off += sprintf(buffer + off, " (connected).\n");      
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   959
        off += sprintf(buffer + off, "    Frames sent:     %u\n",
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   960
                device->tx_count);
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   961
        off += sprintf(buffer + off, "    Frames received: %u\n",
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   962
                device->rx_count);
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   963
        frames_lost = device->tx_count - device->rx_count;
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   964
        if (frames_lost) frames_lost--;
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   965
        off += sprintf(buffer + off, "    Frames lost:     %u\n", frames_lost);
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   966
    }
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   967
    else if (dev_id->type != ec_device_id_empty) {
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   968
        off += sprintf(buffer + off, " (WAITING).\n");      
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   969
    }
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   970
    else {
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   971
        off += sprintf(buffer + off, ".\n");
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   972
    }
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   973
    
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   974
    return off;
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   975
}
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   976
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   977
/*****************************************************************************/
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   978
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   979
/**
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   980
   Formats master information for SysFS read access.
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   981
   \return number of bytes written
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   982
*/
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   983
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   984
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
   985
                       char *buffer /**< memory to store data */
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   986
                       )
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   987
{
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   988
    off_t off = 0;
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
   989
    ec_eoe_t *eoe;
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   990
    uint32_t cur, sum, min, max, pos, i;
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   991
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   992
    off += sprintf(buffer + off, "\nMode: ");
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   993
    switch (master->mode) {
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   994
        case EC_MASTER_MODE_ORPHANED:
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   995
            off += sprintf(buffer + off, "ORPHANED");
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   996
            break;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   997
        case EC_MASTER_MODE_IDLE:
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   998
            off += sprintf(buffer + off, "IDLE");
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
   999
            break;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1000
        case EC_MASTER_MODE_OPERATION:
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1001
            off += sprintf(buffer + off, "OPERATION");
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1002
            break;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1003
    }
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1004
339
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 337
diff changeset
  1005
    off += sprintf(buffer + off, "\nSlaves: %i\n",
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1006
                   master->slave_count);
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1007
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1008
    off += sprintf(buffer + off, "\nDevices:\n");
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1009
    
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1010
    if (down_interruptible(&master->device_sem)) {
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1011
        EC_ERR("Interrupted while waiting for device!\n");
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1012
        return -EINVAL;
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1013
    }
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1014
    
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1015
    off += sprintf(buffer + off, "  Main: ");
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
  1016
    off += ec_master_device_info(&master->main_device,
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1017
            master->main_device_id, buffer + off);
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1018
    off += sprintf(buffer + off, "  Backup: ");
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
  1019
    off += ec_master_device_info(&master->backup_device,
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1020
            master->backup_device_id, buffer + off);
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1021
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1022
    up(&master->device_sem);
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1023
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1024
    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
  1025
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1026
    sum = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1027
    min = 0xFFFFFFFF;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1028
    max = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1029
    pos = master->idle_cycle_time_pos;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1030
    for (i = 0; i < HZ; i++) {
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1031
        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
  1032
        sum += cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1033
        if (cur < min) min = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1034
        if (cur > max) max = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1035
    }
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1036
    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
  1037
                   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
  1038
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1039
    sum = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1040
    min = 0xFFFFFFFF;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1041
    max = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1042
    pos = master->eoe_cycle_time_pos;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1043
    for (i = 0; i < HZ; i++) {
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1044
        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
  1045
        sum += cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1046
        if (cur < min) min = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1047
        if (cur > max) max = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1048
    }
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1049
    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
  1050
                   min, sum / HZ, (sum * 100 / HZ) % 100, max);
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1051
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
  1052
    if (!list_empty(&master->eoe_handlers))
339
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 337
diff changeset
  1053
        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
  1054
    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
  1055
        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
  1056
                       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
  1057
                       ((eoe->rx_rate + eoe->tx_rate) / 8 + 512) / 1024);
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
  1058
    }
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
  1059
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1060
    off += sprintf(buffer + off, "\n");
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1061
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1062
    return off;
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1063
}
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1064
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1065
/*****************************************************************************/
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1066
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1067
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1068
   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
  1069
   \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
  1070
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1071
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1072
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
  1073
                                 struct attribute *attr, /**< attribute */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1074
                                 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
  1075
                                 )
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1076
{
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1077
    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
  1078
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1079
    if (attr == &attr_info) {
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1080
        return ec_master_info(master, buffer);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1081
    }
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1082
    else if (attr == &attr_debug_level) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1083
        return sprintf(buffer, "%i\n", master->debug_level);
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1084
    }
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1085
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1086
    return 0;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1087
}
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1088
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1089
/*****************************************************************************/
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1090
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1091
/**
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1092
   Formats attribute data for SysFS write access.
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1093
   \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
  1094
*/
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1095
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1096
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
  1097
                                  struct attribute *attr, /**< attribute */
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1098
                                  const char *buffer, /**< memory with data */
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1099
                                  size_t size /**< size of data to store */
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1100
                                  )
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1101
{
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1102
    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
  1103
597
3a2c2d6ca5e9 Removed eeprom_write_enable file.
Florian Pose <fp@igh-essen.com>
parents: 589
diff changeset
  1104
    if (attr == &attr_debug_level) {
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1105
        if (!strcmp(buffer, "0\n")) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1106
            master->debug_level = 0;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1107
        }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1108
        else if (!strcmp(buffer, "1\n")) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1109
            master->debug_level = 1;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1110
        }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1111
        else if (!strcmp(buffer, "2\n")) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1112
            master->debug_level = 2;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1113
        }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1114
        else {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1115
            EC_ERR("Invalid debug level value!\n");
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1116
            return -EINVAL;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1117
        }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1118
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1119
        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
  1120
        return size;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1121
    }
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1122
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1123
    return -EINVAL;
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1124
}
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1125
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1126
/*****************************************************************************/
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1127
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1128
/**
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
  1129
   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
  1130
*/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1131
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1132
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
  1133
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1134
    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
  1135
    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
  1136
    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
  1137
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
  1138
    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
  1139
ddb48b173680 Fixed bug with ec_master_eoe_start() does new coupling all the time.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  1140
    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
  1141
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1142
    // 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
  1143
    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
  1144
        eoe->slave = NULL;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1145
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1146
    // 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
  1147
    coupled = 0;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1148
    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
  1149
        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
  1150
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1151
        found = 0;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1152
        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
  1153
            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
  1154
            eoe->slave = slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1155
            found = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1156
            coupled++;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1157
            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
  1158
                    eoe->dev->name, slave->ring_position);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
  1159
            if (eoe->opened)
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
  1160
                ec_slave_request_state(slave, EC_SLAVE_STATE_OP);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
  1161
            else
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
  1162
                ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
253
6dd3e49dbb85 Fixed bug with coupling multiple EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 252
diff changeset
  1163
            break;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1164
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1165
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1166
        if (!found) {
461
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
  1167
            if (master->debug_level)
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
  1168
                EC_WARN("No EoE handler for slave %i!\n",
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
  1169
                        slave->ring_position);
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
  1170
            ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1171
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1172
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1173
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1174
    if (!coupled) {
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1175
        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
  1176
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1177
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1178
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1179
    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
  1180
    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
  1181
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1182
    // start EoE processing
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1183
    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
  1184
    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
  1185
    return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1186
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1187
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1188
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1189
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1190
/**
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1191
   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
  1192
*/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1193
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1194
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
  1195
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1196
    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
  1197
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
  1198
    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
  1199
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1200
    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
  1201
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1202
    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
  1203
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1204
    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
  1205
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1206
    // 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
  1207
    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
  1208
        if (eoe->slave) {
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
  1209
            ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_PREOP);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1210
            eoe->slave = NULL;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1211
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1212
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1213
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1214
    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
  1215
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1216
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1217
/*****************************************************************************/
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1218
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1219
/**
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1220
   Does the Ethernet-over-EtherCAT processing.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1221
*/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1222
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1223
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
  1224
{
60a10d85c20b Prepared EoE processing with workqueue.
Florian Pose <fp@igh-essen.com>
parents: 204
diff changeset
  1225
    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
  1226
    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
  1227
    unsigned int active = 0;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1228
    cycles_t cycles_start, cycles_end;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1229
    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
  1230
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1231
    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
  1232
        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
  1233
    }
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1234
    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
  1235
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1236
    // receive datagrams
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1237
    if (master->request_cb(master->cb_data)) goto queue_timer;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1238
    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
  1239
    ecrt_master_receive(master);
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1240
    master->release_cb(master->cb_data);
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1241
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1242
    // actual EoE processing
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1243
    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
  1244
        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
  1245
    }
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1246
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1247
    // send datagrams
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1248
    if (master->request_cb(master->cb_data)) goto queue_timer;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1249
    ecrt_master_send(master);
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1250
    cycles_end = get_cycles();
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1251
    master->release_cb(master->cb_data);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1252
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1253
    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
  1254
        = (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
  1255
    master->eoe_cycle_time_pos++;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1256
    master->eoe_cycle_time_pos %= HZ;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1257
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1258
 queue_timer:
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1259
    restart_jiffies = HZ / EC_EOE_FREQUENCY;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1260
    if (!restart_jiffies) restart_jiffies = 1;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1261
    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
  1262
    add_timer(&master->eoe_timer);
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1263
}
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1264
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1265
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1266
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1267
/**
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1268
*/
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1269
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1270
void ec_master_check_sdo(unsigned long data /**< master pointer */)
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1271
{
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1272
    ec_master_t *master = (ec_master_t *) data;
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1273
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1274
    if (master->sdo_seq_master != master->sdo_seq_user) {
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1275
        master->sdo_timer.expires = jiffies + 10;
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1276
        add_timer(&master->sdo_timer);
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1277
        return;
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1278
    }
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1279
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1280
    // master has processed the request
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1281
    complete(&master->sdo_complete);
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1282
}
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1283
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1284
/*****************************************************************************/
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1285
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1286
/**
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1287
   Calculates Advanced Position Adresses.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1288
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1289
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1290
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
  1291
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1292
    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
  1293
    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
  1294
    ec_slave_t *slave;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1295
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1296
    coupler_index = 0;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1297
    reverse_coupler_index = 0xFFFF;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1298
    current_coupler_index = 0x0000;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1299
    coupler_subindex = 0;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1300
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1301
    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
  1302
        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
  1303
            if (slave->sii_alias)
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1304
                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
  1305
            else
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1306
                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
  1307
            coupler_subindex = 0;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1308
        }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1309
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1310
        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
  1311
        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
  1312
        coupler_subindex++;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1313
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1314
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1315
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1316
/*****************************************************************************/
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1317
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1318
/**
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1319
   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
  1320
   \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
  1321
*/
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1322
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1323
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
  1324
{
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1325
    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
  1326
    uint32_t cur, sum, min, max, i;
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1327
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1328
    ec_datagram_init(&datagram);
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1329
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1330
    if (ec_datagram_brd(&datagram, 0x130, 2)) {
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1331
        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
  1332
        ec_datagram_clear(&datagram);
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1333
        return -1;
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1334
    }
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1335
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1336
    ecrt_master_receive(master);
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1337
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1338
    sum = 0;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1339
    min = 0xFFFFFFFF;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1340
    max = 0;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1341
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1342
    for (i = 0; i < 100; i++) {
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1343
        ec_master_queue_datagram(master, &datagram);
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1344
        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
  1345
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1346
        while (1) {
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1347
            ecrt_master_receive(master);
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1348
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1349
            if (datagram.state == EC_DATAGRAM_RECEIVED) {
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1350
                break;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1351
            }
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1352
            else if (datagram.state == EC_DATAGRAM_ERROR) {
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1353
                EC_WARN("Failed to measure bus time.\n");
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1354
                goto error;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1355
            }
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1356
            else if (datagram.state == EC_DATAGRAM_TIMED_OUT) {
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1357
                EC_WARN("Timeout while measuring bus time.\n");
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1358
                goto error;
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1359
            }
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1360
        }
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1361
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1362
        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
  1363
                              - 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
  1364
        sum += cur;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1365
        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
  1366
        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
  1367
    }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1368
459
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
  1369
    EC_DBG("Bus time is (min/avg/max) %u / %u.%u / %u us.\n",
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
  1370
           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
  1371
    ec_datagram_clear(&datagram);
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1372
    return 0;
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1373
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1374
  error:
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1375
    ec_datagram_clear(&datagram);
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
  1376
    return -1;
330
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1377
}
b984763cecc2 Measure bus time.
Florian Pose <fp@igh-essen.com>
parents: 326
diff changeset
  1378
495
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1379
/*****************************************************************************/
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1380
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1381
/**
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1382
   Prepares synchronous IO.
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1383
   Queues all domain datagrams and sends them. Then waits a certain time, so
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1384
   that ecrt_master_receive() can be called securely.
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1385
*/
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1386
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1387
void ec_master_prepare(ec_master_t *master /**< EtherCAT master */)
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1388
{
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1389
    ec_domain_t *domain;
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1390
    cycles_t cycles_start, cycles_end, cycles_timeout;
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1391
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1392
    // queue datagrams of all domains
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1393
    list_for_each_entry(domain, &master->domains, list)
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1394
        ecrt_domain_queue(domain);
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1395
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1396
    ecrt_master_send(master);
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1397
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1398
    cycles_start = get_cycles();
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1399
    cycles_timeout = (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000);
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1400
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1401
    // active waiting
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1402
    while (1) {
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1403
        udelay(100);
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1404
        cycles_end = get_cycles();
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1405
        if (cycles_end - cycles_start >= cycles_timeout) break;
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1406
    }
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1407
}
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1408
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1409
/******************************************************************************
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1410
 *  Realtime interface
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1411
 *****************************************************************************/
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1412
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1413
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1414
   Creates a domain.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1415
   \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
  1416
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1417
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1418
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1419
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
  1420
{
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1421
    ec_domain_t *domain, *last_domain;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1422
    unsigned int index;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1423
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1424
    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
  1425
        EC_ERR("Error allocating domain memory!\n");
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 483
diff changeset
  1426
        return NULL;
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1427
    }
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1428
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1429
    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
  1430
    else {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1431
        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
  1432
        index = last_domain->index + 1;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1433
    }
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1434
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1435
    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
  1436
        EC_ERR("Failed to init domain.\n");
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 483
diff changeset
  1437
        return NULL;
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1438
    }
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1439
95
0066de7a456d Domains als Liste verwaltet.
Florian Pose <fp@igh-essen.com>
parents: 94
diff changeset
  1440
    list_add_tail(&domain->list, &master->domains);
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 483
diff changeset
  1441
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1442
    return domain;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1443
}
61
cd014255f94f register_slave_list() und Bugfix in deactivate_slaves()
Florian Pose <fp@igh-essen.com>
parents: 58
diff changeset
  1444
74
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1445
/*****************************************************************************/
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
  1446
61
cd014255f94f register_slave_list() und Bugfix in deactivate_slaves()
Florian Pose <fp@igh-essen.com>
parents: 58
diff changeset
  1447
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1448
   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
  1449
   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
  1450
   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
  1451
   is operational.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1452
   \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
  1453
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1454
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1455
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1456
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
  1457
{
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1458
    uint32_t domain_offset;
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 82
diff changeset
  1459
    ec_domain_t *domain;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
  1460
    ec_fsm_slave_t fsm_slave;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1461
    ec_slave_t *slave;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
  1462
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1463
    // allocate all domains
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1464
    domain_offset = 0;
95
0066de7a456d Domains als Liste verwaltet.
Florian Pose <fp@igh-essen.com>
parents: 94
diff changeset
  1465
    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
  1466
        if (ec_domain_alloc(domain, domain_offset)) {
95
0066de7a456d Domains als Liste verwaltet.
Florian Pose <fp@igh-essen.com>
parents: 94
diff changeset
  1467
            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
  1468
            return -1;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1469
        }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1470
        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
  1471
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1472
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
  1473
    ec_fsm_slave_init(&fsm_slave, &master->fsm_datagram);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
  1474
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
  1475
    // configure all slaves
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
  1476
    list_for_each_entry(slave, &master->slaves, list) {
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
  1477
        ec_fsm_slave_start_conf(&fsm_slave, slave);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
  1478
        while (ec_fsm_slave_exec(&fsm_slave)) { 
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1479
            ec_master_queue_datagram(master, &master->fsm_datagram);
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
  1480
            ec_master_sync_io(master);
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 449
diff changeset
  1481
        }
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
  1482
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
  1483
        if (!ec_fsm_slave_success(&fsm_slave)) {
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
  1484
            ec_fsm_slave_clear(&fsm_slave);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
  1485
            EC_ERR("Failed to configure slave %i!\n", slave->ring_position);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
  1486
            return -1;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
  1487
        }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
  1488
    }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1489
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
  1490
    ec_fsm_slave_clear(&fsm_slave);
495
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1491
    ec_master_prepare(master); // prepare asynchronous IO
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1492
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1493
    if (master->debug_level)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1494
        EC_DBG("FSM datagram is %x.\n", (unsigned int) &master->fsm_datagram);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1495
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1496
    if (ec_master_thread_start(master)) {
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1497
        EC_ERR("Failed to start master thread!\n");
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1498
        return -1;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1499
    }
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1500
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1501
    return 0;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1502
}
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1503
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1504
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1505
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1506
/**
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1507
   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
  1508
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1509
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1510
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
  1511
{
345
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1512
    ec_datagram_t *datagram;
548
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1513
    unsigned int datagrams_sent;
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1514
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1515
    // send all datagrams
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1516
    ecrt_master_send(master);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1517
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1518
    while (1) { // active waiting
549
67be4381c820 schedule() other processes while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 548
diff changeset
  1519
        schedule(); // schedule other processes while waiting.
345
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1520
        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
  1521
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1522
        // count number of datagrams still waiting for response
548
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1523
        datagrams_sent = 0;
345
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
  1524
        list_for_each_entry(datagram, &master->datagram_queue, queue) {
548
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1525
            // there may be another process that queued commands
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1526
            // in the meantime.
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1527
            if (datagram->state == EC_DATAGRAM_QUEUED) continue;
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1528
            datagrams_sent++;
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1529
        }
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1530
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1531
        // abort loop if there are no more datagrams marked as sent.
f5d41a52a8aa Ignore queued datagrams while waiting in ec_master_sync_io().
Florian Pose <fp@igh-essen.com>
parents: 540
diff changeset
  1532
        if (!datagrams_sent) break;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1533
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1534
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1535
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1536
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1537
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1538
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1539
   Asynchronous sending of datagrams.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1540
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1541
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1542
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1543
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
  1544
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1545
    ec_datagram_t *datagram, *n;
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1546
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1547
    if (master->injection_seq_rt != master->injection_seq_fsm) {
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1548
        // inject datagram produced by master FSM
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1549
        ec_master_queue_datagram(master, &master->fsm_datagram);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1550
        master->injection_seq_rt = master->injection_seq_fsm;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1551
    }
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1552
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
  1553
    if (unlikely(!master->main_device.link_state)) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1554
        // link is down, no datagram can be sent
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1555
        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
  1556
            datagram->state = EC_DATAGRAM_ERROR;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1557
            list_del_init(&datagram->queue);
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1558
        }
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1559
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1560
        // query link state
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
  1561
        ec_device_poll(&master->main_device);
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1562
        return;
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1563
    }
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1564
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1565
    // send frames
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1566
    ec_master_send_datagrams(master);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1567
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1568
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1569
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1570
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1571
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1572
   Asynchronous receiving of datagrams.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1573
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1574
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1575
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1576
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
  1577
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1578
    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
  1579
    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
  1580
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1581
    // receive datagrams
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
  1582
    ec_device_poll(&master->main_device);
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1583
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1584
    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
  1585
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1586
    // dequeue all datagrams that timed out
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1587
    list_for_each_entry_safe(datagram, next, &master->datagram_queue, queue) {
495
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1588
        if (datagram->state != EC_DATAGRAM_SENT) continue;
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1589
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
  1590
        if (master->main_device.cycles_poll - datagram->cycles_sent
495
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1591
            > cycles_timeout) {
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1592
            list_del_init(&datagram->queue);
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1593
            datagram->state = EC_DATAGRAM_TIMED_OUT;
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1594
            master->stats.timeouts++;
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1595
            ec_master_output_stats(master);
88c597598bbc Interface changes for version 1.2, see NEWS file.
Florian Pose <fp@igh-essen.com>
parents: 493
diff changeset
  1596
        }
113
a3dbd6bc8fce Do-Schleifen ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 111
diff changeset
  1597
    }
106
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1598
}
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1599
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1600
/*****************************************************************************/
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1601
d6679c77ad3f ecrt_master_prepare_async_io() hinzugef?gt.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
  1602
/**
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1603
   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
  1604
   These are the valid addressing schemes:
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1605
   - \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
  1606
   - \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
  1607
   - \a "#X" = the slave with alias X,
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1608
   - \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
  1609
   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
  1610
   notation (with respective prefix).
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1611
   \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
  1612
   \ingroup RealtimeInterface
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1613
*/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1614
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1615
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
  1616
                                  const char *address /**< address string */
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1617
                                  )
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1618
{
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1619
    unsigned long first, second;
502
5f4a2fd3b180 Fixed warnings in master.c.
Florian Pose <fp@igh-essen.com>
parents: 500
diff changeset
  1620
    char *remainder, *remainder2;
5f4a2fd3b180 Fixed warnings in master.c.
Florian Pose <fp@igh-essen.com>
parents: 500
diff changeset
  1621
    const char *original;
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1622
    unsigned int alias_requested, alias_found;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1623
    ec_slave_t *alias_slave = NULL, *slave;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1624
500
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
  1625
    original = address;
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
  1626
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1627
    if (!address || address[0] == 0) return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1628
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1629
    alias_requested = 0;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1630
    if (address[0] == '#') {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1631
        alias_requested = 1;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1632
        address++;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1633
    }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1634
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1635
    first = simple_strtoul(address, &remainder, 0);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1636
    if (remainder == address) {
500
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
  1637
        EC_ERR("Slave address \"%s\" - First number empty!\n", original);
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1638
        return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1639
    }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1640
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1641
    if (alias_requested) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1642
        alias_found = 0;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1643
        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
  1644
            if (alias_slave->sii_alias == first) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1645
                alias_found = 1;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1646
                break;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1647
            }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1648
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1649
        if (!alias_found) {
500
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
  1650
            EC_ERR("Slave address \"%s\" - Alias not found!\n", original);
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1651
            return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1652
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1653
    }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1654
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1655
    if (!remainder[0]) { // absolute position
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1656
        if (alias_requested) {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1657
            return alias_slave;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1658
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1659
        else {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1660
            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
  1661
                if (slave->ring_position == first) return slave;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1662
            }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1663
            EC_ERR("Slave address \"%s\" - Absolute position invalid!\n",
500
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
  1664
                   original);
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1665
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1666
    }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1667
    else if (remainder[0] == ':') { // field position
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1668
        remainder++;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1669
        second = simple_strtoul(remainder, &remainder2, 0);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1670
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1671
        if (remainder2 == remainder) {
500
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
  1672
            EC_ERR("Slave address \"%s\" - Second number empty!\n", original);
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1673
            return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1674
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1675
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1676
        if (remainder2[0]) {
500
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
  1677
            EC_ERR("Slave address \"%s\" - Invalid trailer!\n", original);
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1678
            return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1679
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1680
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1681
        if (alias_requested) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1682
            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
  1683
                EC_ERR("Slave address \"%s\": Alias slave must be bus coupler"
500
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
  1684
                       " in colon mode.\n", original);
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1685
                return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1686
            }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1687
            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
  1688
                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
  1689
                    && slave->coupler_subindex == second)
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1690
                    return slave;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1691
            }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1692
            EC_ERR("Slave address \"%s\" - Bus coupler %i has no %lu. slave"
500
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
  1693
                   " following!\n", original, alias_slave->ring_position,
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1694
                   second);
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1695
            return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1696
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1697
        else {
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1698
            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
  1699
                if (slave->coupler_index == first
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1700
                    && slave->coupler_subindex == second) return slave;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1701
            }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1702
        }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1703
    }
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1704
    else
500
f9e6d119463f Corrected error messages in get_slave().
Florian Pose <fp@igh-essen.com>
parents: 496
diff changeset
  1705
        EC_ERR("Slave address \"%s\" - Invalid format!\n", original);
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1706
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1707
    return NULL;
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1708
}
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1709
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1710
/*****************************************************************************/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1711
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1712
/**
204
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1713
   Sets the locking callbacks.
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
  1714
   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
  1715
   (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
  1716
   that access is forbidden at this time.
204
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1717
   \ingroup RealtimeInterface
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1718
*/
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1719
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1720
void ecrt_master_callbacks(ec_master_t *master, /**< EtherCAT master */
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1721
                           int (*request_cb)(void *), /**< request lock CB */
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1722
                           void (*release_cb)(void *), /**< release lock CB */
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1723
                           void *cb_data /**< data parameter */
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1724
                           )
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1725
{
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1726
    master->request_cb = request_cb;
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1727
    master->release_cb = release_cb;
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1728
    master->cb_data = cb_data;
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1729
}
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1730
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1731
/*****************************************************************************/
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1732
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1733
/**
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1734
 * Reads the current master status.
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1735
 */
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1736
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1737
void ecrt_master_get_status(const ec_master_t *master, /**< EtherCAT master */
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1738
        ec_master_status_t *status /**< target status object */
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1739
        )
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1740
{
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1741
    status->bus_status =
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1742
        master->pdo_slaves_offline ? EC_BUS_FAILURE : EC_BUS_OK;
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1743
    status->bus_tainted = master->fsm.tainted; 
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1744
    status->slaves_responding = master->fsm.slaves_responding;
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1745
}
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1746
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1747
/*****************************************************************************/
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1748
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1749
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1750
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1751
EXPORT_SYMBOL(ecrt_master_create_domain);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1752
EXPORT_SYMBOL(ecrt_master_activate);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1753
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
  1754
EXPORT_SYMBOL(ecrt_master_receive);
206
60a10d85c20b Prepared EoE processing with workqueue.
Florian Pose <fp@igh-essen.com>
parents: 204
diff changeset
  1755
EXPORT_SYMBOL(ecrt_master_callbacks);
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 136
diff changeset
  1756
EXPORT_SYMBOL(ecrt_master_get_slave);
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1757
EXPORT_SYMBOL(ecrt_master_get_status);
42
a22a202d0f42 Domains, Warten beim Senden, 10kHz.
Florian Pose <fp@igh-essen.com>
parents: 39
diff changeset
  1758
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1759
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1760
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1761
/*****************************************************************************/