master/master.c
author Florian Pose <fp@igh-essen.com>
Wed, 04 Jun 2008 08:30:18 +0000
changeset 943 1d9e2663e087
parent 927 ffb7d1876ce0
child 946 6ef20c5de875
permissions -rw-r--r--
Enable sync managers only if SII enable is set and size is greater zero.
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"
55
059a9e712aa7 Mit neuer Schnittstelle wieder lauff?hig.
Florian Pose <fp@igh-essen.com>
parents: 54
diff changeset
    49
#include "slave.h"
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    50
#include "slave_config.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"
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    53
#ifdef EC_EOE
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
    54
#include "ethernet.h"
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    55
#endif
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    56
#include "master.h"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    57
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    58
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    59
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    60
void ec_master_destroy_slave_configs(ec_master_t *);
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
    61
void ec_master_destroy_domains(ec_master_t *);
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
    62
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
    63
static int ec_master_operation_thread(ec_master_t *);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    64
#ifdef EC_EOE
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    65
void ec_master_eoe_run(unsigned long);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    66
#endif
179
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    67
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
    68
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
    69
                                  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
    70
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    71
/*****************************************************************************/
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    72
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    73
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    74
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
    75
EC_SYSFS_READ_ATTR(info);
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
    76
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
    77
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    78
static struct attribute *ec_def_attrs[] = {
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
    79
    &attr_info,
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
    80
    &attr_debug_level,
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    81
    NULL,
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    82
};
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    83
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    84
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
    85
    .show = &ec_show_master_attribute,
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
    86
    .store = ec_store_master_attribute
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    87
};
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    88
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    89
static struct kobj_type ktype_ec_master = {
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
    90
    .release = NULL,
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    91
    .sysfs_ops = &ec_sysfs_ops,
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    92
    .default_attrs = ec_def_attrs
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    93
};
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    94
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    95
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    96
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    97
/*****************************************************************************/
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
    98
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   100
   Master constructor.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   101
   \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
   102
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   103
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   104
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
   105
        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
   106
        unsigned int index, /**< master index */
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   107
        const uint8_t *main_mac, /**< MAC address of main device */
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents: 902
diff changeset
   108
        const uint8_t *backup_mac, /**< MAC address of backup device */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents: 902
diff changeset
   109
        dev_t device_number /**< Character device number. */
576
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   110
        )
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   111
{
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   112
    unsigned int i;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   113
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   114
    master->index = index;
647
dc556a8c8fed Replaced master variable 'atomic_t available' by integer and used
Florian Pose <fp@igh-essen.com>
parents: 646
diff changeset
   115
    master->reserved = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   116
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   117
    master->main_mac = main_mac;
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   118
    master->backup_mac = backup_mac;
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   119
    init_MUTEX(&master->device_sem);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   120
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   121
    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
   122
    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
   123
    master->injection_seq_rt = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   124
182
8c0bc99229a9 Slaves stored in list, slaves in SysFS
Florian Pose <fp@igh-essen.com>
parents: 179
diff changeset
   125
    INIT_LIST_HEAD(&master->slaves);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   126
    master->slave_count = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   127
    
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   128
    INIT_LIST_HEAD(&master->configs);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   129
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   130
    master->scan_busy = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   131
    master->allow_scan = 1;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   132
    init_MUTEX(&master->scan_sem);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   133
    init_waitqueue_head(&master->scan_queue);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   134
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   135
    master->config_busy = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   136
    master->allow_config = 1;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   137
    init_MUTEX(&master->config_sem);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   138
    init_waitqueue_head(&master->config_queue);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   139
    
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   140
    INIT_LIST_HEAD(&master->datagram_queue);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   141
    master->datagram_index = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   142
95
0066de7a456d Domains als Liste verwaltet.
Florian Pose <fp@igh-essen.com>
parents: 94
diff changeset
   143
    INIT_LIST_HEAD(&master->domains);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   144
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   145
    master->debug_level = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   146
    master->stats.timeouts = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   147
    master->stats.corrupted = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   148
    master->stats.unmatched = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   149
    master->stats.output_jiffies = 0;
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   150
    master->frames_timed_out = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   151
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   152
    for (i = 0; i < HZ; i++) {
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   153
        master->idle_cycle_times[i] = 0;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   154
#ifdef EC_EOE
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   155
        master->eoe_cycle_times[i] = 0;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   156
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   157
    }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   158
    master->idle_cycle_time_pos = 0;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   159
#ifdef EC_EOE
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   160
    master->eoe_cycle_time_pos = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   161
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   162
    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
   163
    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
   164
    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
   165
    master->eoe_running = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   166
    INIT_LIST_HEAD(&master->eoe_handlers);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   167
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   168
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   169
    master->internal_lock = SPIN_LOCK_UNLOCKED;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   170
    master->request_cb = NULL;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   171
    master->release_cb = NULL;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   172
    master->cb_data = NULL;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   173
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   174
    INIT_LIST_HEAD(&master->sii_requests);
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   175
    init_MUTEX(&master->sii_sem);
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   176
    init_waitqueue_head(&master->sii_queue);
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 597
diff changeset
   177
849
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   178
    INIT_LIST_HEAD(&master->slave_sdo_requests);
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   179
    init_MUTEX(&master->sdo_sem);
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   180
    init_waitqueue_head(&master->sdo_queue);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   181
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents: 902
diff changeset
   182
    // init character device
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents: 902
diff changeset
   183
    if (ec_cdev_init(&master->cdev, master, device_number))
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents: 902
diff changeset
   184
        goto out_return;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents: 902
diff changeset
   185
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   186
    // 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
   187
    if (ec_device_init(&master->main_device, master))
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents: 902
diff changeset
   188
        goto out_cdev;
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   189
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   190
    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
   191
        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
   192
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
   193
    // 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
   194
    ec_datagram_init(&master->fsm_datagram);
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 715
diff changeset
   195
    snprintf(master->fsm_datagram.name, EC_DATAGRAM_NAME_SIZE, "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
   196
    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
   197
        EC_ERR("Failed to allocate FSM datagram.\n");
659
d7c5a958bad0 Removed unecessary clearing of EoE handlers in master init function;
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   198
        goto out_clear_backup;
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
    }
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
   200
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   201
    // 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
   202
    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
   203
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   204
    // 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
   205
    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
   206
    kobject_init(&master->kobj);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   207
    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
   208
    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
   209
    
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   210
    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
   211
        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
   212
        kobject_put(&master->kobj);
659
d7c5a958bad0 Removed unecessary clearing of EoE handlers in master init function;
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   213
        goto out_clear_fsm;
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   214
    }
