master/master.c
author Florian Pose <fp@igh-essen.com>
Mon, 20 Apr 2009 10:27:36 +0000
changeset 1404 b7ea043d5081
parent 1399 f79d4bb5b23a
child 1408 91b35db64a24
permissions -rw-r--r--
Minor changes.
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
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     6
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     8
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    11
 *  published by the Free Software Foundation.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    12
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    16
 *  Public License for more details.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    17
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 239
diff changeset
    27
 *
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 35
diff changeset
    28
 *****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    30
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    31
   \file
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    32
   EtherCAT master methods.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    33
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    34
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    35
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    36
24
d417dd9bdc2f Wilhelms ?nderungen ?bernommen.
Florian Pose <fp@igh-essen.com>
parents: 23
diff changeset
    37
#include <linux/module.h>
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include <linux/kernel.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include <linux/string.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include <linux/slab.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <linux/delay.h>
1015
24efac66a647 Added support for different versions of class_device_create().
Florian Pose <fp@igh-essen.com>
parents: 1013
diff changeset
    42
#include <linux/device.h>
24efac66a647 Added support for different versions of class_device_create().
Florian Pose <fp@igh-essen.com>
parents: 1013
diff changeset
    43
#include <linux/version.h>
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    45
#include "globals.h"
55
059a9e712aa7 Mit neuer Schnittstelle wieder lauff?hig.
Florian Pose <fp@igh-essen.com>
parents: 54
diff changeset
    46
#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
    47
#include "slave_config.h"
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    48
#include "device.h"
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
    49
#include "datagram.h"
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    50
#ifdef EC_EOE
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
    51
#include "ethernet.h"
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    52
#endif
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    53
#include "master.h"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    54
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    55
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    56
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    57
#ifdef EC_HAVE_CYCLES
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    58
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    59
/** Frame timeout in cycles.
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    60
 */
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    61
static cycles_t timeout_cycles;
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    62
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    63
#else
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    64
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    65
/** Frame timeout in jiffies.
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    66
 */
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    67
static unsigned long timeout_jiffies;
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    68
    
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    69
#endif
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    70
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    71
/*****************************************************************************/
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    72
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
    73
void ec_master_clear_slave_configs(ec_master_t *);
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
    74
void ec_master_clear_domains(ec_master_t *);
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
    75
static int ec_master_idle_thread(void *);
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
    76
static int ec_master_operation_thread(void *);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    77
#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
    78
void ec_master_eoe_run(unsigned long);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    79
#endif
179
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    80
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    81
/*****************************************************************************/
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    82
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    83
/** Static variables initializer.
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    84
*/
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    85
void ec_master_init_static(void)
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    86
{
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    87
#ifdef EC_HAVE_CYCLES
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    88
    timeout_cycles = (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000);
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    89
#else
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    90
    // one jiffy may always elapse between time measurement
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    91
    timeout_jiffies = max(EC_IO_TIMEOUT * HZ / 1000000, 1);
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    92
#endif
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    93
}
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    94
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    95
/*****************************************************************************/
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    96
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    98
   Master constructor.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    99
   \return 0 in case of success, else < 0
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   100
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   101
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   102
int ec_master_init(ec_master_t *master, /**< EtherCAT master */
576
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   103
        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
   104
        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
   105
        const uint8_t *backup_mac, /**< MAC address of backup device */
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   106
        dev_t device_number, /**< Character device number. */
1399
f79d4bb5b23a Added debug_level module parameter. debug_level is now unsigned int.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
   107
        struct class *class, /**< Device class. */
f79d4bb5b23a Added debug_level module parameter. debug_level is now unsigned int.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
   108
        unsigned int debug_level /**< Debug level (module parameter). */
576
158c5a3d0a2a New module file /sys/ethercat, masters moved to /sys/ethercat/masterX.
Florian Pose <fp@igh-essen.com>
parents: 573
diff changeset
   109
        )
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   110
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   111
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   112
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   113
    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
   114
    master->reserved = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   115
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   116
    init_MUTEX(&master->master_sem);
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   117
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   118
    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
   119
    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
   120
    init_MUTEX(&master->device_sem);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   121
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   122
    master->phase = EC_ORPHANED;
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   123
    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
   124
    master->injection_seq_rt = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   125
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   126
    master->slaves = NULL;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   127
    master->slave_count = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   128
    
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   129
    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
   130
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   131
    master->scan_busy = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   132
    master->allow_scan = 1;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   133
    init_MUTEX(&master->scan_sem);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   134
    init_waitqueue_head(&master->scan_queue);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   135
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   136
    master->config_busy = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   137
    master->allow_config = 1;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   138
    init_MUTEX(&master->config_sem);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   139
    init_waitqueue_head(&master->config_queue);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   140
    
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   141
    INIT_LIST_HEAD(&master->datagram_queue);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   142
    master->datagram_index = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   143
95
0066de7a456d Domains als Liste verwaltet.
Florian Pose <fp@igh-essen.com>
parents: 94
diff changeset
   144
    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
   145
1399
f79d4bb5b23a Added debug_level module parameter. debug_level is now unsigned int.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
   146
    master->debug_level = debug_level;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   147
    master->stats.timeouts = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   148
    master->stats.corrupted = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   149
    master->stats.unmatched = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   150
    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
   151
    master->frames_timed_out = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   152
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   153
    master->thread = NULL;
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   154
1041
42c9ac58d9ce Removed state machine cycle time measuring.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   155
#ifdef EC_EOE
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   156
    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
   157
    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
   158
    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
   159
    master->eoe_running = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   160
    INIT_LIST_HEAD(&master->eoe_handlers);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   161
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   162
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   163
    master->internal_lock = SPIN_LOCK_UNLOCKED;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   164
    master->request_cb = NULL;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   165
    master->release_cb = NULL;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   166
    master->cb_data = NULL;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   167
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   168
    INIT_LIST_HEAD(&master->sii_requests);
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   169
    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
   170
849
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   171
    INIT_LIST_HEAD(&master->slave_sdo_requests);
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 643
diff changeset
   172
    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
   173
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1369
diff changeset
   174
    INIT_LIST_HEAD(&master->reg_requests);
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1369
diff changeset
   175
    init_waitqueue_head(&master->reg_queue);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1198
diff changeset
   176
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1332
diff changeset
   177
    INIT_LIST_HEAD(&master->foe_requests);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1332
diff changeset
   178
    init_waitqueue_head(&master->foe_queue);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1332