576
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   215
    
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 483
diff changeset
   216
    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
   217
        EC_ERR("Failed to add master kobject.\n");
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 483
diff changeset
   218
        kobject_put(&master->kobj);
659
d7c5a958bad0 Removed unecessary clearing of EoE handlers in master init function;
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   219
        goto out_clear_fsm;
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 483
diff changeset
   220
    }
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   221
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   222
    return 0;
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   223
659
d7c5a958bad0 Removed unecessary clearing of EoE handlers in master init function;
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   224
out_clear_fsm:
d7c5a958bad0 Removed unecessary clearing of EoE handlers in master init function;
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   225
    ec_fsm_master_clear(&master->fsm);
d7c5a958bad0 Removed unecessary clearing of EoE handlers in master init function;
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   226
out_clear_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
   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);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents: 902
diff changeset
   230
out_cdev:
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents: 902
diff changeset
   231
    ec_cdev_clear(&master->cdev);
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   232
out_return:
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   233
    return -1;
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 35
diff changeset
   236
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
/**
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
   239
   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
   240
   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
   241
   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
   242
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   243
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   244
void ec_master_clear(
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   245
        ec_master_t *master /**< EtherCAT master */
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   246
        )
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   247
{
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   248
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   249
    ec_master_clear_eoe_handlers(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   250
#endif
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   251
    ec_master_destroy_slave_configs(master);
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   252
    ec_master_destroy_slaves(master);
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   253
    ec_master_destroy_domains(master);
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
   254
    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
   255
    ec_datagram_clear(&master->fsm_datagram);
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   256
    ec_device_clear(&master->backup_device);
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   257
    ec_device_clear(&master->main_device);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents: 902
diff changeset
   258
    ec_cdev_clear(&master->cdev);
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   259
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   260
    // destroy self
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   261
    kobject_del(&master->kobj);
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   262
    kobject_put(&master->kobj);
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   263
}
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   264
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   265
/*****************************************************************************/
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   266
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   267
#ifdef EC_EOE
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   268
/** Clear and free all EoE handlers.
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   269
 */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   270
void ec_master_clear_eoe_handlers(
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   271
        ec_master_t *master /**< EtherCAT master */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   272
        )
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   273
{
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   274
    ec_eoe_t *eoe, *next;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   275
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   276
    list_for_each_entry_safe(eoe, next, &master->eoe_handlers, list) {
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   277
        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
   278
        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
   279
        kfree(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   280
    }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   281
}
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   282
#endif
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   283
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   284
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   285
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   286
/** Destroy all slave configurations.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   287
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   288
void ec_master_destroy_slave_configs(ec_master_t *master)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   289
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   290
    ec_slave_config_t *sc, *next;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   291
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   292
    list_for_each_entry_safe(sc, next, &master->configs, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   293
        list_del(&sc->list);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   294
        ec_slave_config_destroy(sc);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   295
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   296
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   297
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   298
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   299
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   300
/** Destroy all slaves.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   301
 */
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
   302
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
   303
{
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   304
    ec_slave_t *slave, *next;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   305
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   306
    list_for_each_entry_safe(slave, next, &master->slaves, list) {
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   307
        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
   308
        ec_slave_destroy(slave);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   309
    }
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   310
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   311
    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
   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
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   314
/*****************************************************************************/
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   315
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   316
/**
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
   317
   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
   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
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
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
   321
{
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   322
    ec_domain_t *domain, *next;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   323
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   324
    list_for_each_entry_safe(domain, next, &master->domains, 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
   325
        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
   326
        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
   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
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   330
/*****************************************************************************/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   331
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   332
/**
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   333
   Internal locking callback.
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   334
*/
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   335
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   336
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
   337
{
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   338
    spin_lock(&((ec_master_t *) master)->internal_lock);
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   339
    return 0;
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   340
}
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   341
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   342
/*****************************************************************************/
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   343
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   344
/**
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   345
   Internal unlocking 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
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
   349
{
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   350
    spin_unlock(&((ec_master_t *) master)->internal_lock);
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   351
}
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
/**
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   356
 * Starts the master thread.
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   357
 */
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   358
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   359
int ec_master_thread_start(
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   360
        ec_master_t *master, /**< EtherCAT master */
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   361
        int (*thread_func)(ec_master_t *) /**< thread function to start */
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   362
        )
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   363
{
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   364
    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
   365
540
a729667dea1e Minor changes in master thread messages.
Florian Pose <fp@igh-essen.com>
parents: 533
diff changeset
   366
    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
   367
    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
   368
                    master, CLONE_KERNEL)))
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   369
        return -1;
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
    return 0;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   372
}
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   373
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   374
/*****************************************************************************/
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   375
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   376
/**
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   377
 * Stops the master thread.
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   378
 */
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   379
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   380
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
   381
{
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   382
    if (!master->thread_id) {
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   383
        EC_WARN("ec_master_thread_stop: Already finished!\n");
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   384
        return;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   385
    }
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   386
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   387
    kill_proc(master->thread_id, SIGTERM, 1);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   388
    wait_for_completion(&master->thread_exit);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   389
    EC_INFO("Master thread exited.\n");
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   390
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   391
    if (master->fsm_datagram.state != EC_DATAGRAM_SENT) return;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   392
    
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   393
    // wait for FSM datagram
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   394
    while (get_cycles() - master->fsm_datagram.cycles_sent
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   395
            < (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000))
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   396
        schedule();
525
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
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   401
/**
527
3eea08638522 Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 525
diff changeset
   402
 * Transition function from ORPHANED to IDLE mode.
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   403
 */
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   404
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   405
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
   406
{
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   407
    master->request_cb = ec_master_request_cb;
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   408
    master->release_cb = ec_master_release_cb;
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   409
    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
   410
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   411
    master->mode = EC_MASTER_MODE_IDLE;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   412
    if (ec_master_thread_start(master, ec_master_idle_thread)) {
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   413
        master->mode = EC_MASTER_MODE_ORPHANED;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   414
        return -1;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   415
    }
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   416
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   417
    return 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   418
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   419
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   420
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   421
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   422
/**
527
3eea08638522 Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 525
diff changeset
   423
 * Transition function from IDLE to ORPHANED mode.
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   424
 */
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   425
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   426
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
   427
{
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   428
    master->mode = EC_MASTER_MODE_ORPHANED;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   429
    
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   430
#ifdef EC_EOE
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   431
    ec_master_eoe_stop(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   432
#endif
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   433
    ec_master_thread_stop(master);
589
492148a329e7 Destroy slaves when leaving idle mode.
Florian Pose <fp@igh-essen.com>
parents: 579
diff changeset
   434
    ec_master_destroy_slaves(master);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   435
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   436
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
/**
527
3eea08638522 Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 525
diff changeset
   440
 * Transition function from IDLE to OPERATION mode.
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   441
 */
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   442
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   443
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
   444
{
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   445
    ec_slave_t *slave;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   446
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   447
    ec_eoe_t *eoe;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   448
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   449
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   450
    down(&master->config_sem);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   451
    master->allow_config = 0; // temporarily disable slave configuration
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   452
    if (master->config_busy) {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   453
        up(&master->config_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   454
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   455
        // wait for slave configuration to complete
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   456
        if (wait_event_interruptible(master->config_queue,
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   457
                    !master->config_busy)) {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   458
            EC_INFO("Finishing slave configuration interrupted by signal.\n");
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   459
            goto out_allow;
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   460
        }
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   461
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   462
        if (master->debug_level)
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   463
            EC_DBG("Waiting for pending slave configuration returned.\n");
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   464
    } else {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   465
        up(&master->config_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   466
    }
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   467
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   468
    down(&master->scan_sem);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   469
    master->allow_scan = 0; // 'lock' the slave list
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   470
    if (!master->scan_busy) {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   471
        up(&master->scan_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   472
    } else {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   473
        up(&master->scan_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   474
794
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   475
        // wait for slave scan to complete
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   476
        if (wait_event_interruptible(master->scan_queue, !master->scan_busy)) {
794
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   477
            EC_INFO("Waiting for slave scan interrupted by signal.\n");
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   478
            goto out_allow;
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   479
        }
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   480
        
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   481
        if (master->debug_level)
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   482
            EC_DBG("Waiting for pending slave scan returned.\n");
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   483
    }
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   484
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   485
    // set states for all slaves
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   486
    list_for_each_entry(slave, &master->slaves, list) {
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 640
diff changeset
   487
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   488
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   489
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   490
    // ... but set EoE slaves to OP
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   491
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   492
        if (ec_eoe_is_open(eoe))
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   493
            ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP);
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   494
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   495
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   496
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   497
    if (master->debug_level)
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   498
        EC_DBG("Switching to operation mode.\n");
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   499
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   500
    master->mode = EC_MASTER_MODE_OPERATION;
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   501
    master->ext_request_cb = NULL;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   502
    master->ext_release_cb = NULL;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   503
    master->ext_cb_data = NULL;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   504
    return 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   505
    
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   506
out_allow:
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   507
    master->allow_scan = 1;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   508
    master->allow_config = 1;
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.
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   516
 */
446
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;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   522
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   523
    ec_eoe_t *eoe;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   524
#endif
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   525
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   526
    master->mode = EC_MASTER_MODE_IDLE;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   527
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   528
#ifdef EC_EOE
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   529
    ec_master_eoe_stop(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   530
#endif
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   531
    ec_master_thread_stop(master);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   532
    
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   533
    master->request_cb = ec_master_request_cb;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   534
    master->release_cb = ec_master_release_cb;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   535
    master->cb_data = master;
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
   536
    
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   537
    ec_master_destroy_slave_configs(master);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   538
    ec_master_destroy_domains(master);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   539
449
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   540
    // 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
   541
    list_for_each_entry(slave, &master->slaves, list) {
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   542
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   543
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   544
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   545
    // ... but leave EoE slaves in OP
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   546
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   547
        if (ec_eoe_is_open(eoe))
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   548
            ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP);
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   549
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   550
#endif
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
   551
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   552
    if (ec_master_thread_start(master, ec_master_idle_thread))
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   553
        EC_WARN("Failed to restart master thread!\n");
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   554
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   555
    ec_master_eoe_start(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   556
#endif
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   557
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   558
    master->allow_scan = 1;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   559
    master->allow_config = 1;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   560
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   561
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   562
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   563
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   564
/**
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   565
   Places a datagram in the datagram queue.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   566
*/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   567
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   568
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
   569
                              ec_datagram_t *datagram /**< datagram */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   570
                              )
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   571
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   572
    ec_datagram_t *queued_datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   573
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   574
    // check, if the datagram is already queued
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   575
    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
   576
        if (queued_datagram == datagram) {
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 715
diff changeset
   577
            datagram->skip_count++;
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   578
            if (master->debug_level)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   579
                EC_DBG("skipping datagram %x.\n", (unsigned int) datagram);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   580
            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
   581
            return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   582
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   583
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   584
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   585
    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
   586
    datagram->state = EC_DATAGRAM_QUEUED;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   587
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   588
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   589
/*****************************************************************************/
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
   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
   593
   \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
   594
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   595
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   596
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
   597
{
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   598
    ec_datagram_t *datagram, *next;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   599
    size_t datagram_size;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   600
    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
   601
    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
   602
    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
   603
    unsigned long jiffies_sent;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   604
    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
   605
    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
   606
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   607
    cycles_start = get_cycles();
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   608
    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
   609
    INIT_LIST_HEAD(&sent_datagrams);
208
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
   610
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   611
    if (unlikely(master->debug_level > 1))
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   612
        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
   613
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   614
    do {
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   615
        // 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
   616
        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
   617
        cur_data = frame_data + EC_FRAME_HEADER_SIZE;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   618
        follows_word = NULL;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   619
        more_datagrams_waiting = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   620
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   621
        // fill current frame with datagrams
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   622
        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
   623
            if (datagram->state != EC_DATAGRAM_QUEUED) continue;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   624
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   625
            // does the current datagram fit in the frame?
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   626
            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
   627
                + EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   628
            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
   629
                more_datagrams_waiting = 1;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   630
                break;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   631
            }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   632
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   633
            list_add_tail(&datagram->sent, &sent_datagrams);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   634
            datagram->index = master->datagram_index++;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
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("adding datagram 0x%02X\n", datagram->index);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   638
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   639
            // set "datagram following" flag in previous frame
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   640
            if (follows_word)
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   641
                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
   642
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   643
            // EtherCAT datagram header
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   644
            EC_WRITE_U8 (cur_data,     datagram->type);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   645
            EC_WRITE_U8 (cur_data + 1, datagram->index);
708
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 697
diff changeset
   646
            memcpy(cur_data + 2, datagram->address, EC_ADDR_LEN);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   647
            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
   648
            EC_WRITE_U16(cur_data + 8, 0x0000);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   649
            follows_word = cur_data + 6;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   650
            cur_data += EC_DATAGRAM_HEADER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   651
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   652
            // EtherCAT datagram data
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   653
            memcpy(cur_data, datagram->data, datagram->data_size);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   654
            cur_data += datagram->data_size;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   655
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   656
            // EtherCAT datagram footer
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   657
            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
   658
            cur_data += EC_DATAGRAM_FOOTER_SIZE;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   659
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   660
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   661
        if (list_empty(&sent_datagrams)) {
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   662
            if (unlikely(master->debug_level > 1))
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   663
                EC_DBG("nothing to send.\n");
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   664
            break;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   665
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   666
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   667
        // EtherCAT frame header
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   668
        EC_WRITE_U16(frame_data, ((cur_data - frame_data
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   669
                                   - EC_FRAME_HEADER_SIZE) & 0x7FF) | 0x1000);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   670
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   671
        // pad frame
211
c684b6b7adaf Using kernel Ethernet constants.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
   672
        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
   673
            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
   674
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   675
        if (unlikely(master->debug_level > 1))
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   676
            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
   677
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   678
        // 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
   679
        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
   680
        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
   681
        jiffies_sent = jiffies;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   682
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   683
        // 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
   684
        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
   685
            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
   686
            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
   687
            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
   688
            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
   689
        }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   690
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   691
        frame_count++;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   692
    }
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   693
    while (more_datagrams_waiting);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   694
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   695
    if (unlikely(master->debug_level > 1)) {
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   696
        cycles_end = get_cycles();
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   697
        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
   698
               frame_count,
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   699
               (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
   700
    }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   701
}
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   702
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   703
/*****************************************************************************/
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   704
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   705
/**
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   706
   Processes a received frame.
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   707
   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
   708
   \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
   709
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   710
331
17f58fe99511 Renamed ec_master_receive() to ec_master_receive_datagrams().
Florian Pose <fp@igh-essen.com>
parents: 330
diff changeset
   711
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
   712
                                 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
   713
                                 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
   714
                                 )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   715
{
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   716
    size_t frame_size, data_size;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   717
    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
   718
    unsigned int cmd_follows, matched;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   719
    const uint8_t *cur_data;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   720
    ec_datagram_t *datagram;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   721
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   722
    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
   723
        master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   724
        ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   725
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   726
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   727
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   728
    cur_data = frame_data;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   729
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   730
    // 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
   731
    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
   732
    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
   733
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   734
    if (unlikely(frame_size > size)) {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   735
        master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   736
        ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   737
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   738
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   739
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   740
    cmd_follows = 1;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   741
    while (cmd_follows) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   742
        // process datagram header
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   743
        datagram_type  = EC_READ_U8 (cur_data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   744
        datagram_index = EC_READ_U8 (cur_data + 1);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   745
        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
   746
        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
   747
        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
   748
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   749
        if (unlikely(cur_data - frame_data
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   750
                     + 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
   751
            master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   752
            ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   753
            return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   754
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   755
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   756
        // 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
   757
        matched = 0;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   758
        list_for_each_entry(datagram, &master->datagram_queue, queue) {
690
5e231f6a3d2e Re-ordered criteria for datagram matching.
Florian Pose <fp@igh-essen.com>
parents: 688
diff changeset
   759
            if (datagram->index == datagram_index
5e231f6a3d2e Re-ordered criteria for datagram matching.
Florian Pose <fp@igh-essen.com>
parents: 688
diff changeset
   760
                && datagram->state == EC_DATAGRAM_SENT
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   761
                && datagram->type == datagram_type
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   762
                && 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
   763
                matched = 1;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   764
                break;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   765
            }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   766
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   767
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   768
        // 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
   769
        if (!matched) {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   770
            master->stats.unmatched++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   771
            ec_master_output_stats(master);
684
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
   772
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
   773
            if (unlikely(master->debug_level > 0)) {
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
   774
                EC_DBG("UNMATCHED datagram:\n");
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
   775
                ec_print_data(cur_data - EC_DATAGRAM_HEADER_SIZE,
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
   776
                        EC_DATAGRAM_HEADER_SIZE + data_size
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
   777
                        + EC_DATAGRAM_FOOTER_SIZE);
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 691
diff changeset
   778
#ifdef EC_DEBUG_RING
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 691
diff changeset
   779
                ec_device_debug_ring_print(&master->main_device);
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 691
diff changeset
   780
#endif
684
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
   781
            }
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
   782
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   783
            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
   784
            continue;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   785
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   786
345
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   787
        // copy received data into the datagram memory
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   788
        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
   789
        cur_data += data_size;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   790
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   791
        // set the datagram's working counter
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   792
        datagram->working_counter = EC_READ_U16(cur_data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   793
        cur_data += EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   794
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   795
        // 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
   796
        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
   797
        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
   798
        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
   799
        list_del_init(&datagram->queue);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   800
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   801
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   802
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   803
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   804
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   805
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   806
   Output statistics in cyclic mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   807
   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
   808
   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
   809
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   810
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   811
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
   812
{
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   813
    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
   814
        master->stats.output_jiffies = jiffies;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   815
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   816
        if (master->stats.timeouts) {
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   817
            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
   818
                    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
   819
            master->stats.timeouts = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   820
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   821
        if (master->stats.corrupted) {
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   822
            EC_WARN("%i frame%s CORRUPTED!\n", master->stats.corrupted,
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   823
                    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
   824
            master->stats.corrupted = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   825
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   826
        if (master->stats.unmatched) {
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   827
            EC_WARN("%i datagram%s UNMATCHED!\n", master->stats.unmatched,
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   828
                    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
   829
            master->stats.unmatched = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   830
        }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   831
    }
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   832
}
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   833
68
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   834
/*****************************************************************************/
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   835
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   836
/**
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   837
 * 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
   838
 */
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   839
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   840
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
   841
{
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   842
    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
   843
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   844
    daemonize("EtherCAT-IDLE");
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   845
    allow_signal(SIGTERM);
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   846
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   847
    while (!signal_pending(current)) {
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   848
        cycles_start = get_cycles();
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 715
diff changeset
   849
        ec_datagram_output_stats(&master->fsm_datagram);
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   850
691
77b79a29e0e7 Included datagram queuing in critical section in idle task; added some
Florian Pose <fp@igh-essen.com>
parents: 690
diff changeset
   851
        if (ec_fsm_master_running(&master->fsm)) { // datagram on the way
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   852
            // receive
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   853
            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
   854
            ecrt_master_receive(master);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   855
            spin_unlock_bh(&master->internal_lock);
691
77b79a29e0e7 Included datagram queuing in critical section in idle task; added some
Florian Pose <fp@igh-essen.com>
parents: 690
diff changeset
   856
77b79a29e0e7 Included datagram queuing in critical section in idle task; added some
Florian Pose <fp@igh-essen.com>
parents: 690
diff changeset
   857
            if (master->fsm_datagram.state == EC_DATAGRAM_SENT)
77b79a29e0e7 Included datagram queuing in critical section in idle task; added some
Florian Pose <fp@igh-essen.com>
parents: 690
diff changeset
   858
                goto schedule;
77b79a29e0e7 Included datagram queuing in critical section in idle task; added some
Florian Pose <fp@igh-essen.com>
parents: 690
diff changeset
   859
        }
651
8c11399cc911 Fixed skipped datagrams when not in FSM idle phase.
Florian Pose <fp@igh-essen.com>
parents: 650
diff changeset
   860
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   861
        // execute master state machine
691
77b79a29e0e7 Included datagram queuing in critical section in idle task; added some
Florian Pose <fp@igh-essen.com>
parents: 690
diff changeset
   862
        if (ec_fsm_master_exec(&master->fsm)) { // datagram ready for sending
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   863
            // queue and send
691
77b79a29e0e7 Included datagram queuing in critical section in idle task; added some
Florian Pose <fp@igh-essen.com>
parents: 690
diff changeset
   864
            spin_lock_bh(&master->internal_lock);
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   865
            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
   866
            ecrt_master_send(master);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   867
            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
   868
        }
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   869
        
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   870
        cycles_end = get_cycles();
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   871
        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
   872
            = (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
   873
        master->idle_cycle_time_pos++;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   874
        master->idle_cycle_time_pos %= HZ;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   875
651
8c11399cc911 Fixed skipped datagrams when not in FSM idle phase.
Florian Pose <fp@igh-essen.com>
parents: 650
diff changeset
   876
schedule:
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   877
        if (ec_fsm_master_idle(&master->fsm)) {
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   878
            set_current_state(TASK_INTERRUPTIBLE);
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   879
            schedule_timeout(1);
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   880
        }
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   881
        else {
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   882
            schedule();
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   883
        }
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   884
    }
518
b6a1426ba724 Fixed race: Stop EoE processing when entering or leaving operation mode.
Florian Pose <fp@igh-essen.com>
parents: 517
diff changeset
   885
    
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   886
    master->thread_id = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   887
    if (master->debug_level)
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   888
        EC_DBG("Master IDLE thread exiting...\n");
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   889
    complete_and_exit(&master->thread_exit, 0);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   890
}
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   891
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   892
/*****************************************************************************/
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   893
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   894
/**
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   895
 * 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
   896
 */
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   897
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   898
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
   899
{
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   900
    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
   901
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   902
    daemonize("EtherCAT-OP");
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   903
    allow_signal(SIGTERM);
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   904
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   905
    while (!signal_pending(current)) {
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 715
diff changeset
   906
        ec_datagram_output_stats(&master->fsm_datagram);
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   907
        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
   908
                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
   909
                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
   910
            goto schedule;
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
        cycles_start = get_cycles();
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   913
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   914
        // output statistics
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   915
        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
   916
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   917
        // execute master state machine
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   918
        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
   919
            // inject datagram
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   920
            master->injection_seq_fsm++;
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
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   923
        cycles_end = get_cycles();
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   924
        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
   925
            = (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
   926
        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
   927
        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
   928
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   929
schedule:
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   930
        if (ec_fsm_master_idle(&master->fsm)) {
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   931
            set_current_state(TASK_INTERRUPTIBLE);
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   932
            schedule_timeout(1);
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   933
        }
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   934
        else {
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   935
            schedule();
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   936
        }
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   937
    }
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   938
    
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   939
    master->thread_id = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   940
    if (master->debug_level)
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   941
        EC_DBG("Master OP thread exiting...\n");
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   942
    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
   943
}
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   944
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
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   947
/**
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   948
 * Prints the device information to a buffer.
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   949
 * \return number of bytes written.
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   950
 */
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   951
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   952
ssize_t ec_master_device_info(
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   953
        const ec_device_t *device, /**< EtherCAT device */
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   954
        const uint8_t *mac, /**< MAC address */
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   955
        char *buffer /**< target buffer */
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   956
        )
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   957
{
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   958
    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
   959
    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
   960
    
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   961
    if (ec_mac_is_zero(mac)) {
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   962
        off += sprintf(buffer + off, "none.\n");
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   963
    }
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   964
    else {
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   965
        off += ec_mac_print(mac, buffer + off);
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   966
    
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   967
        if (device->dev) {
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   968
            off += sprintf(buffer + off, " (connected).\n");      
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   969
            off += sprintf(buffer + off, "    Frames sent:     %u\n",
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   970
                    device->tx_count);
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   971
            off += sprintf(buffer + off, "    Frames received: %u\n",
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   972
                    device->rx_count);
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   973
            frames_lost = device->tx_count - device->rx_count;
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   974
            if (frames_lost) frames_lost--;
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   975
            off += sprintf(buffer + off, "    Frames lost:     %u\n", frames_lost);
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   976
        }
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   977
        else {
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   978
            off += sprintf(buffer + off, " (WAITING).\n");      
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   979
        }
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   980
    }
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   981
    
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   982
    return off;
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   983
}
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
   984
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   985
/*****************************************************************************/
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   986
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   987
/**
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   988
   Formats master information for SysFS read access.
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   989
   \return number of bytes written
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   990
*/
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   991
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   992
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
   993
                       char *buffer /**< memory to store data */
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   994
                       )
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   995
{
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
   996
    off_t off = 0;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   997
#ifdef EC_EOE
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
   998
    ec_eoe_t *eoe;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   999
#endif
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1000
    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
  1001
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1002
    off += sprintf(buffer + off, "\nMode: ");
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1003
    switch (master->mode) {
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1004
        case EC_MASTER_MODE_ORPHANED:
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1005
            off += sprintf(buffer + off, "ORPHANED");
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1006
            break;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1007
        case EC_MASTER_MODE_IDLE:
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1008
            off += sprintf(buffer + off, "IDLE");
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1009
            break;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1010
        case EC_MASTER_MODE_OPERATION:
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1011
            off += sprintf(buffer + off, "OPERATION");
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1012
            break;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1013
    }
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1014
339
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 337
diff changeset
  1015
    off += sprintf(buffer + off, "\nSlaves: %i\n",
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1016
                   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
  1017
    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
  1018
    
648
0a6d38ec463f Made waiting for device semaphore uninterruptible.
Florian Pose <fp@igh-essen.com>
parents: 647
diff changeset
  1019
    down(&master->device_sem);
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1020
    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
  1021
    off += ec_master_device_info(&master->main_device,
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1022
            master->main_mac, buffer + off);
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1023
    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
  1024
    off += ec_master_device_info(&master->backup_device,
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
  1025
            master->backup_mac, buffer + off);
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1026
    up(&master->device_sem);
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1027
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1028
    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
  1029
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1030
    sum = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1031
    min = 0xFFFFFFFF;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1032
    max = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1033
    pos = master->idle_cycle_time_pos;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1034
    for (i = 0; i < HZ; i++) {
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1035
        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
  1036
        sum += cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1037
        if (cur < min) min = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1038
        if (cur > max) max = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1039
    }
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1040
    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
  1041
                   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
  1042
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1043
#ifdef EC_EOE
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1044
    sum = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1045
    min = 0xFFFFFFFF;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1046
    max = 0;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1047
    pos = master->eoe_cycle_time_pos;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1048
    for (i = 0; i < HZ; i++) {
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1049
        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
  1050
        sum += cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1051
        if (cur < min) min = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1052
        if (cur > max) max = cur;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1053
    }
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1054
    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
  1055
                   min, sum / HZ, (sum * 100 / HZ) % 100, max);
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1056
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
  1057
    if (!list_empty(&master->eoe_handlers))
339
a3a4ee854bd8 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 337
diff changeset
  1058
        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
  1059
    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
  1060
        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
  1061
                       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
  1062
                       ((eoe->rx_rate + eoe->tx_rate) / 8 + 512) / 1024);
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
  1063
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1064
#endif
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 335
diff changeset
  1065
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1066
    off += sprintf(buffer + off, "\n");
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1067
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1068
    return off;
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1069
}
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1070
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1071
/*****************************************************************************/
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1072
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1073
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1074
   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
  1075
   \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
  1076
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1077
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1078
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
  1079
                                 struct attribute *attr, /**< attribute */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1080
                                 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
  1081
                                 )
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1082
{
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1083
    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
  1084
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1085
    if (attr == &attr_info) {
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1086
        return ec_master_info(master, buffer);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1087
    }
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1088
    else if (attr == &attr_debug_level) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1089
        return sprintf(buffer, "%i\n", master->debug_level);
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1090
    }
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1091
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1092
    return 0;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1093
}
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1094
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1095
/*****************************************************************************/
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1096
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
  1097
/**
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1098
   Formats attribute data for SysFS write access.
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1099
   \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
  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
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
  1103
                                  struct attribute *attr, /**< attribute */
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1104
                                  const char *buffer, /**< memory with data */
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1105
                                  size_t size /**< size of data to store */
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1106
                                  )
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1107
{
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1108
    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
  1109
597
3a2c2d6ca5e9 Removed eeprom_write_enable file.
Florian Pose <fp@igh-essen.com>
parents: 589
diff changeset
  1110
    if (attr == &attr_debug_level) {
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1111
        if (!strcmp(buffer, "0\n")) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1112
            master->debug_level = 0;
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 if (!strcmp(buffer, "1\n")) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1115
            master->debug_level = 1;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1116
        }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1117
        else if (!strcmp(buffer, "2\n")) {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1118
            master->debug_level = 2;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1119
        }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1120
        else {
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1121
            EC_ERR("Invalid debug level value!\n");
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1122
            return -EINVAL;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1123
        }
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1124
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1125
        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
  1126
        return size;
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1127
    }
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1128
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1129
    return -EINVAL;
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1130
}
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1131
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1132
/*****************************************************************************/
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1133
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1134
#ifdef EC_EOE
268
4f9c149fb71f EEPROM write enable SysFS entry.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
  1135
/**
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
  1136
   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
  1137
*/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1138
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1139
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
  1140
{
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1141
    if (master->eoe_running) {
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1142
        EC_WARN("EoE already running!\n");
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1143
        return;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1144
    }
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1145
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1146
    if (list_empty(&master->eoe_handlers))
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1147
        return;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1148
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1149
    if (!master->request_cb || !master->release_cb) {
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1150
        EC_WARN("No EoE processing because of missing locking callbacks!\n");
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1151
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1152
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1153
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1154
    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
  1155
    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
  1156
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1157
    // start EoE processing
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1158
    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
  1159
    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
  1160
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1161
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1162
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1163
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
   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
  1166
*/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1167
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1168
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
  1169
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1170
    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
  1171
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1172
    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
  1173
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1174
    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
  1175
    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
  1176
}
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
/*****************************************************************************/
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1179
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1180
/**
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1181
   Does the Ethernet-over-EtherCAT processing.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1182
*/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1183
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1184
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
  1185
{
60a10d85c20b Prepared EoE processing with workqueue.
Florian Pose <fp@igh-essen.com>
parents: 204
diff changeset
  1186
    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
  1187
    ec_eoe_t *eoe;
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1188
    unsigned int none_open = 1;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1189
    cycles_t cycles_start, cycles_end;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1190
    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
  1191
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1192
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1193
        if (ec_eoe_is_open(eoe)) {
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1194
            none_open = 0;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1195
            break;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1196
        }
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1197
    }
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1198
    if (none_open)
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1199
        goto queue_timer;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1200
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1201
    // receive datagrams
663
38d9c37664d9 Completely lock master while an EoE cycle is executing.
Florian Pose <fp@igh-essen.com>
parents: 661
diff changeset
  1202
    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
  1203
    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
  1204
    ecrt_master_receive(master);
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1205
    master->release_cb(master->cb_data);
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1206
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1207
    // 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
  1208
    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
  1209
        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
  1210
    }
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1211
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1212
    // send datagrams
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1213
    if (master->request_cb(master->cb_data)) {
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1214
        goto queue_timer;
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1215
    }
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1216
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1217
        ec_eoe_queue(eoe);
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1218
    }
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1219
    ecrt_master_send(master);
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1220
    master->release_cb(master->cb_data);
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1221
    cycles_end = get_cycles();
663
38d9c37664d9 Completely lock master while an EoE cycle is executing.
Florian Pose <fp@igh-essen.com>
parents: 661
diff changeset
  1222
335
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1223
    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
  1224
        = (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
  1225
    master->eoe_cycle_time_pos++;
1e37c856b74e Better EoE and Idle timing measurement.
Florian Pose <fp@igh-essen.com>
parents: 334
diff changeset
  1226
    master->eoe_cycle_time_pos %= HZ;
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1227
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1228
 queue_timer:
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1229
    restart_jiffies = HZ / EC_EOE_FREQUENCY;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1230
    if (!restart_jiffies) restart_jiffies = 1;
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1231
    master->eoe_timer.expires = jiffies + restart_jiffies;
208
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
  1232
    add_timer(&master->eoe_timer);
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1233
}
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1234
#endif
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1235
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1236
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1237
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1238
/** Detaches the slave configurations from the slaves.
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1239
 */
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1240
void ec_master_detach_slave_configs(
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1241
        ec_master_t *master /**< EtherCAT master. */
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1242
        )
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1243
{
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1244
    ec_slave_config_t *sc;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1245
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1246
    if (!master->configs_attached)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1247
        return;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1248
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1249
    list_for_each_entry(sc, &master->configs, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1250
        ec_slave_config_detach(sc); 
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1251
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1252
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1253
    master->configs_attached = 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1254
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1255
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1256
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1257
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1258
/** Attaches the slave configurations to the slaves.
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1259
 */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1260
int ec_master_attach_slave_configs(
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1261
        ec_master_t *master /**< EtherCAT master. */
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1262
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1263
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1264
    ec_slave_config_t *sc;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1265
    unsigned int errors = 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1266
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1267
    if (master->configs_attached)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1268
        return 0;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1269
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1270
    list_for_each_entry(sc, &master->configs, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1271
        if (ec_slave_config_attach(sc))
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1272
            errors = 1;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1273
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1274
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1275
    master->configs_attached = !errors;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1276
    return errors ? -1 : 0;
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1277
}
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1278
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1279
/*****************************************************************************/
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1280
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1281
/** Finds a slave in the bus, given the alias and position.
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1282
 */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1283
ec_slave_t *ec_master_find_slave(
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1284
        ec_master_t *master, /**< EtherCAT master. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1285
        uint16_t alias, /**< Slave alias. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1286
        uint16_t position /**< Slave position. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1287
        )
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1288
{
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1289
    ec_slave_t *slave;
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1290
    unsigned int alias_found = 0, relative_position = 0;
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1291
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1292
	list_for_each_entry(slave, &master->slaves, list) {
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1293
        if (!alias_found) {
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1294
			if (alias && slave->sii.alias != alias)
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1295
				continue;
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1296
			alias_found = 1;
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1297
			relative_position = 0;
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1298
		}
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1299
		if (relative_position == position) {
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1300
            return slave;
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1301
        }
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1302
		relative_position++;
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1303
	}
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1304
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1305
    return NULL;
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1306
}
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1307
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1308
/******************************************************************************
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1309
 *  Realtime interface
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1310
 *****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1311
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1312
ec_domain_t *ecrt_master_create_domain(ec_master_t *master /**< master */)
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1313
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1314
    ec_domain_t *domain, *last_domain;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1315
    unsigned int index;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1316
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1317
    if (!(domain = (ec_domain_t *) kmalloc(sizeof(ec_domain_t), GFP_KERNEL))) {
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1318
        EC_ERR("Error allocating domain memory!\n");
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1319
        return NULL;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1320
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1321
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1322
    if (list_empty(&master->domains)) index = 0;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1323
    else {
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1324
        last_domain = list_entry(master->domains.prev, ec_domain_t, list);
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1325
        index = last_domain->index + 1;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1326
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1327
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1328
    if (ec_domain_init(domain, master, index)) {
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1329
        EC_ERR("Failed to init domain.\n");
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1330
        return NULL;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1331
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1332
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1333
    list_add_tail(&domain->list, &master->domains);
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1334
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1335
    return domain;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1336
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1337
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1338
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1339
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1340
int ecrt_master_activate(ec_master_t *master)
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1341
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1342
    uint32_t domain_offset;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1343
    ec_domain_t *domain;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1344
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1345
    // finish all domains
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1346
    domain_offset = 0;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1347
    list_for_each_entry(domain, &master->domains, list) {
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1348
        if (ec_domain_finish(domain, domain_offset)) {
926
6bb33c6ec770 Output subindices with %02X.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1349
            EC_ERR("Failed to finish domain 0x%08X!\n", (u32) domain);
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1350
            return -1;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1351
        }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1352
        domain_offset += domain->data_size;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1353
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1354
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1355
    // restart EoE process and master thread with new locking
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1356
#ifdef EC_EOE
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1357
    ec_master_eoe_stop(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1358
#endif
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1359
    ec_master_thread_stop(master);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1360
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1361
    if (master->debug_level)
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1362
        EC_DBG("FSM datagram is %x.\n", (unsigned int) &master->fsm_datagram);
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1363
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1364
    master->injection_seq_fsm = 0;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1365
    master->injection_seq_rt = 0;
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1366
    master->request_cb = master->ext_request_cb;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1367
    master->release_cb = master->ext_release_cb;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1368
    master->cb_data = master->ext_cb_data;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1369
    
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1370
    if (ec_master_thread_start(master, ec_master_operation_thread)) {
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1371
        EC_ERR("Failed to start master thread!\n");
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1372
        return -1;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1373
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1374
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1375
    ec_master_eoe_start(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1376
#endif
902
ad703091a32b Moved setting of the allow flags.
Florian Pose <fp@igh-essen.com>
parents: 901
diff changeset
  1377
ad703091a32b Moved setting of the allow flags.
Florian Pose <fp@igh-essen.com>
parents: 901
diff changeset
  1378
    master->allow_config = 1; // request the current configuration
ad703091a32b Moved setting of the allow flags.
Florian Pose <fp@igh-essen.com>
parents: 901
diff changeset
  1379
    master->allow_scan = 1; // allow re-scanning on topology change
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1380
    return 0;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1381
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1382
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1383
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1384
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1385
void ecrt_master_send(ec_master_t *master)
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1386
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1387
    ec_datagram_t *datagram, *n;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1388
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1389
    if (master->injection_seq_rt != master->injection_seq_fsm) {
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1390
        // inject datagram produced by master FSM
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1391
        ec_master_queue_datagram(master, &master->fsm_datagram);
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1392
        master->injection_seq_rt = master->injection_seq_fsm;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1393
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1394
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1395
    if (unlikely(!master->main_device.link_state)) {
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1396
        // link is down, no datagram can be sent
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1397
        list_for_each_entry_safe(datagram, n, &master->datagram_queue, queue) {
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1398
            datagram->state = EC_DATAGRAM_ERROR;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1399
            list_del_init(&datagram->queue);
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1400
        }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1401
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1402
        // query link state
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1403
        ec_device_poll(&master->main_device);
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1404
        return;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1405
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1406
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1407
    // send frames
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1408
    ec_master_send_datagrams(master);
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1409
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1410
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1411
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1412
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1413
void ecrt_master_receive(ec_master_t *master)
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1414
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1415
    ec_datagram_t *datagram, *next;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1416
    cycles_t cycles_timeout;
664
18c48cb7de06 Introduced frames_timed_out flag to notice bus failure when link down is
Florian Pose <fp@igh-essen.com>
parents: 663
diff changeset
  1417
    unsigned int frames_timed_out = 0;
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1418
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1419
    // receive datagrams
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1420
    ec_device_poll(&master->main_device);
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1421
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1422
    cycles_timeout = (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000);
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1423
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1424
    // dequeue all datagrams that timed out
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1425
    list_for_each_entry_safe(datagram, next, &master->datagram_queue, queue) {
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1426
        if (datagram->state != EC_DATAGRAM_SENT) continue;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1427
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1428
        if (master->main_device.cycles_poll - datagram->cycles_sent
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1429
            > cycles_timeout) {
664
18c48cb7de06 Introduced frames_timed_out flag to notice bus failure when link down is
Florian Pose <fp@igh-essen.com>
parents: 663
diff changeset
  1430
            frames_timed_out = 1;
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1431
            list_del_init(&datagram->queue);
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1432
            datagram->state = EC_DATAGRAM_TIMED_OUT;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1433
            master->stats.timeouts++;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1434
            ec_master_output_stats(master);
684
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1435
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1436
            if (unlikely(master->debug_level > 0)) {
691
77b79a29e0e7 Included datagram queuing in critical section in idle task; added some
Florian Pose <fp@igh-essen.com>
parents: 690
diff changeset
  1437
                EC_DBG("TIMED OUT datagram %08x, index %02X waited %u us.\n",
77b79a29e0e7 Included datagram queuing in critical section in idle task; added some
Florian Pose <fp@igh-essen.com>
parents: 690
diff changeset
  1438
                        (unsigned int) datagram, datagram->index,
684
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1439
                        (unsigned int) (master->main_device.cycles_poll
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1440
                            - datagram->cycles_sent) * 1000 / cpu_khz);
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1441
            }
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1442
        }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1443
    }
664
18c48cb7de06 Introduced frames_timed_out flag to notice bus failure when link down is
Florian Pose <fp@igh-essen.com>
parents: 663
diff changeset
  1444
18c48cb7de06 Introduced frames_timed_out flag to notice bus failure when link down is
Florian Pose <fp@igh-essen.com>
parents: 663
diff changeset
  1445
    master->frames_timed_out = frames_timed_out;
640
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1446
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1447
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1448
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1449
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1450
ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master,
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1451
        uint16_t alias, uint16_t position, uint32_t vendor_id,
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1452
        uint32_t product_code)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1453
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1454
    ec_slave_config_t *sc;
697
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1455
    unsigned int found = 0;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1456
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1457
    list_for_each_entry(sc, &master->configs, list) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1458
        if (sc->alias == alias && sc->position == position) {
697
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1459
            found = 1;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1460
            break;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1461
        }
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1462
    }
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1463
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1464
    if (found) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1465
        if (master->debug_level) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1466
            EC_INFO("Using existing slave configuration for %u:%u\n",
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1467
                    alias, position);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1468
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1469
        if (sc->vendor_id != vendor_id || sc->product_code != product_code) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1470
            EC_ERR("Slave type mismatch. Slave was configured as"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1471
                    " 0x%08X/0x%08X before. Now configuring with"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1472
                    " 0x%08X/0x%08X.\n", sc->vendor_id, sc->product_code,
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1473
                    vendor_id, product_code);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1474
            return NULL;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1475
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1476
    } else {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1477
        if (master->debug_level) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1478
            EC_INFO("Creating slave configuration for %u:%u,"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1479
                    " 0x%08X/0x%08X.\n", alias, position, vendor_id,
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1480
                    product_code);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1481
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1482
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1483
        if (!(sc = (ec_slave_config_t *) kmalloc(sizeof(ec_slave_config_t),
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1484
                        GFP_KERNEL))) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1485
            EC_ERR("Failed to allocate memory for slave configuration.\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1486
            return NULL;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1487
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1488
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1489
        if (ec_slave_config_init(sc, master, alias, position, vendor_id,
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1490
                    product_code)) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1491
            EC_ERR("Failed to init slave configuration.\n");
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1492
            return NULL;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1493
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1494
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1495
        // try to find the addressed slave
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1496
        ec_slave_config_attach(sc);
879
9b395c5646ab Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
  1497
        ec_slave_config_load_default_assignment(sc);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1498
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1499
        list_add_tail(&sc->list, &master->configs);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1500
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1501
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1502
    return sc;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1503
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1504
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1505
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1506
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1507
void ecrt_master_callbacks(ec_master_t *master, int (*request_cb)(void *),
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1508
        void (*release_cb)(void *), void *cb_data)
204
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1509
{
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1510
    master->ext_request_cb = request_cb;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1511
    master->ext_release_cb = release_cb;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1512
    master->ext_cb_data = cb_data;
204
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1513
}
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1514
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1515
/*****************************************************************************/
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1516
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1517
void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state)
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1518
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1519
    state->slaves_responding = master->fsm.slaves_responding;
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1520
}
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1521
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1522
/*****************************************************************************/
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1523
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1524
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1525
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1526
EXPORT_SYMBOL(ecrt_master_create_domain);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1527
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
  1528
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
  1529
EXPORT_SYMBOL(ecrt_master_receive);
206
60a10d85c20b Prepared EoE processing with workqueue.
Florian Pose <fp@igh-essen.com>
parents: 204
diff changeset
  1530
EXPORT_SYMBOL(ecrt_master_callbacks);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1531
EXPORT_SYMBOL(ecrt_master_slave_config);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1532
EXPORT_SYMBOL(ecrt_master_state);
42
a22a202d0f42 Domains, Warten beim Senden, 10kHz.
Florian Pose <fp@igh-essen.com>
parents: 39
diff changeset
  1533
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1534
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1535
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1536
/*****************************************************************************/