diff changeset
   179
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   180
    // init devices
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   181
    ret = ec_device_init(&master->main_device, master);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   182
    if (ret < 0)
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   183
        goto out_return;
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   184
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   185
    ret = ec_device_init(&master->backup_device, master);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   186
    if (ret < 0)
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   187
        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
   188
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
   189
    // 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
   190
    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
   191
    snprintf(master->fsm_datagram.name, EC_DATAGRAM_NAME_SIZE, "master-fsm");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   192
    ret = ec_datagram_prealloc(&master->fsm_datagram, EC_MAX_DATA_SIZE);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   193
    if (ret < 0) {
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   194
        ec_datagram_clear(&master->fsm_datagram);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   195
        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
   196
        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
   197
    }
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
   198
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   199
    // 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
   200
    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
   201
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   202
    // init reference sync datagram
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   203
    ec_datagram_init(&master->ref_sync_datagram);
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   204
    snprintf(master->ref_sync_datagram.name, EC_DATAGRAM_NAME_SIZE, "refsync");
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   205
    ret = ec_datagram_apwr(&master->ref_sync_datagram, 0, 0x0910, 8);
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   206
    if (ret < 0) {
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   207
        ec_datagram_clear(&master->ref_sync_datagram);
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   208
        EC_ERR("Failed to allocate reference synchronisation datagram.\n");
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   209
        goto out_clear_fsm;
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   210
    }
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   211
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   212
    // init sync datagram
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   213
    ec_datagram_init(&master->sync_datagram);
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   214
    snprintf(master->sync_datagram.name, EC_DATAGRAM_NAME_SIZE, "sync");
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   215
    ret = ec_datagram_armw(&master->sync_datagram, 0 /* FIXME */, 0x0910, 4);
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   216
    if (ret < 0) {
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   217
        ec_datagram_clear(&master->sync_datagram);
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   218
        EC_ERR("Failed to allocate synchronisation datagram.\n");
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   219
        goto out_clear_ref_sync;
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   220
    }
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   221
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   222
    // init character device
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   223
    ret = ec_cdev_init(&master->cdev, master, device_number);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   224
    if (ret)
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   225
        goto out_clear_sync;
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   226
    
1369
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   227
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   228
    master->class_device = device_create(class, NULL,
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   229
            MKDEV(MAJOR(device_number), master->index), NULL,
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   230
            "EtherCAT%u", master->index);
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   231
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
1250
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   232
    master->class_device = device_create(class, NULL,
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   233
            MKDEV(MAJOR(device_number), master->index),
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   234
            "EtherCAT%u", master->index);
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   235
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15)
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   236
    master->class_device = class_device_create(class, NULL,
1369
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   237
            MKDEV(MAJOR(device_number), master->index), NULL,
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   238
            "EtherCAT%u", master->index);
1015
24efac66a647 Added support for different versions of class_device_create().
Florian Pose <fp@igh-essen.com>
parents: 1013
diff changeset
   239
#else
1250
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   240
    master->class_device = class_device_create(class,
1369
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   241
            MKDEV(MAJOR(device_number), master->index), NULL,
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   242
            "EtherCAT%u", master->index);
1015
24efac66a647 Added support for different versions of class_device_create().
Florian Pose <fp@igh-essen.com>
parents: 1013
diff changeset
   243
#endif
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   244
    if (IS_ERR(master->class_device)) {
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   245
        EC_ERR("Failed to create class device!\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   246
        ret = PTR_ERR(master->class_device);
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   247
        goto out_clear_cdev;
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   248
    }
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   249
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   250
    return 0;
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   251
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   252
out_clear_cdev:
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   253
    ec_cdev_clear(&master->cdev);
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   254
out_clear_sync:
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   255
    ec_datagram_clear(&master->sync_datagram);
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   256
out_clear_ref_sync:
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   257
    ec_datagram_clear(&master->ref_sync_datagram);
659
d7c5a958bad0 Removed unecessary clearing of EoE handlers in master init function;
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   258
out_clear_fsm:
d7c5a958bad0 Removed unecessary clearing of EoE handlers in master init function;
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   259
    ec_fsm_master_clear(&master->fsm);
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   260
    ec_datagram_clear(&master->fsm_datagram);
659
d7c5a958bad0 Removed unecessary clearing of EoE handlers in master init function;
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   261
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
   262
    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
   263
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
   264
    ec_device_clear(&master->main_device);
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   265
out_return:
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   266
    return ret;
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 35
diff changeset
   269
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   271
/** Destructor.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   272
*/
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   273
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
   274
        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
   275
        )
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   276
{
1250
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   277
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   278
    device_unregister(master->class_device);
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   279
#else
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   280
    class_device_unregister(master->class_device);
1250
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   281
#endif
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   282
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   283
    ec_cdev_clear(&master->cdev);
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   284
    
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   285
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   286
    ec_master_clear_eoe_handlers(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   287
#endif
994
e29edcced328 Clear domains before slave configs, because domain references the FMMU
Florian Pose <fp@igh-essen.com>
parents: 993
diff changeset
   288
    ec_master_clear_domains(master);
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   289
    ec_master_clear_slave_configs(master);
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   290
    ec_master_clear_slaves(master);
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   291
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   292
    ec_datagram_clear(&master->sync_datagram);
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   293
    ec_datagram_clear(&master->ref_sync_datagram);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 527
diff changeset
   294
    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
   295
    ec_datagram_clear(&master->fsm_datagram);
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   296
    ec_device_clear(&master->backup_device);
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   297
    ec_device_clear(&master->main_device);
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   298
}
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   299
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   300
/*****************************************************************************/
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   301
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   302
#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
   303
/** Clear and free all EoE handlers.
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   304
 */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   305
void ec_master_clear_eoe_handlers(
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   306
        ec_master_t *master /**< EtherCAT master */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   307
        )
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   308
{
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   309
    ec_eoe_t *eoe, *next;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   310
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   311
    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
   312
        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
   313
        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
   314
        kfree(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   315
    }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   316
}
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   317
#endif
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   318
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   319
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   320
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   321
/** Clear all slave configurations.
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   322
 */
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   323
void ec_master_clear_slave_configs(ec_master_t *master)
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   324
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   325
    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
   326
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   327
    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
   328
        list_del(&sc->list);
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   329
        ec_slave_config_clear(sc);
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   330
        kfree(sc);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   331
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   332
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   333
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   334
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   335
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   336
/** Clear all slaves.
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   337
 */
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   338
void ec_master_clear_slaves(ec_master_t *master)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents: 236
diff changeset
   339
{
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   340
    ec_slave_t *slave;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   341
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   342
    for (slave = master->slaves;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   343
            slave < master->slaves + master->slave_count;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   344
            slave++) {
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   345
        ec_slave_clear(slave);
1004
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   346
    }
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   347
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   348
    if (master->slaves) {
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   349
        kfree(master->slaves);
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   350
        master->slaves = NULL;
1004
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   351
    }
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   352
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   353
    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
   354
}
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   355
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   356
/*****************************************************************************/
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   357
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   358
/** Clear all domains.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   359
 */
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   360
void ec_master_clear_domains(ec_master_t *master)
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
   361
{
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   362
    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
   363
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   364
    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
   365
        list_del(&domain->list);
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   366
        ec_domain_clear(domain);
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   367
        kfree(domain);
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
   368
    }
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   369
}
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   370
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   371
/*****************************************************************************/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   372
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   373
/** Internal locking callback.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   374
 */
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   375
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
   376
{
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   377
    spin_lock(&((ec_master_t *) master)->internal_lock);
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   378
    return 0;
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   379
}
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   380
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   381
/*****************************************************************************/
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   382
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   383
/** Internal unlocking callback.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   384
 */
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   385
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
   386
{
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   387
    spin_unlock(&((ec_master_t *) master)->internal_lock);
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   388
}
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   389
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   390
/*****************************************************************************/
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   391
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   392
/** Starts the master thread.
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   393
 *
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   394
 * \retval  0 Success.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   395
 * \retval <0 Error code.
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   396
 */
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   397
int ec_master_thread_start(
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   398
        ec_master_t *master, /**< EtherCAT master */
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   399
        int (*thread_func)(void *), /**< thread function to start */
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   400
        const char *name /**< Thread name. */
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   401
        )
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   402
{
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   403
    EC_INFO("Starting %s thread.\n", name);
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   404
    master->thread = kthread_run(thread_func, master, name);
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   405
    if (IS_ERR(master->thread)) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   406
        int err = (int) PTR_ERR(master->thread);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   407
        EC_ERR("Failed to start master thread (error %i)!\n", err);
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   408
        master->thread = NULL;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   409
        return err;
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   410
    }
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   411
    
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   412
    return 0;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   413
}
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   414
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
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   417
/** Stops the master thread.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   418
 */
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   419
void ec_master_thread_stop(
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   420
        ec_master_t *master /**< EtherCAT master */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   421
        )
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   422
{
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   423
    unsigned long sleep_jiffies;
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   424
    
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   425
    if (!master->thread) {
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   426
        EC_WARN("ec_master_thread_stop(): Already finished!\n");
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   427
        return;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   428
    }
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   429
1006
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   430
    if (master->debug_level)
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   431
        EC_DBG("Stopping master thread.\n");
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   432
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   433
    kthread_stop(master->thread);
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   434
    master->thread = NULL;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   435
    EC_INFO("Master thread exited.\n");
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   436
1198
be606e9caba4 Fixed race concerning thread signaling when master thread had no
Florian Pose <fp@igh-essen.com>
parents: 1197
diff changeset
   437
    if (master->fsm_datagram.state != EC_DATAGRAM_SENT)
be606e9caba4 Fixed race concerning thread signaling when master thread had no
Florian Pose <fp@igh-essen.com>
parents: 1197
diff changeset
   438
        return;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   439
    
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   440
    // wait for FSM datagram
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   441
    sleep_jiffies = max(HZ / 100, 1); // 10 ms, at least 1 jiffy
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   442
    schedule_timeout(sleep_jiffies);
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   443
}
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   444
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   445
/*****************************************************************************/
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   446
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   447
/** Transition function from ORPHANED to IDLE phase.
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   448
 */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   449
int ec_master_enter_idle_phase(
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   450
        ec_master_t *master /**< EtherCAT master */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   451
        )
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   452
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   453
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   454
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   455
    if (master->debug_level)
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   456
        EC_DBG("ORPHANED -> IDLE.\n");
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   457
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   458
    master->request_cb = ec_master_request_cb;
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   459
    master->release_cb = ec_master_release_cb;
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   460
    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
   461
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   462
    master->phase = EC_IDLE;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   463
    ret = ec_master_thread_start(master, ec_master_idle_thread,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   464
            "EtherCAT-IDLE");
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   465
    if (ret)
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   466
        master->phase = EC_ORPHANED;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   467
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   468
    return ret;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   469
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   470
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   471
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   472
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   473
/** Transition function from IDLE to ORPHANED phase.
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   474
 */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   475
void ec_master_leave_idle_phase(ec_master_t *master /**< EtherCAT master */)
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   476
{
1006
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   477
    if (master->debug_level)
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   478
        EC_DBG("IDLE -> ORPHANED.\n");
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   479
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   480
    master->phase = EC_ORPHANED;
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   481
    
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   482
#ifdef EC_EOE
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   483
    ec_master_eoe_stop(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   484
#endif
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   485
    ec_master_thread_stop(master);
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   486
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   487
    down(&master->master_sem);
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   488
    ec_master_clear_slaves(master);
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   489
    up(&master->master_sem);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   490
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   491
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   492
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   493
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   494
/** Transition function from IDLE to OPERATION phase.
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   495
 */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   496
int ec_master_enter_operation_phase(ec_master_t *master /**< EtherCAT master */)
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   497
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   498
    int ret = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   499
    ec_slave_t *slave;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   500
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   501
    ec_eoe_t *eoe;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   502
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   503
1006
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   504
    if (master->debug_level)
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   505
        EC_DBG("IDLE -> OPERATION.\n");
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   506
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   507
    down(&master->config_sem);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   508
    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
   509
    if (master->config_busy) {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   510
        up(&master->config_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   511
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   512
        // wait for slave configuration to complete
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   513
        ret = wait_event_interruptible(master->config_queue,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   514
                    !master->config_busy);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   515
        if (ret) {
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   516
            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
   517
            goto out_allow;
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   518
        }
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   519
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   520
        if (master->debug_level)
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   521
            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
   522
    } else {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   523
        up(&master->config_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   524
    }
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   525
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   526
    down(&master->scan_sem);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   527
    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
   528
    if (!master->scan_busy) {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   529
        up(&master->scan_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   530
    } else {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   531
        up(&master->scan_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   532
794
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   533
        // wait for slave scan to complete
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   534
        ret = wait_event_interruptible(master->scan_queue, !master->scan_busy);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   535
        if (ret) {
794
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   536
            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
   537
            goto out_allow;
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   538
        }
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   539
        
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   540
        if (master->debug_level)
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   541
            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
   542
    }
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   543
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   544
    // set states for all slaves
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   545
    for (slave = master->slaves;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   546
            slave < master->slaves + master->slave_count;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   547
            slave++) {
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 640
diff changeset
   548
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   549
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   550
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   551
    // ... but set EoE slaves to OP
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   552
    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
   553
        if (ec_eoe_is_open(eoe))
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   554
            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
   555
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   556
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   557
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   558
    master->phase = EC_OPERATION;
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   559
    master->ext_request_cb = NULL;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   560
    master->ext_release_cb = NULL;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   561
    master->ext_cb_data = NULL;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   562
    return ret;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   563
    
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   564
out_allow:
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   565
    master->allow_scan = 1;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   566
    master->allow_config = 1;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   567
    return ret;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   568
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   569
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   570
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   571
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   572
/** Transition function from OPERATION to IDLE phase.
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   573
 */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   574
void ec_master_leave_operation_phase(ec_master_t *master
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   575
                                    /**< EtherCAT master */)
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   576
{
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   577
    ec_slave_t *slave;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   578
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   579
    ec_eoe_t *eoe;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   580
#endif
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   581
1006
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   582
    if (master->debug_level)
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   583
        EC_DBG("OPERATION -> IDLE.\n");
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   584
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   585
    master->phase = EC_IDLE;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   586
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   587
#ifdef EC_EOE
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   588
    ec_master_eoe_stop(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   589
#endif
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   590
    ec_master_thread_stop(master);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   591
    
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   592
    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
   593
    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
   594
    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
   595
    
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   596
    down(&master->master_sem);
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   597
    ec_master_clear_domains(master);
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   598
    ec_master_clear_slave_configs(master);
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   599
    up(&master->master_sem);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   600
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   601
    for (slave = master->slaves;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   602
            slave < master->slaves + master->slave_count;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   603
            slave++) {
1178
ca00393c8ca6 Fixed reconfiguration: Force config when application detaches.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   604
ca00393c8ca6 Fixed reconfiguration: Force config when application detaches.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   605
        // set states for all slaves
449
3caf8ff4d8a2 Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   606
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
1178
ca00393c8ca6 Fixed reconfiguration: Force config when application detaches.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   607
ca00393c8ca6 Fixed reconfiguration: Force config when application detaches.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   608
        // mark for reconfiguration, because the master could have no
ca00393c8ca6 Fixed reconfiguration: Force config when application detaches.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   609
        // possibility for a reconfiguration between two sequential operation
ca00393c8ca6 Fixed reconfiguration: Force config when application detaches.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   610
        // phases.
ca00393c8ca6 Fixed reconfiguration: Force config when application detaches.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   611
        slave->force_config = 1;
ca00393c8ca6 Fixed reconfiguration: Force config when application detaches.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   612
    }
ca00393c8ca6 Fixed reconfiguration: Force config when application detaches.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   613
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   614
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   615
    // ... but leave EoE slaves in OP
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   616
    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
   617
        if (ec_eoe_is_open(eoe))
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   618
            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
   619
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   620
#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
   621
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   622
    if (ec_master_thread_start(master, ec_master_idle_thread,
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   623
                "EtherCAT-IDLE"))
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   624
        EC_WARN("Failed to restart master thread!\n");
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   625
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   626
    ec_master_eoe_start(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   627
#endif
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   628
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   629
    master->allow_scan = 1;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   630
    master->allow_config = 1;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   631
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   632
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   633
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   634
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   635
/** Places a datagram in the datagram queue.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   636
 */
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   637
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
   638
                              ec_datagram_t *datagram /**< datagram */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   639
                              )
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   640
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   641
    ec_datagram_t *queued_datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   642
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   643
    // check, if the datagram is already queued
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   644
    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
   645
        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
   646
            datagram->skip_count++;
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   647
            if (master->debug_level)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   648
                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
   649
            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
   650
            return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   651
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   652
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   653
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   654
    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
   655
    datagram->state = EC_DATAGRAM_QUEUED;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   656
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   657
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   658
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   659
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   660
/** Sends the datagrams in the queue.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   661
 *
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   662
 * \return 0 in case of success, else < 0
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   663
 */
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   664
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
   665
{
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   666
    ec_datagram_t *datagram, *next;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   667
    size_t datagram_size;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   668
    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
   669
    void *follows_word;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   670
#ifdef EC_HAVE_CYCLES
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   671
    cycles_t cycles_start, cycles_sent, cycles_end;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   672
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   673
    unsigned long jiffies_sent;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   674
    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
   675
    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
   676
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   677
#ifdef EC_HAVE_CYCLES
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   678
    cycles_start = get_cycles();
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   679
#endif
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   680
    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
   681
    INIT_LIST_HEAD(&sent_datagrams);
208
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
   682
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   683
    if (unlikely(master->debug_level > 1))
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   684
        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
   685
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   686
    do {
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   687
        // 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
   688
        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
   689
        cur_data = frame_data + EC_FRAME_HEADER_SIZE;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   690
        follows_word = NULL;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   691
        more_datagrams_waiting = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   692
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   693
        // fill current frame with datagrams
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   694
        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
   695
            if (datagram->state != EC_DATAGRAM_QUEUED) continue;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   696
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   697
            // does the current datagram fit in the frame?
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   698
            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
   699
                + EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   700
            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
   701
                more_datagrams_waiting = 1;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   702
                break;
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
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   705
            list_add_tail(&datagram->sent, &sent_datagrams);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   706
            datagram->index = master->datagram_index++;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   707
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   708
            if (unlikely(master->debug_level > 1))
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   709
                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
   710
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   711
            // set "datagram following" flag in previous frame
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   712
            if (follows_word)
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   713
                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
   714
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   715
            // EtherCAT datagram header
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   716
            EC_WRITE_U8 (cur_data,     datagram->type);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   717
            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
   718
            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
   719
            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
   720
            EC_WRITE_U16(cur_data + 8, 0x0000);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   721
            follows_word = cur_data + 6;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   722
            cur_data += EC_DATAGRAM_HEADER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   723
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   724
            // EtherCAT datagram data
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   725
            memcpy(cur_data, datagram->data, datagram->data_size);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   726
            cur_data += datagram->data_size;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   727
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   728
            // EtherCAT datagram footer
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   729
            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
   730
            cur_data += EC_DATAGRAM_FOOTER_SIZE;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   731
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   732
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   733
        if (list_empty(&sent_datagrams)) {
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   734
            if (unlikely(master->debug_level > 1))
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   735
                EC_DBG("nothing to send.\n");
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   736
            break;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   737
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   738
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   739
        // EtherCAT frame header
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   740
        EC_WRITE_U16(frame_data, ((cur_data - frame_data
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   741
                                   - EC_FRAME_HEADER_SIZE) & 0x7FF) | 0x1000);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   742
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   743
        // pad frame
211
c684b6b7adaf Using kernel Ethernet constants.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
   744
        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
   745
            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
   746
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   747
        if (unlikely(master->debug_level > 1))
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 958
diff changeset
   748
            EC_DBG("frame size: %u\n", cur_data - frame_data);
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   749
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   750
        // 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
   751
        ec_device_send(&master->main_device, cur_data - frame_data);
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   752
#ifdef EC_HAVE_CYCLES
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   753
        cycles_sent = get_cycles();
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   754
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   755
        jiffies_sent = jiffies;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   756
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   757
        // 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
   758
        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
   759
            datagram->state = EC_DATAGRAM_SENT;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   760
#ifdef EC_HAVE_CYCLES
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   761
            datagram->cycles_sent = cycles_sent;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   762
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   763
            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
   764
            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
   765
        }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   766
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   767
        frame_count++;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   768
    }
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   769
    while (more_datagrams_waiting);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   770
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   771
#ifdef EC_HAVE_CYCLES
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
   772
    if (unlikely(master->debug_level > 1)) {
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   773
        cycles_end = get_cycles();
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 958
diff changeset
   774
        EC_DBG("ec_master_send_datagrams sent %u frames in %uus.\n",
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   775
               frame_count,
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   776
               (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
   777
    }
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   778
#endif
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   779
}
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   780
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   781
/*****************************************************************************/
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   782
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   783
/** Processes a received frame.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   784
 *
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   785
 * This function is called by the network driver for every received frame.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   786
 * 
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   787
 * \return 0 in case of success, else < 0
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   788
 */
331
17f58fe99511 Renamed ec_master_receive() to ec_master_receive_datagrams().
Florian Pose <fp@igh-essen.com>
parents: 330
diff changeset
   789
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
   790
                                 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
   791
                                 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
   792
                                 )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   793
{
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   794
    size_t frame_size, data_size;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   795
    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
   796
    unsigned int cmd_follows, matched;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   797
    const uint8_t *cur_data;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   798
    ec_datagram_t *datagram;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   799
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   800
    if (unlikely(size < EC_FRAME_HEADER_SIZE)) {
1303
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   801
        if (master->debug_level) {
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   802
            EC_DBG("Corrupted frame received (size %u < %u byte):\n",
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   803
                    size, EC_FRAME_HEADER_SIZE);
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   804
            ec_print_data(frame_data, size);
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   805
        }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   806
        master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   807
        ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   808
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   809
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   810
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   811
    cur_data = frame_data;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   812
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   813
    // 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
   814
    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
   815
    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
   816
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   817
    if (unlikely(frame_size > size)) {
1303
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   818
        if (master->debug_level) {
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   819
            EC_DBG("Corrupted frame received (invalid frame size %u for "
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   820
                    "received size %u):\n", frame_size, size);
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   821
            ec_print_data(frame_data, size);
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   822
        }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   823
        master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   824
        ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   825
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   826
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   827
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   828
    cmd_follows = 1;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   829
    while (cmd_follows) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   830
        // process datagram header
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   831
        datagram_type  = EC_READ_U8 (cur_data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   832
        datagram_index = EC_READ_U8 (cur_data + 1);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   833
        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
   834
        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
   835
        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
   836
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   837
        if (unlikely(cur_data - frame_data
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   838
                     + data_size + EC_DATAGRAM_FOOTER_SIZE > size)) {
1303
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   839
            if (master->debug_level) {
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   840
                EC_DBG("Corrupted frame received (invalid data size %u):\n",
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   841
                        data_size);
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   842
                ec_print_data(frame_data, size);
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
   843
            }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   844
            master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   845
            ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   846
            return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   847
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   848
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   849
        // 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
   850
        matched = 0;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   851
        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
   852
            if (datagram->index == datagram_index
5e231f6a3d2e Re-ordered criteria for datagram matching.
Florian Pose <fp@igh-essen.com>
parents: 688
diff changeset
   853
                && datagram->state == EC_DATAGRAM_SENT
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   854
                && datagram->type == datagram_type
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   855
                && 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
   856
                matched = 1;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   857
                break;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   858
            }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   859
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   860
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   861
        // 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
   862
        if (!matched) {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   863
            master->stats.unmatched++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   864
            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
   865
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
   866
            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
   867
                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
   868
                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
   869
                        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
   870
                        + 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
   871
#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
   872
                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
   873
#endif
684
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
   874
            }
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
   875
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   876
            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
   877
            continue;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   878
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   879
345
beb0a77d73c0 Improved datagram reception in sync_io and frame dequeuing.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   880
        // copy received data into the datagram memory
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   881
        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
   882
        cur_data += data_size;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   883
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   884
        // set the datagram's working counter
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   885
        datagram->working_counter = EC_READ_U16(cur_data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   886
        cur_data += EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   887
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   888
        // 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
   889
        datagram->state = EC_DATAGRAM_RECEIVED;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   890
#ifdef EC_HAVE_CYCLES
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   891
        datagram->cycles_received = master->main_device.cycles_poll;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   892
#endif
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   893
        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
   894
        list_del_init(&datagram->queue);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   895
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   896
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   897
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   898
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   899
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   900
/** Output master statistics.
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   901
 *
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   902
 * This function outputs statistical data on demand, but not more often than
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   903
 * necessary. The output happens at most once a second.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   904
 */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   905
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
   906
{
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   907
    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
   908
        master->stats.output_jiffies = jiffies;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
   909
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   910
        if (master->stats.timeouts) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 958
diff changeset
   911
            EC_WARN("%u datagram%s TIMED OUT!\n", master->stats.timeouts,
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   912
                    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
   913
            master->stats.timeouts = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   914
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   915
        if (master->stats.corrupted) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 958
diff changeset
   916
            EC_WARN("%u frame%s CORRUPTED!\n", master->stats.corrupted,
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   917
                    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
   918
            master->stats.corrupted = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   919
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   920
        if (master->stats.unmatched) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 958
diff changeset
   921
            EC_WARN("%u datagram%s UNMATCHED!\n", master->stats.unmatched,
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
   922
                    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
   923
            master->stats.unmatched = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   924
        }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   925
    }
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   926
}
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   927
68
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   928
/*****************************************************************************/
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   929
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   930
/** Master kernel thread function for IDLE phase.
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   931
 */
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   932
static int ec_master_idle_thread(void *priv_data)
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   933
{
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   934
    ec_master_t *master = (ec_master_t *) priv_data;
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   935
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   936
    if (master->debug_level)
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   937
        EC_DBG("Idle thread running.\n");
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   938
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   939
    while (!kthread_should_stop()) {
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 715
diff changeset
   940
        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
   941
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   942
        // receive
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   943
        spin_lock_bh(&master->internal_lock);
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   944
        ecrt_master_receive(master);
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   945
        spin_unlock_bh(&master->internal_lock);
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   946
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   947
        if (master->fsm_datagram.state == EC_DATAGRAM_SENT)
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   948
            goto schedule;
651
8c11399cc911 Fixed skipped datagrams when not in FSM idle phase.
Florian Pose <fp@igh-essen.com>
parents: 650
diff changeset
   949
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   950
        // execute master state machine
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   951
        if (down_interruptible(&master->master_sem))
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   952
            break;
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   953
        ec_fsm_master_exec(&master->fsm);
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   954
        up(&master->master_sem);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   955
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   956
        // queue and send
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   957
        spin_lock_bh(&master->internal_lock);
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   958
        ec_master_queue_datagram(master, &master->fsm_datagram);
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   959
        ecrt_master_send(master);
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   960
        spin_unlock_bh(&master->internal_lock);
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   961
        
651
8c11399cc911 Fixed skipped datagrams when not in FSM idle phase.
Florian Pose <fp@igh-essen.com>
parents: 650
diff changeset
   962
schedule:
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   963
        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
   964
            set_current_state(TASK_INTERRUPTIBLE);
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   965
            schedule_timeout(1);
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   966
        }
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   967
        else {
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   968
            schedule();
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
   969
        }
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   970
    }
518
b6a1426ba724 Fixed race: Stop EoE processing when entering or leaving operation mode.
Florian Pose <fp@igh-essen.com>
parents: 517
diff changeset
   971
    
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   972
    if (master->debug_level)
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   973
        EC_DBG("Master IDLE thread exiting...\n");
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   974
    return 0;
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   975
}
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
   976
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   977
/*****************************************************************************/
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   978
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   979
/** Master kernel thread function for IDLE phase.
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   980
 */
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   981
static int ec_master_operation_thread(void *priv_data)
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   982
{
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   983
    ec_master_t *master = (ec_master_t *) priv_data;
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   984
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   985
    if (master->debug_level)
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   986
        EC_DBG("Operation thread running.\n");
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   987
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   988
    while (!kthread_should_stop()) {
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 715
diff changeset
   989
        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
   990
        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
   991
                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
   992
                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
   993
            goto schedule;
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   994
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   995
        // output statistics
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   996
        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
   997
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   998
        // execute master state machine
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   999
        if (down_interruptible(&master->master_sem))
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1000
            break;
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1001
        ec_fsm_master_exec(&master->fsm);
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1002
        up(&master->master_sem);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1003
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1004
        // inject datagram
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1005
        master->injection_seq_fsm++;
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1006
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1007
schedule:
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
  1008
        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
  1009
            set_current_state(TASK_INTERRUPTIBLE);
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
  1010
            schedule_timeout(1);
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
  1011
        }
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
  1012
        else {
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
  1013
            schedule();
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 648
diff changeset
  1014
        }
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1015
    }
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1016
    
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1017
    if (master->debug_level)
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1018
        EC_DBG("Master OP thread exiting...\n");
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1019
    return 0;
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1020
}
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1021
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1022
/*****************************************************************************/
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1023
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1024
#ifdef EC_EOE
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1025
/** Starts Ethernet over EtherCAT processing on demand.
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1026
 */
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1027
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
  1028
{
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1029
    if (master->eoe_running) {
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1030
        EC_WARN("EoE already running!\n");
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1031
        return;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1032
    }
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1033
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1034
    if (list_empty(&master->eoe_handlers))
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1035
        return;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1036
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1037
    if (!master->request_cb || !master->release_cb) {
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1038
        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
  1039
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1040
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1041
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1042
    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
  1043
    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
  1044
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1045
    // start EoE processing
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1046
    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
  1047
    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
  1048
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1049
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1050
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1051
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1052
/** Stops the Ethernet over EtherCAT processing.
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1053
 */
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1054
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
  1055
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1056
    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
  1057
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1058
    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
  1059
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1060
    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
  1061
    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
  1062
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1063
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1064
/*****************************************************************************/
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1065
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1066
/** Does the Ethernet over EtherCAT processing.
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1067
 */
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1068
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
  1069
{
60a10d85c20b Prepared EoE processing with workqueue.
Florian Pose <fp@igh-essen.com>
parents: 204
diff changeset
  1070
    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
  1071
    ec_eoe_t *eoe;
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1072
    unsigned int none_open = 1;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1073
    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
  1074
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1075
    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
  1076
        if (ec_eoe_is_open(eoe)) {
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1077
            none_open = 0;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1078
            break;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1079
        }
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1080
    }
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1081
    if (none_open)
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1082
        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
  1083
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1084
    // receive datagrams
1041
42c9ac58d9ce Removed state machine cycle time measuring.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
  1085
    if (master->request_cb(master->cb_data))
42c9ac58d9ce Removed state machine cycle time measuring.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
  1086
        goto queue_timer;
42c9ac58d9ce Removed state machine cycle time measuring.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
  1087
    
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1088
    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
  1089
    master->release_cb(master->cb_data);
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1090
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1091
    // 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
  1092
    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
  1093
        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
  1094
    }
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1095
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
  1096
    // send datagrams
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1097
    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
  1098
        goto queue_timer;
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1099
    }
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 720
diff changeset
  1100
    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
  1101
        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
  1102
    }
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1103
    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
  1104
    master->release_cb(master->cb_data);
334
2be97e069602 Master information, timing.
Florian Pose <fp@igh-essen.com>
parents: 332
diff changeset
  1105
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1106
 queue_timer:
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1107
    restart_jiffies = HZ / EC_EOE_FREQUENCY;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1108
    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
  1109
    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
  1110
    add_timer(&master->eoe_timer);
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1111
}
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1112
#endif
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1113
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1114
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1115
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1116
/** 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
  1117
 */
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1118
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
  1119
        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
  1120
        )
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1121
{
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1122
    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
  1123
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1124
    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
  1125
        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
  1126
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1127
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1128
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1129
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1130
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1131
/** 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
  1132
 */
1028
afdd4bdbb7ec Removed configs_attached flag; changed return value of
Florian Pose <fp@igh-essen.com>
parents: 1024
diff changeset
  1133
void ec_master_attach_slave_configs(
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1134
        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
  1135
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1136
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1137
    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
  1138
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1139
    list_for_each_entry(sc, &master->configs, list) {
1028
afdd4bdbb7ec Removed configs_attached flag; changed return value of
Florian Pose <fp@igh-essen.com>
parents: 1024
diff changeset
  1140
        ec_slave_config_attach(sc);
afdd4bdbb7ec Removed configs_attached flag; changed return value of
Florian Pose <fp@igh-essen.com>
parents: 1024
diff changeset
  1141
    }
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1142
}
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1143
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1144
/*****************************************************************************/
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1145
1077
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1146
/** Common implementation for ec_master_find_slave()
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1147
 * and ec_master_find_slave_const().
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1148
 */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1149
#define EC_FIND_SLAVE \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1150
    do { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1151
        if (alias) { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1152
            for (; slave < master->slaves + master->slave_count; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1153
                    slave++) { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1154
                if (slave->sii.alias == alias) \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1155
                break; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1156
            } \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1157
            if (slave == master->slaves + master->slave_count) \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1158
            return NULL; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1159
        } \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1160
        \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1161
        slave += position; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1162
        if (slave < master->slaves + master->slave_count) { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1163
            return slave; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1164
        } else { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1165
            return NULL; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1166
        } \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1167
    } while (0)
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1168
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1169
/** 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
  1170
 */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1171
ec_slave_t *ec_master_find_slave(
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1172
        ec_master_t *master, /**< EtherCAT master. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1173
        uint16_t alias, /**< Slave alias. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1174
        uint16_t position /**< Slave position. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1175
        )
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1176
{
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
  1177
    ec_slave_t *slave = master->slaves;
1077
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1178
    EC_FIND_SLAVE;
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1179
}
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1180
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1181
/** Finds a slave in the bus, given the alias and position.
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1182
 *
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1183
 * Const version.
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1184
 */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1185
const ec_slave_t *ec_master_find_slave_const(
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1186
        const ec_master_t *master, /**< EtherCAT master. */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1187
        uint16_t alias, /**< Slave alias. */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1188
        uint16_t position /**< Slave position. */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1189
        )
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1190
{
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1191
    const ec_slave_t *slave = master->slaves;
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1192
    EC_FIND_SLAVE;
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1193
}
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1194
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1195
/*****************************************************************************/
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1196
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1197
/** Get the number of slave configurations provided by the application.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1198
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1199
 * \return Number of configurations.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1200
 */
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1201
unsigned int ec_master_config_count(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1202
		const ec_master_t *master /**< EtherCAT master. */
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1203
		)
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1204
{
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1205
	const ec_slave_config_t *sc;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1206
	unsigned int count = 0;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1207
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1208
	list_for_each_entry(sc, &master->configs, list) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1209
		count++;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1210
	}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1211
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1212
	return count;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1213
}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1214
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1215
/*****************************************************************************/
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1216
1252
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1217
/** Common implementation for ec_master_get_config()
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1218
 * and ec_master_get_config_const().
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1219
 */
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1220
#define EC_FIND_CONFIG \
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1221
    do { \
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1222
		list_for_each_entry(sc, &master->configs, list) { \
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1223
			if (pos--) \
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1224
				continue; \
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1225
			return sc; \
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1226
		} \
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1227
		return NULL; \
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1228
    } while (0)
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1229
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1230
/** Get a slave configuration via its position in the list.
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1231
 *
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1232
 * \return Slave configuration or \a NULL.
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1233
 */
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1234
ec_slave_config_t *ec_master_get_config(
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1235
		const ec_master_t *master, /**< EtherCAT master. */
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1236
		unsigned int pos /**< List position. */
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1237
		)
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1238
{
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1239
	ec_slave_config_t *sc;
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1240
	EC_FIND_CONFIG;
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1241
}
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1242
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1243
/** Get a slave configuration via its position in the list.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1244
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1245
 * Const version.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1246
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1247
 * \return Slave configuration or \a NULL.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1248
 */
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1249
const ec_slave_config_t *ec_master_get_config_const(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1250
		const ec_master_t *master, /**< EtherCAT master. */
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1251
		unsigned int pos /**< List position. */
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1252
		)
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1253
{
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1254
	const ec_slave_config_t *sc;
1252
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1255
	EC_FIND_CONFIG;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1256
}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1257
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1258
/*****************************************************************************/
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1259
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1260
/** Get the number of domains.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1261
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1262
 * \return Number of domains.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1263
 */
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1264
unsigned int ec_master_domain_count(
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1265
		const ec_master_t *master /**< EtherCAT master. */
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1266
		)
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1267
{
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1268
	const ec_domain_t *domain;
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1269
	unsigned int count = 0;
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1270
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1271
	list_for_each_entry(domain, &master->domains, list) {
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1272
		count++;
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1273
	}
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1274
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1275
	return count;
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1276
}
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1277
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1278
/*****************************************************************************/
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1279
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1280
/** Common implementation for ec_master_find_domain() and
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1281
 * ec_master_find_domain_const().
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1282
 */
1078
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1283
#define EC_FIND_DOMAIN \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1284
    do { \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1285
        list_for_each_entry(domain, &master->domains, list) { \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1286
            if (index--) \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1287
                continue; \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1288
            return domain; \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1289
        } \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1290
        \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1291
        return NULL; \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1292
    } while (0)
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1293
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1294
/** Get a domain via its position in the list.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1295
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1296
 * \return Domain pointer, or \a NULL if not found.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1297
 */
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1298
ec_domain_t *ec_master_find_domain(
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1299
		ec_master_t *master, /**< EtherCAT master. */
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1300
		unsigned int index /**< Domain index. */
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1301
		)
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1302
{
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1303
	ec_domain_t *domain;
1078
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1304
    EC_FIND_DOMAIN;
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1305
}
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1306
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1307
/** Get a domain via its position in the list.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1308
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1309
 * Const version.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1310
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1311
 * \return Domain pointer, or \a NULL if not found.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1312
 */
1078
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1313
const ec_domain_t *ec_master_find_domain_const(
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1314
		const ec_master_t *master, /**< EtherCAT master. */
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1315
		unsigned int index /**< Domain index. */
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1316
		)
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1317
{
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1318
	const ec_domain_t *domain;
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1319
    EC_FIND_DOMAIN;
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1320
}
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1321
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1322
/*****************************************************************************/
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1323
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1324
/** Set the debug level.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1325
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1326
 * \retval       0 Success.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1327
 * \retval -EINVAL Invalid debug level.
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1328
 */
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1329
int ec_master_debug_level(
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1330
        ec_master_t *master, /**< EtherCAT master. */
1399
f79d4bb5b23a Added debug_level module parameter. debug_level is now unsigned int.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
  1331
        unsigned int level /**< Debug level. May be 0, 1 or 2. */
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1332
        )
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1333
{
1399
f79d4bb5b23a Added debug_level module parameter. debug_level is now unsigned int.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
  1334
    if (level > 2) {
f79d4bb5b23a Added debug_level module parameter. debug_level is now unsigned int.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
  1335
        EC_ERR("Invalid debug level %u!\n", level);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1336
        return -EINVAL;
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1337
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1338
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1339
    if (level != master->debug_level) {
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1340
        master->debug_level = level;
1399
f79d4bb5b23a Added debug_level module parameter. debug_level is now unsigned int.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
  1341
        EC_INFO("Master debug level set to %u.\n", master->debug_level);
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1342
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1343
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1344
    return 0;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1345
}
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1346
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
  1347
/******************************************************************************
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  1348
 *  Application interface
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
  1349
 *****************************************************************************/
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
1332
d62633fea8ed merge -c1610 branches/stable-1.4: Added missing doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 1329
diff changeset
  1351
/** Same as ecrt_master_create_domain(), but with ERR_PTR() return value.
d62633fea8ed merge -c1610 branches/stable-1.4: Added missing doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 1329
diff changeset
  1352
 */
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1353
ec_domain_t *ecrt_master_create_domain_err(
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1354
        ec_master_t *master /**< master */
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1355
        )
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
  1356
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1357
    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
  1358
    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
  1359
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1360
    if (master->debug_level)
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1361
        EC_DBG("ecrt_master_create_domain(master = 0x%x)\n", (u32) master);
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1362
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
  1363
    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
  1364
        EC_ERR("Error allocating domain memory!\n");
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1365
        return ERR_PTR(-ENOMEM);
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
  1366
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1367
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1368
    down(&master->master_sem);
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1369
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  1370
    if (list_empty(&master->domains)) {
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  1371
        index = 0;
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  1372
    } else {
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
  1373
        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
  1374
        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
  1375
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1376
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  1377
    ec_domain_init(domain, master, index);
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
  1378
    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
  1379
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1380
    up(&master->master_sem);
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1381
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1382
    if (master->debug_level)
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1383
        EC_DBG("Created domain %u.\n", domain->index);
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1384
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
  1385
    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
  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
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
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1390
ec_domain_t *ecrt_master_create_domain(
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1391
        ec_master_t *master /**< master */
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1392
        )
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1393
{
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1394
    ec_domain_t *d = ecrt_master_create_domain_err(master);
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1395
    return IS_ERR(d) ? NULL : d;
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1396
}
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1397
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1398
/*****************************************************************************/
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1399
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1400
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
  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
    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
  1403
    ec_domain_t *domain;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1404
    int ret;
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
  1405
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1406
    if (master->debug_level)
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1407
        EC_DBG("ecrt_master_activate(master = 0x%x)\n", (u32) master);
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1408
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1409
    down(&master->master_sem);
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1410
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1411
    // 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
  1412
    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
  1413
    list_for_each_entry(domain, &master->domains, list) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1414
        ret = ec_domain_finish(domain, domain_offset);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1415
        if (ret < 0) {
1197
f65f9c36ba33 Fixed missing up().
Florian Pose <fp@igh-essen.com>
parents: 1181
diff changeset
  1416
            up(&master->master_sem);
926
6bb33c6ec770 Output subindices with %02X.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1417
            EC_ERR("Failed to finish domain 0x%08X!\n", (u32) domain);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1418
            return ret;
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
  1419
        }
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
        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
  1421
    }
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1422
    
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1423
    up(&master->master_sem);
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
  1424
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1425
    // 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
  1426
#ifdef EC_EOE
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1427
    ec_master_eoe_stop(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1428
#endif
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1429
    ec_master_thread_stop(master);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1430
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
    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
  1432
        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
  1433
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1434
    master->injection_seq_fsm = 0;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  1435
    master->injection_seq_rt = 0;
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1436
    master->request_cb = master->ext_request_cb;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1437
    master->release_cb = master->ext_release_cb;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1438
    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
  1439
    
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1440
    ret = ec_master_thread_start(master, ec_master_operation_thread,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1441
                "EtherCAT-OP");
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1442
    if (ret < 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
  1443
        EC_ERR("Failed to start master thread!\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1444
        return ret;
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
  1445
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1446
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1447
    ec_master_eoe_start(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1448
#endif
902
ad703091a32b Moved setting of the allow flags.
Florian Pose <fp@igh-essen.com>
parents: 901
diff changeset
  1449
ad703091a32b Moved setting of the allow flags.
Florian Pose <fp@igh-essen.com>
parents: 901
diff changeset
  1450
    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
  1451
    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
  1452
    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
  1453
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1454
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1455
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
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
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
  1458
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1459
    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
  1460
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1461
    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
  1462
        // 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
  1463
        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
  1464
        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
  1465
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1466
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1467
    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
  1468
        // 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
  1469
        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
  1470
            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
  1471
            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
  1472
        }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1473
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1474
        // 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
  1475
        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
  1476
        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
  1477
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1478
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1479
    // 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
  1480
    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
  1481
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1482
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1483
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1484
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1485
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
  1486
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1487
    ec_datagram_t *datagram, *next;
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
  1488
    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
  1489
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1490
    // 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
  1491
    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
  1492
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1493
    // 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
  1494
    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
  1495
        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
  1496
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1497
#ifdef EC_HAVE_CYCLES
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
  1498
        if (master->main_device.cycles_poll - datagram->cycles_sent
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
  1499
                > timeout_cycles) {
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1500
#else
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
  1501
        if (master->main_device.jiffies_poll - datagram->jiffies_sent
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
  1502
                > timeout_jiffies) {
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1503
#endif
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
  1504
            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
  1505
            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
  1506
            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
  1507
            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
  1508
            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
  1509
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1510
            if (unlikely(master->debug_level > 0)) {
1237
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  1511
                unsigned int time_us;
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  1512
#ifdef EC_HAVE_CYCLES
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  1513
                time_us = (unsigned int) (master->main_device.cycles_poll -
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  1514
                        datagram->cycles_sent) * 1000 / cpu_khz;
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  1515
#else
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
  1516
                time_us = (unsigned int) ((master->main_device.jiffies_poll -
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
  1517
                            datagram->jiffies_sent) * 1000000 / HZ);
1237
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  1518
#endif
691
77b79a29e0e7 Included datagram queuing in critical section in idle task; added some
Florian Pose <fp@igh-essen.com>
parents: 690
diff changeset
  1519
                EC_DBG("TIMED OUT datagram %08x, index %02X waited %u us.\n",
1237
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  1520
                        (unsigned int) datagram, datagram->index, time_us);
684
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1521
            }
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
  1522
        }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1523
    }
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
  1524
18c48cb7de06 Introduced frames_timed_out flag to notice bus failure when link down is
Florian Pose <fp@igh-essen.com>
parents: 663
diff changeset
  1525
    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
  1526
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1527
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1528
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  1529
1332
d62633fea8ed merge -c1610 branches/stable-1.4: Added missing doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 1329
diff changeset
  1530
/** Same as ecrt_master_slave_config(), but with ERR_PTR() return value.
d62633fea8ed merge -c1610 branches/stable-1.4: Added missing doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 1329
diff changeset
  1531
 */
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1532
ec_slave_config_t *ecrt_master_slave_config_err(ec_master_t *master,
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1533
        uint16_t alias, uint16_t position, uint32_t vendor_id,
1010
6672b86e7b10 Reverted revision number checking from r1228.
Florian Pose <fp@igh-essen.com>
parents: 1009
diff changeset
  1534
        uint32_t product_code)
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1535
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1536
    ec_slave_config_t *sc;
697
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1537
    unsigned int found = 0;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1538
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1539
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1540
    if (master->debug_level)
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1541
        EC_DBG("ecrt_master_slave_config(master = 0x%x, alias = %u, "
1329
379e60baa5be merge -c1606 branches/stable-1.4: Output vendor Id in hex.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
  1542
                "position = %u, vendor_id = 0x%x, product_code = 0x%x)\n",
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1543
                (u32) master, alias, position, vendor_id, product_code);
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1544
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1545
    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
  1546
        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
  1547
            found = 1;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1548
            break;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1549
        }
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1550
    }
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  1551
1024
fef0b1953770 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1023
diff changeset
  1552
    if (found) { // config with same alias/position already existing
1010
6672b86e7b10 Reverted revision number checking from r1228.
Florian Pose <fp@igh-essen.com>
parents: 1009
diff changeset
  1553
        if (sc->vendor_id != vendor_id || sc->product_code != product_code) {
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1554
            EC_ERR("Slave type mismatch. Slave was configured as"
1010
6672b86e7b10 Reverted revision number checking from r1228.
Florian Pose <fp@igh-essen.com>
parents: 1009
diff changeset
  1555
                    " 0x%08X/0x%08X before. Now configuring with"
6672b86e7b10 Reverted revision number checking from r1228.
Florian Pose <fp@igh-essen.com>
parents: 1009
diff changeset
  1556
                    " 0x%08X/0x%08X.\n", sc->vendor_id, sc->product_code,
6672b86e7b10 Reverted revision number checking from r1228.
Florian Pose <fp@igh-essen.com>
parents: 1009
diff changeset
  1557
                    vendor_id, product_code);
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1558
            return ERR_PTR(-ENOENT);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1559
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1560
    } else {
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1047
diff changeset
  1561
        if (master->debug_level)
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1047
diff changeset
  1562
            EC_DBG("Creating slave configuration for %u:%u, 0x%08X/0x%08X.\n",
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1047
diff changeset
  1563
                    alias, position, vendor_id, product_code);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1564
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1565
        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
  1566
                        GFP_KERNEL))) {
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1567
            EC_ERR("Failed to allocate memory for slave configuration.\n");
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1568
            return ERR_PTR(-ENOMEM);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1569
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1570
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
  1571
        ec_slave_config_init(sc, master,
1010
6672b86e7b10 Reverted revision number checking from r1228.
Florian Pose <fp@igh-essen.com>
parents: 1009
diff changeset
  1572
                alias, position, vendor_id, product_code);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1573
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1574
        down(&master->master_sem);
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1575
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1576
        // try to find the addressed slave
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1047
diff changeset
  1577
        ec_slave_config_attach(sc);
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1047
diff changeset
  1578
        ec_slave_config_load_default_sync_config(sc);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1579
        list_add_tail(&sc->list, &master->configs);
1075
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1580
94c6e36e0f8d Implemented master semaphore to secure concurrent access from ioctls, state machine and realtime interface.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1581
        up(&master->master_sem);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1582
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1583
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1584
    return sc;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1585
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1586
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1587
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1588
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1589
ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master,
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1590
        uint16_t alias, uint16_t position, uint32_t vendor_id,
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1591
        uint32_t product_code)
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1592
{
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1593
    ec_slave_config_t *sc = ecrt_master_slave_config_err(master, alias,
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1594
            position, vendor_id, product_code);
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1595
    return IS_ERR(sc) ? NULL : sc;
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1596
}
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1597
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1598
/*****************************************************************************/
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  1599
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1600
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
  1601
        void (*release_cb)(void *), void *cb_data)
204
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1602
{
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1603
    if (master->debug_level)
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1604
        EC_DBG("ecrt_master_callbacks(master = 0x%x, request_cb = 0x%x, "
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1605
                " release_cb = 0x%x, cb_data = 0x%x)\n", (u32) master,
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1606
                (u32) request_cb, (u32) release_cb, (u32) cb_data);
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  1607
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1608
    master->ext_request_cb = request_cb;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1609
    master->ext_release_cb = release_cb;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1610
    master->ext_cb_data = cb_data;
204
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1611
}
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1612
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1613
/*****************************************************************************/
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  1614
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1615
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
  1616
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1617
    state->slaves_responding = master->fsm.slaves_responding;
1022
8e49b519e6ba Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents: 1018
diff changeset
  1618
    state->al_states = master->fsm.slave_states;
1018
e068da25639d Completed master states.
Richard Hacker <ha@igh-essen.com>
parents: 1015
diff changeset
  1619
    state->link_up = master->main_device.link_state;
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1620
}
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1621
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1622
/*****************************************************************************/
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  1623
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
  1624
void ecrt_master_sync(ec_master_t *master, const struct timeval *app_time)
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
  1625
{
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
  1626
    master->app_time = EC_TIMEVAL2NANO(app_time);
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
  1627
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
  1628
#if 1
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
  1629
    EC_WRITE_U32(master->ref_sync_datagram.data, master->app_time);
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
  1630
    ec_master_queue_datagram(master, &master->ref_sync_datagram);
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
  1631
#endif
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
  1632
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
  1633
#if 1
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  1634
    ec_datagram_zero(&master->sync_datagram);
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  1635
    ec_master_queue_datagram(master, &master->sync_datagram);
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
  1636
#endif
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  1637
}
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  1638
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  1639
/*****************************************************************************/
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  1640
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1641
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1642
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1643
EXPORT_SYMBOL(ecrt_master_create_domain);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  1644
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
  1645
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
  1646
EXPORT_SYMBOL(ecrt_master_receive);
206
60a10d85c20b Prepared EoE processing with workqueue.
Florian Pose <fp@igh-essen.com>
parents: 204
diff changeset
  1647
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
  1648
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
  1649
EXPORT_SYMBOL(ecrt_master_state);
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  1650
EXPORT_SYMBOL(ecrt_master_sync);
42
a22a202d0f42 Domains, Warten beim Senden, 10kHz.
Florian Pose <fp@igh-essen.com>
parents: 39
diff changeset
  1651
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1652
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1653
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  1654
/*****************************************************************************/