master/master.c
author Florian Pose <fp@igh-essen.com>
Tue, 12 Feb 2013 17:30:45 +0100
branchstable-1.5
changeset 2525 4c2e37d2237c
parent 2522 ec403cf308eb
child 2529 c7e1f2616a9d
permissions -rw-r--r--
Fixed missing distribution of lib/ioctl.h.
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
 *
2085
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
     3
 *  $Id$
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
     5
 *  Copyright (C) 2006-2012  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
 *
1873
219be3742274 Added missing queue_external_datagram(); removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
    28
 *  vim: expandtab
219be3742274 Added missing queue_external_datagram(); removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1856
diff changeset
    29
 *
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 35
diff changeset
    30
 *****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    32
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    33
   \file
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    34
   EtherCAT master methods.
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
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    37
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    38
24
d417dd9bdc2f Wilhelms ?nderungen ?bernommen.
Florian Pose <fp@igh-essen.com>
parents: 23
diff changeset
    39
#include <linux/module.h>
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include <linux/kernel.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <linux/string.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include <linux/slab.h>
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#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
    44
#include <linux/device.h>
24efac66a647 Added support for different versions of class_device_create().
Florian Pose <fp@igh-essen.com>
parents: 1013
diff changeset
    45
#include <linux/version.h>
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
    46
#include <linux/hrtimer.h>
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    47
#include "globals.h"
55
059a9e712aa7 Mit neuer Schnittstelle wieder lauff?hig.
Florian Pose <fp@igh-essen.com>
parents: 54
diff changeset
    48
#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
    49
#include "slave_config.h"
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    50
#include "device.h"
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
    51
#include "datagram.h"
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    52
#ifdef EC_EOE
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
    53
#include "ethernet.h"
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    54
#endif
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    55
#include "master.h"
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    56
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    57
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    58
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
    59
/** Set to 1 to enable external datagram injection debugging.
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
    60
 */
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
    61
#define DEBUG_INJECT 0
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
    62
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    63
#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
    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 cycles.
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 cycles_t timeout_cycles;
1906
96805a6eae3d Renamed sdo_injecton_timeout to ext_injection_timeout.
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    68
96805a6eae3d Renamed sdo_injecton_timeout to ext_injection_timeout.
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    69
/** Timeout for external datagram injection [cycles].
96805a6eae3d Renamed sdo_injecton_timeout to ext_injection_timeout.
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    70
 */
96805a6eae3d Renamed sdo_injecton_timeout to ext_injection_timeout.
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    71
static cycles_t ext_injection_timeout_cycles;
96805a6eae3d Renamed sdo_injecton_timeout to ext_injection_timeout.
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    72
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    73
#else
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    74
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    75
/** 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
    76
 */
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    77
static unsigned long timeout_jiffies;
1906
96805a6eae3d Renamed sdo_injecton_timeout to ext_injection_timeout.
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    78
96805a6eae3d Renamed sdo_injecton_timeout to ext_injection_timeout.
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    79
/** Timeout for external datagram injection [jiffies].
96805a6eae3d Renamed sdo_injecton_timeout to ext_injection_timeout.
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    80
 */
96805a6eae3d Renamed sdo_injecton_timeout to ext_injection_timeout.
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    81
static unsigned long ext_injection_timeout_jiffies;
1585
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
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
#endif
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    84
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
    85
/** List of intervals for statistics [s].
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
    86
 */
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
    87
const unsigned int rate_intervals[] = {
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
    88
    1, 10, 60
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
    89
};
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
    90
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    91
/*****************************************************************************/
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    92
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
    93
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
    94
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
    95
static int ec_master_idle_thread(void *);
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
    96
static int ec_master_operation_thread(void *);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    97
#ifdef EC_EOE
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
    98
static int ec_master_eoe_thread(void *);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
    99
#endif
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   100
void ec_master_find_dc_ref_clock(ec_master_t *);
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
   101
void ec_master_clear_device_stats(ec_master_t *);
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
   102
void ec_master_update_device_stats(ec_master_t *);
179
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
   103
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
   104
/*****************************************************************************/
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
   105
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   106
/** 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
   107
*/
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   108
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
   109
{
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   110
#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
   111
    timeout_cycles = (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000);
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   112
    ext_injection_timeout_cycles =
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   113
        (cycles_t) EC_SDO_INJECTION_TIMEOUT /* us */ * (cpu_khz / 1000);
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   114
#else
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   115
    // 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
   116
    timeout_jiffies = max(EC_IO_TIMEOUT * HZ / 1000000, 1);
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   117
    ext_injection_timeout_jiffies =
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   118
        max(EC_SDO_INJECTION_TIMEOUT * HZ / 1000000, 1);
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   119
#endif
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   120
}
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   121
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   122
/*****************************************************************************/
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   123
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   125
   Master constructor.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   126
   \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
   127
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   128
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   129
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
   130
        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
   131
        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
   132
        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
   133
        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
   134
        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
   135
        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
   136
        )
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   137
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   138
    int ret;
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   139
    unsigned int dev_idx, i;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   140
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   141
    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
   142
    master->reserved = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   143
1579
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   144
    sema_init(&master->master_sem, 1);
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
   145
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   146
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < EC_MAX_NUM_DEVICES; dev_idx++) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   147
        master->macs[dev_idx] = NULL;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   148
    }
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   149
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   150
    master->macs[EC_DEVICE_MAIN] = main_mac;
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   151
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   152
#if EC_MAX_NUM_DEVICES > 1
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   153
    master->macs[EC_DEVICE_BACKUP] = backup_mac;
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   154
    master->num_devices = 1 + !ec_mac_is_zero(backup_mac);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   155
#else
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   156
    if (!ec_mac_is_zero(backup_mac)) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   157
        EC_MASTER_WARN(master, "Ignoring backup MAC address!");
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   158
    }
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   159
#endif
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   160
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
   161
    ec_master_clear_device_stats(master);
1579
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   162
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   163
    sema_init(&master->device_sem, 1);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   164
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   165
    master->phase = EC_ORPHANED;
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   166
    master->active = 0;
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   167
    master->config_changed = 0;
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   168
    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
   169
    master->injection_seq_rt = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   170
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   171
    master->slaves = NULL;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   172
    master->slave_count = 0;
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
   173
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   174
    INIT_LIST_HEAD(&master->configs);
2300
70b15347c707 Minor: Ordered master member initialisations.
Florian Pose <fp@igh-essen.com>
parents: 2269
diff changeset
   175
    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
   176
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
   177
    master->app_time = 0ULL;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
   178
    master->app_start_time = 0ULL;
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   179
    master->has_app_time = 0;
1408
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
   180
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   181
    master->scan_busy = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   182
    master->allow_scan = 1;
1579
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   183
    sema_init(&master->scan_sem, 1);
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   184
    init_waitqueue_head(&master->scan_queue);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   185
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   186
    master->config_busy = 0;
1579
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   187
    sema_init(&master->config_sem, 1);
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   188
    init_waitqueue_head(&master->config_queue);
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
   189
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   190
    INIT_LIST_HEAD(&master->datagram_queue);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   191
    master->datagram_index = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   192
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   193
    INIT_LIST_HEAD(&master->ext_datagram_queue);
1579
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   194
    sema_init(&master->ext_queue_sem, 1);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   195
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   196
    master->ext_ring_idx_rt = 0;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   197
    master->ext_ring_idx_fsm = 0;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   198
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   199
    // init external datagram ring
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   200
    for (i = 0; i < EC_EXT_RING_SIZE; i++) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   201
        ec_datagram_t *datagram = &master->ext_datagram_ring[i];
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   202
        ec_datagram_init(datagram);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   203
        snprintf(datagram->name, EC_DATAGRAM_NAME_SIZE, "ext-%u", i);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   204
    }
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
   205
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   206
    // send interval in IDLE phase
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   207
    ec_master_set_send_interval(master, 1000000 / HZ);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
   208
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   209
    master->fsm_slave = NULL;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   210
    INIT_LIST_HEAD(&master->fsm_exec_list);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   211
    master->fsm_exec_count = 0U;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   212
1399
f79d4bb5b23a Added debug_level module parameter. debug_level is now unsigned int.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
   213
    master->debug_level = debug_level;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   214
    master->stats.timeouts = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   215
    master->stats.corrupted = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   216
    master->stats.unmatched = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   217
    master->stats.output_jiffies = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   218
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   219
    master->thread = NULL;
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   220
1041
42c9ac58d9ce Removed state machine cycle time measuring.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   221
#ifdef EC_EOE
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
   222
    master->eoe_thread = NULL;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   223
    INIT_LIST_HEAD(&master->eoe_handlers);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   224
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   225
1579
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   226
    sema_init(&master->io_sem, 1);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   227
    master->send_cb = NULL;
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   228
    master->receive_cb = NULL;
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   229
    master->cb_data = NULL;
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   230
    master->app_send_cb = NULL;
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   231
    master->app_receive_cb = NULL;
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   232
    master->app_cb_data = NULL;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   233
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   234
    INIT_LIST_HEAD(&master->sii_requests);
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
   235
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
   236
    init_waitqueue_head(&master->request_queue);
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 597
diff changeset
   237
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   238
    // init devices
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   239
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   240
            dev_idx++) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   241
        ret = ec_device_init(&master->devices[dev_idx], master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   242
        if (ret < 0) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   243
            goto out_clear_devices;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   244
        }
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   245
    }
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   246
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
   247
    // 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
   248
    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
   249
    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
   250
    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
   251
    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
   252
        ec_datagram_clear(&master->fsm_datagram);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   253
        EC_MASTER_ERR(master, "Failed to allocate FSM datagram.\n");
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   254
        goto out_clear_devices;
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
   255
    }
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
   256
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   257
    // 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
   258
    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
   259
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   260
    // alloc external datagram ring
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   261
    for (i = 0; i < EC_EXT_RING_SIZE; i++) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   262
        ec_datagram_t *datagram = &master->ext_datagram_ring[i];
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   263
        ret = ec_datagram_prealloc(datagram, EC_MAX_DATA_SIZE);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   264
        if (ret) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   265
            EC_MASTER_ERR(master, "Failed to allocate external"
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   266
                    " datagram %u.\n", i);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   267
            goto out_clear_ext_datagrams;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   268
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   269
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   270
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   271
    // init reference sync datagram
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   272
    ec_datagram_init(&master->ref_sync_datagram);
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   273
    snprintf(master->ref_sync_datagram.name, EC_DATAGRAM_NAME_SIZE,
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   274
            "refsync");
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
   275
    ret = ec_datagram_prealloc(&master->ref_sync_datagram, 4);
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   276
    if (ret < 0) {
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   277
        ec_datagram_clear(&master->ref_sync_datagram);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   278
        EC_MASTER_ERR(master, "Failed to allocate reference"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   279
                " synchronisation datagram.\n");
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   280
        goto out_clear_ext_datagrams;
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   281
    }
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   282
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   283
    // 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
   284
    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
   285
    snprintf(master->sync_datagram.name, EC_DATAGRAM_NAME_SIZE, "sync");
1408
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
   286
    ret = ec_datagram_prealloc(&master->sync_datagram, 4);
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   287
    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
   288
        ec_datagram_clear(&master->sync_datagram);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   289
        EC_MASTER_ERR(master, "Failed to allocate"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   290
                " synchronisation datagram.\n");
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   291
        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
   292
    }
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   293
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   294
    // init sync monitor datagram
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   295
    ec_datagram_init(&master->sync_mon_datagram);
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   296
    snprintf(master->sync_mon_datagram.name, EC_DATAGRAM_NAME_SIZE,
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   297
            "syncmon");
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   298
    ret = ec_datagram_brd(&master->sync_mon_datagram, 0x092c, 4);
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   299
    if (ret < 0) {
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   300
        ec_datagram_clear(&master->sync_mon_datagram);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   301
        EC_MASTER_ERR(master, "Failed to allocate sync"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   302
                " monitoring datagram.\n");
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   303
        goto out_clear_sync;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   304
    }
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   305
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
   306
    master->dc_ref_config = NULL;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
   307
    master->dc_ref_clock = NULL;
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   308
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   309
    // init character device
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   310
    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
   311
    if (ret)
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   312
        goto out_clear_sync_mon;
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
   313
1369
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   314
#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
   315
    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
   316
            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
   317
            "EtherCAT%u", master->index);
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   318
#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
   319
    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
   320
            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
   321
            "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
   322
#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
   323
    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
   324
            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
   325
            "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
   326
#else
1250
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   327
    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
   328
            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
   329
            "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
   330
#endif
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   331
    if (IS_ERR(master->class_device)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   332
        EC_MASTER_ERR(master, "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
   333
        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
   334
        goto out_clear_cdev;
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   335
    }
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   336
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   337
#ifdef EC_RTDM
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   338
    // init RTDM device
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   339
    ret = ec_rtdm_dev_init(&master->rtdm_dev, master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   340
    if (ret) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   341
        goto out_unregister_class_device;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   342
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   343
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   344
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   345
    return 0;
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   346
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   347
#ifdef EC_RTDM
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   348
out_unregister_class_device:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   349
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   350
    device_unregister(master->class_device);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   351
#else
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   352
    class_device_unregister(master->class_device);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   353
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   354
#endif
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   355
out_clear_cdev:
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   356
    ec_cdev_clear(&master->cdev);
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   357
out_clear_sync_mon:
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   358
    ec_datagram_clear(&master->sync_mon_datagram);
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   359
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
   360
    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
   361
out_clear_ref_sync:
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   362
    ec_datagram_clear(&master->ref_sync_datagram);
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   363
out_clear_ext_datagrams:
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   364
    for (i = 0; i < EC_EXT_RING_SIZE; i++) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   365
        ec_datagram_clear(&master->ext_datagram_ring[i]);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   366
    }
659
d7c5a958bad0 Removed unecessary clearing of EoE handlers in master init function;
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   367
    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
   368
    ec_datagram_clear(&master->fsm_datagram);
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   369
out_clear_devices:
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   370
    for (; dev_idx > 0; dev_idx--) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   371
        ec_device_clear(&master->devices[dev_idx - 1]);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   372
    }
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   373
    return ret;
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   374
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 35
diff changeset
   376
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   377
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   378
/** Destructor.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   379
*/
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   380
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
   381
        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
   382
        )
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   383
{
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   384
    unsigned int dev_idx, i;
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   385
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   386
#ifdef EC_RTDM
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   387
    ec_rtdm_dev_clear(&master->rtdm_dev);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   388
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2421
diff changeset
   389
1250
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   390
#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
   391
    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
   392
#else
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   393
    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
   394
#endif
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   395
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   396
    ec_cdev_clear(&master->cdev);
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
   397
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   398
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   399
    ec_master_clear_eoe_handlers(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   400
#endif
994
e29edcced328 Clear domains before slave configs, because domain references the FMMU
Florian Pose <fp@igh-essen.com>
parents: 993
diff changeset
   401
    ec_master_clear_domains(master);
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   402
    ec_master_clear_slave_configs(master);
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   403
    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
   404
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   405
    ec_datagram_clear(&master->sync_mon_datagram);
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   406
    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
   407
    ec_datagram_clear(&master->ref_sync_datagram);
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   408
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   409
    for (i = 0; i < EC_EXT_RING_SIZE; i++) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   410
        ec_datagram_clear(&master->ext_datagram_ring[i]);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   411
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   412
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
   413
    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
   414
    ec_datagram_clear(&master->fsm_datagram);
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   415
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   416
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   417
            dev_idx++) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   418
        ec_device_clear(&master->devices[dev_idx]);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   419
    }
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   420
}
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   421
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   422
/*****************************************************************************/
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   423
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   424
#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
   425
/** Clear and free all EoE handlers.
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   426
 */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   427
void ec_master_clear_eoe_handlers(
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   428
        ec_master_t *master /**< EtherCAT master */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   429
        )
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   430
{
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   431
    ec_eoe_t *eoe, *next;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   432
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   433
    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
   434
        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
   435
        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
   436
        kfree(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   437
    }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   438
}
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   439
#endif
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   440
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   441
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   442
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   443
/** 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
   444
 */
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   445
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
   446
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   447
    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
   448
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
   449
    master->dc_ref_config = NULL;
2457
30a6df891e7d Mark processing SDO request as invalid if config is cleared.
Florian Pose <fp@igh-essen.com>
parents: 2456
diff changeset
   450
    master->fsm.sdo_request = NULL; // mark sdo_request as invalid
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
   451
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   452
    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
   453
        list_del(&sc->list);
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   454
        ec_slave_config_clear(sc);
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   455
        kfree(sc);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   456
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   457
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   458
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   459
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   460
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   461
/** 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
   462
 */
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   463
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
   464
{
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   465
    ec_slave_t *slave;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   466
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   467
    master->dc_ref_clock = NULL;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   468
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
   469
    // External requests are obsolete, so we wake pending waiters and remove
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
   470
    // them from the list.
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   471
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   472
    while (!list_empty(&master->sii_requests)) {
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   473
        ec_sii_write_request_t *request =
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   474
            list_entry(master->sii_requests.next,
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   475
                    ec_sii_write_request_t, list);
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   476
        list_del_init(&request->list); // dequeue
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   477
        EC_MASTER_WARN(master, "Discarding SII request, slave %u about"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   478
                " to be deleted.\n", request->slave->ring_position);
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   479
        request->state = EC_INT_REQUEST_FAILURE;
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   480
        wake_up_all(&master->request_queue);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   481
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   482
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   483
    master->fsm_slave = NULL;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   484
    INIT_LIST_HEAD(&master->fsm_exec_list);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   485
    master->fsm_exec_count = 0;
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   486
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   487
    for (slave = master->slaves;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   488
            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
   489
            slave++) {
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   490
        ec_slave_clear(slave);
1004
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   491
    }
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   492
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   493
    if (master->slaves) {
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   494
        kfree(master->slaves);
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   495
        master->slaves = NULL;
1004
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   496
    }
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   497
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   498
    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
   499
}
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   500
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   501
/*****************************************************************************/
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   502
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   503
/** Clear all domains.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   504
 */
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   505
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
   506
{
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   507
    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
   508
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   509
    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
   510
        list_del(&domain->list);
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   511
        ec_domain_clear(domain);
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   512
        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
   513
    }
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   514
}
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   515
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   516
/*****************************************************************************/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   517
1939
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   518
/** Clear the configuration applied by the application.
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   519
 */
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   520
void ec_master_clear_config(
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   521
        ec_master_t *master /**< EtherCAT master. */
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   522
        )
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   523
{
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   524
    down(&master->master_sem);
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   525
    ec_master_clear_domains(master);
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   526
    ec_master_clear_slave_configs(master);
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   527
    up(&master->master_sem);
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   528
}
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   529
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   530
/*****************************************************************************/
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   531
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   532
/** Internal sending callback.
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   533
 */
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   534
void ec_master_internal_send_cb(
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   535
        void *cb_data /**< Callback data. */
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   536
        )
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   537
{
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   538
    ec_master_t *master = (ec_master_t *) cb_data;
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
   539
    down(&master->io_sem);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   540
    ecrt_master_send_ext(master);
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   541
    up(&master->io_sem);
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   542
}
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   543
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   544
/*****************************************************************************/
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   545
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   546
/** Internal receiving callback.
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   547
 */
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   548
void ec_master_internal_receive_cb(
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   549
        void *cb_data /**< Callback data. */
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   550
        )
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   551
{
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   552
    ec_master_t *master = (ec_master_t *) cb_data;
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   553
    down(&master->io_sem);
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   554
    ecrt_master_receive(master);
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
   555
    up(&master->io_sem);
515
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   556
}
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   557
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   558
/*****************************************************************************/
37aa1bfa0dee Internal locking callbacks, improved locking.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   559
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   560
/** Starts the master thread.
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   561
 *
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   562
 * \retval  0 Success.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   563
 * \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
   564
 */
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   565
int ec_master_thread_start(
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   566
        ec_master_t *master, /**< EtherCAT master */
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   567
        int (*thread_func)(void *), /**< thread function to start */
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   568
        const char *name /**< Thread name. */
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   569
        )
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   570
{
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   571
    EC_MASTER_INFO(master, "Starting %s thread.\n", name);
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   572
    master->thread = kthread_run(thread_func, master, name);
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   573
    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
   574
        int err = (int) PTR_ERR(master->thread);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   575
        EC_MASTER_ERR(master, "Failed to start master thread (error %i)!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   576
                err);
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   577
        master->thread = NULL;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   578
        return err;
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   579
    }
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
   580
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   581
    return 0;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   582
}
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   583
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   584
/*****************************************************************************/
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   585
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   586
/** Stops the master thread.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   587
 */
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   588
void ec_master_thread_stop(
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   589
        ec_master_t *master /**< EtherCAT master */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   590
        )
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   591
{
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   592
    unsigned long sleep_jiffies;
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
   593
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   594
    if (!master->thread) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   595
        EC_MASTER_WARN(master, "%s(): Already finished!\n", __func__);
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   596
        return;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   597
    }
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   598
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   599
    EC_MASTER_DBG(master, 1, "Stopping master thread.\n");
1006
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   600
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   601
    kthread_stop(master->thread);
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   602
    master->thread = NULL;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   603
    EC_MASTER_INFO(master, "Master thread exited.\n");
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   604
2455
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
   605
    if (master->fsm_datagram.state != EC_DATAGRAM_SENT) {
1198
be606e9caba4 Fixed race concerning thread signaling when master thread had no
Florian Pose <fp@igh-essen.com>
parents: 1197
diff changeset
   606
        return;
2455
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
   607
    }
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
   608
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   609
    // wait for FSM datagram
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   610
    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
   611
    schedule_timeout(sleep_jiffies);
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   612
}
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   613
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   614
/*****************************************************************************/
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   615
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   616
/** Transition function from ORPHANED to IDLE phase.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
   617
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
   618
 * \return Zero on success, otherwise a negative error code.
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   619
 */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   620
int ec_master_enter_idle_phase(
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   621
        ec_master_t *master /**< EtherCAT master */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   622
        )
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   623
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   624
    int ret;
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
   625
    ec_device_index_t dev_idx;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   626
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   627
    EC_MASTER_DBG(master, 1, "ORPHANED -> IDLE.\n");
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
   628
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   629
    master->send_cb = ec_master_internal_send_cb;
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   630
    master->receive_cb = ec_master_internal_receive_cb;
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   631
    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
   632
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   633
    master->phase = EC_IDLE;
2301
01e4381ebd09 Improved resetting number of responding slaves.
Florian Pose <fp@igh-essen.com>
parents: 2300
diff changeset
   634
01e4381ebd09 Improved resetting number of responding slaves.
Florian Pose <fp@igh-essen.com>
parents: 2300
diff changeset
   635
    // reset number of responding slaves to trigger scanning
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   636
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   637
            dev_idx++) {
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
   638
        master->fsm.slaves_responding[dev_idx] = 0;
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
   639
    }
2301
01e4381ebd09 Improved resetting number of responding slaves.
Florian Pose <fp@igh-essen.com>
parents: 2300
diff changeset
   640
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   641
    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
   642
            "EtherCAT-IDLE");
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   643
    if (ret)
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   644
        master->phase = EC_ORPHANED;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   645
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   646
    return ret;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   647
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   648
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   649
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   650
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   651
/** Transition function from IDLE to ORPHANED phase.
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   652
 */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   653
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
   654
{
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   655
    EC_MASTER_DBG(master, 1, "IDLE -> ORPHANED.\n");
1006
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   656
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   657
    master->phase = EC_ORPHANED;
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
   658
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   659
#ifdef EC_EOE
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   660
    ec_master_eoe_stop(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   661
#endif
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   662
    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
   663
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
   664
    down(&master->master_sem);
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   665
    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
   666
    up(&master->master_sem);
2456
a9bbc44584e0 Reset master state machine when going to orphaned phase.
Florian Pose <fp@igh-essen.com>
parents: 2455
diff changeset
   667
a9bbc44584e0 Reset master state machine when going to orphaned phase.
Florian Pose <fp@igh-essen.com>
parents: 2455
diff changeset
   668
    ec_fsm_master_reset(&master->fsm);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   669
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   670
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   671
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   672
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   673
/** Transition function from IDLE to OPERATION phase.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
   674
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
   675
 * \return Zero on success, otherwise a negative error code.
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   676
 */
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   677
int ec_master_enter_operation_phase(
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   678
        ec_master_t *master /**< EtherCAT master */
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   679
        )
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   680
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   681
    int ret = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   682
    ec_slave_t *slave;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   683
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   684
    ec_eoe_t *eoe;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   685
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   686
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   687
    EC_MASTER_DBG(master, 1, "IDLE -> OPERATION.\n");
1006
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   688
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   689
    down(&master->config_sem);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   690
    if (master->config_busy) {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   691
        up(&master->config_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   692
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   693
        // 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
   694
        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
   695
                    !master->config_busy);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   696
        if (ret) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   697
            EC_MASTER_INFO(master, "Finishing slave configuration"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   698
                    " interrupted by signal.\n");
2349
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
   699
            goto out_return;
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   700
        }
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   701
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   702
        EC_MASTER_DBG(master, 1, "Waiting for pending slave"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   703
                " configuration returned.\n");
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   704
    } else {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   705
        up(&master->config_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   706
    }
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   707
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   708
    down(&master->scan_sem);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   709
    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
   710
    if (!master->scan_busy) {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   711
        up(&master->scan_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   712
    } else {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   713
        up(&master->scan_sem);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   714
794
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   715
        // wait for slave scan to complete
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   716
        ret = wait_event_interruptible(master->scan_queue,
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
   717
                !master->scan_busy);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   718
        if (ret) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   719
            EC_MASTER_INFO(master, "Waiting for slave scan"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   720
                    " interrupted by signal.\n");
794
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   721
            goto out_allow;
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   722
        }
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
   723
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   724
        EC_MASTER_DBG(master, 1, "Waiting for pending"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   725
                " slave scan returned.\n");
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   726
    }
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   727
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   728
    // 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
   729
    for (slave = master->slaves;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   730
            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
   731
            slave++) {
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 640
diff changeset
   732
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   733
    }
1451
78fbafbf08ba Always set DC reference clock to OP.
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
   734
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   735
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   736
    // ... but set EoE slaves to OP
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   737
    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
   738
        if (ec_eoe_is_open(eoe))
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   739
            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
   740
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   741
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   742
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   743
    master->phase = EC_OPERATION;
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   744
    master->app_send_cb = NULL;
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   745
    master->app_receive_cb = NULL;
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   746
    master->app_cb_data = NULL;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   747
    return ret;
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
   748
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   749
out_allow:
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   750
    master->allow_scan = 1;
2349
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
   751
out_return:
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   752
    return ret;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   753
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   754
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   755
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   756
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   757
/** Transition function from OPERATION to IDLE phase.
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   758
 */
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   759
void ec_master_leave_operation_phase(
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   760
        ec_master_t *master /**< EtherCAT master */
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   761
        )
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   762
{
1939
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   763
    if (master->active) {
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   764
        ecrt_master_deactivate(master); // also clears config
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   765
    } else {
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   766
        ec_master_clear_config(master);
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   767
    }
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   768
2349
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
   769
    /* Re-allow scanning for IDLE phase. */
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
   770
    master->allow_scan = 1;
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
   771
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   772
    EC_MASTER_DBG(master, 1, "OPERATION -> IDLE.\n");
1006
90db4c3de57b Added a few debugging messages.
Florian Pose <fp@igh-essen.com>
parents: 1004
diff changeset
   773
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   774
    master->phase = EC_IDLE;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   775
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   776
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
   777
/*****************************************************************************/
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
   778
1774
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   779
/** Injects external datagrams that fit into the datagram queue.
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   780
 */
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   781
void ec_master_inject_external_datagrams(
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   782
        ec_master_t *master /**< EtherCAT master */
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   783
        )
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   784
{
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   785
    ec_datagram_t *datagram;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   786
    size_t queue_size = 0, new_queue_size = 0;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   787
#if DEBUG_INJECT
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   788
    unsigned int datagram_count = 0;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   789
#endif
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   790
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   791
    if (master->ext_ring_idx_rt == master->ext_ring_idx_fsm) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   792
        // nothing to inject
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   793
        return;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   794
    }
1774
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   795
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   796
    list_for_each_entry(datagram, &master->datagram_queue, queue) {
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   797
        if (datagram->state == EC_DATAGRAM_QUEUED) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   798
            queue_size += datagram->data_size;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   799
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   800
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   801
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   802
#if DEBUG_INJECT
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   803
    EC_MASTER_DBG(master, 1, "Injecting datagrams, queue_size=%zu\n",
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   804
            queue_size);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   805
#endif
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   806
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   807
    while (master->ext_ring_idx_rt != master->ext_ring_idx_fsm) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   808
        datagram = &master->ext_datagram_ring[master->ext_ring_idx_rt];
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   809
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   810
        if (datagram->state != EC_DATAGRAM_INIT) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   811
            // skip datagram
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   812
            master->ext_ring_idx_rt =
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   813
                (master->ext_ring_idx_rt + 1) % EC_EXT_RING_SIZE;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   814
            continue;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   815
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   816
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   817
        new_queue_size = queue_size + datagram->data_size;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   818
        if (new_queue_size <= master->max_queue_size) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   819
#if DEBUG_INJECT
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   820
            EC_MASTER_DBG(master, 1, "Injecting datagram %s"
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   821
                    " size=%zu, queue_size=%zu\n", datagram->name,
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   822
                    datagram->data_size, new_queue_size);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   823
            datagram_count++;
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   824
#endif
1585
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
   825
#ifdef EC_HAVE_CYCLES
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   826
            datagram->cycles_sent = 0;
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   827
#endif
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   828
            datagram->jiffies_sent = 0;
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
   829
            ec_master_queue_datagram(master, datagram);
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   830
            queue_size = new_queue_size;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   831
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   832
        else if (datagram->data_size > master->max_queue_size) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   833
            datagram->state = EC_DATAGRAM_ERROR;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   834
            EC_MASTER_ERR(master, "External datagram %s is too large,"
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   835
                    " size=%zu, max_queue_size=%zu\n",
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   836
                    datagram->name, datagram->data_size,
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   837
                    master->max_queue_size);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   838
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   839
        else { // datagram does not fit in the current cycle
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   840
#ifdef EC_HAVE_CYCLES
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   841
            cycles_t cycles_now = get_cycles();
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   842
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   843
            if (cycles_now - datagram->cycles_sent
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   844
                    > ext_injection_timeout_cycles)
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   845
#else
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   846
            if (jiffies - datagram->jiffies_sent
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   847
                    > ext_injection_timeout_jiffies)
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   848
#endif
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   849
            {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   850
                unsigned int time_us;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   851
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   852
                datagram->state = EC_DATAGRAM_ERROR;
1585
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
   853
#ifdef EC_HAVE_CYCLES
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   854
                time_us = (unsigned int)
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   855
                    ((cycles_now - datagram->cycles_sent) * 1000LL)
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   856
                    / cpu_khz;
1585
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
   857
#else
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   858
                time_us = (unsigned int)
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   859
                    ((jiffies - datagram->jiffies_sent) * 1000000 / HZ);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   860
#endif
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   861
                EC_MASTER_ERR(master, "Timeout %u us: Injecting"
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   862
                        " external datagram %s size=%zu,"
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   863
                        " max_queue_size=%zu\n", time_us, datagram->name,
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   864
                        datagram->data_size, master->max_queue_size);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   865
            }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   866
            else {
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   867
#if DEBUG_INJECT
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   868
                EC_MASTER_DBG(master, 1, "Deferred injecting"
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   869
                        " external datagram %s size=%u, queue_size=%u\n",
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   870
                        datagram->name, datagram->data_size, queue_size);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   871
#endif
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   872
                break;
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   873
            }
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
   874
        }
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   875
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   876
        master->ext_ring_idx_rt =
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   877
            (master->ext_ring_idx_rt + 1) % EC_EXT_RING_SIZE;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   878
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   879
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   880
#if DEBUG_INJECT
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   881
    EC_MASTER_DBG(master, 1, "Injected %u datagrams.\n", datagram_count);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   882
#endif
1774
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   883
}
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   884
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   885
/*****************************************************************************/
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   886
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   887
/** Sets the expected interval between calls to ecrt_master_send
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   888
 * and calculates the maximum amount of data to queue.
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   889
 */
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   890
void ec_master_set_send_interval(
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   891
        ec_master_t *master, /**< EtherCAT master */
1930
59a50053ccc6 Made send_interval variable an unsigned int; fixed format specifiers for
Florian Pose <fp@igh-essen.com>
parents: 1925
diff changeset
   892
        unsigned int send_interval /**< Send interval */
1774
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   893
        )
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   894
{
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   895
    master->send_interval = send_interval;
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   896
    master->max_queue_size =
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   897
        (send_interval * 1000) / EC_BYTE_TRANSMISSION_TIME_NS;
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   898
    master->max_queue_size -= master->max_queue_size / 10;
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   899
}
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
   900
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
   901
/*****************************************************************************/
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
   902
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   903
/** Searches for a free datagram in the external datagram ring.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
   904
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
   905
 * \return Next free datagram, or NULL.
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   906
 */
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   907
ec_datagram_t *ec_master_get_external_datagram(
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   908
        ec_master_t *master /**< EtherCAT master */
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   909
        )
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   910
{
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   911
    if ((master->ext_ring_idx_fsm + 1) % EC_EXT_RING_SIZE !=
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   912
            master->ext_ring_idx_rt) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   913
        ec_datagram_t *datagram =
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   914
            &master->ext_datagram_ring[master->ext_ring_idx_fsm];
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   915
        return datagram;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   916
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   917
    else {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   918
        return NULL;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
   919
    }
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
   920
}
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
   921
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   922
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   923
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   924
/** 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
   925
 */
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   926
void ec_master_queue_datagram(
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   927
        ec_master_t *master, /**< EtherCAT master */
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
   928
        ec_datagram_t *datagram /**< datagram */
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   929
        )
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   930
{
2085
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   931
    ec_datagram_t *queued_datagram;
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   932
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   933
    /* It is possible, that a datagram in the queue is re-initialized with the
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   934
     * ec_datagram_<type>() methods and then shall be queued with this method.
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   935
     * In that case, the state is already reset to EC_DATAGRAM_INIT. Check if
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   936
     * the datagram is queued to avoid duplicate queuing (which results in an
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   937
     * infinite loop!). Set the state to EC_DATAGRAM_QUEUED again, probably
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   938
     * causing an unmatched datagram. */
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   939
    list_for_each_entry(queued_datagram, &master->datagram_queue, queue) {
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   940
        if (queued_datagram == datagram) {
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   941
            datagram->skip_count++;
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2441
diff changeset
   942
            EC_MASTER_DBG(master, 1,
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2441
diff changeset
   943
                    "Datagram %p already queued (skipping).\n", datagram);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   944
            datagram->state = EC_DATAGRAM_QUEUED;
2085
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   945
            return;
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   946
        }
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   947
    }
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   948
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   949
    list_add_tail(&datagram->queue, &master->datagram_queue);
23ffec5c9c5b Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2082
diff changeset
   950
    datagram->state = EC_DATAGRAM_QUEUED;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   951
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   952
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   953
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   954
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   955
/** Places a datagram in the non-application datagram queue.
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   956
 */
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   957
void ec_master_queue_datagram_ext(
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   958
        ec_master_t *master, /**< EtherCAT master */
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   959
        ec_datagram_t *datagram /**< datagram */
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   960
        )
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   961
{
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   962
    down(&master->ext_queue_sem);
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   963
    list_add_tail(&datagram->queue, &master->ext_datagram_queue);
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   964
    up(&master->ext_queue_sem);
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   965
}
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   966
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   967
/*****************************************************************************/
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   968
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
   969
/** Sends the datagrams in the queue for a certain device.
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   970
 *
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   971
 */
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
   972
void ec_master_send_datagrams(
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
   973
        ec_master_t *master, /**< EtherCAT master */
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
   974
        ec_device_index_t device_index /**< Device index. */
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
   975
        )
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   976
{
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   977
    ec_datagram_t *datagram, *next;
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
   978
    size_t datagram_size;
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
   979
    uint8_t *frame_data, *cur_data = NULL;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   980
    void *follows_word;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   981
#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
   982
    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
   983
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   984
    unsigned long jiffies_sent;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   985
    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
   986
    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
   987
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   988
#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
   989
    cycles_start = get_cycles();
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   990
#endif
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   991
    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
   992
    INIT_LIST_HEAD(&sent_datagrams);
208
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
   993
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
   994
    EC_MASTER_DBG(master, 2, "%s(device_index = %u)\n",
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
   995
            __func__, device_index);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
   996
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   997
    do {
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
   998
        frame_data = NULL;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
   999
        follows_word = NULL;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1000
        more_datagrams_waiting = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1001
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1002
        // fill current frame with datagrams
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1003
        list_for_each_entry(datagram, &master->datagram_queue, queue) {
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1004
            if (datagram->state != EC_DATAGRAM_QUEUED ||
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1005
                    datagram->device_index != device_index) {
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1006
                continue;
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1007
            }
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1008
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1009
            if (!frame_data) {
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1010
                // fetch pointer to transmit socket buffer
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1011
                frame_data =
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1012
                    ec_device_tx_data(&master->devices[device_index]);
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1013
                cur_data = frame_data + EC_FRAME_HEADER_SIZE;
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1014
            }
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1015
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1016
            // does the current datagram fit in the frame?
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1017
            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
  1018
                + EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1019
            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
  1020
                more_datagrams_waiting = 1;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1021
                break;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1022
            }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1023
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1024
            list_add_tail(&datagram->sent, &sent_datagrams);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1025
            datagram->index = master->datagram_index++;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1026
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1027
            EC_MASTER_DBG(master, 2, "Adding datagram 0x%02X\n",
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1028
                    datagram->index);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1029
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1030
            // set "datagram following" flag in previous datagram
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1031
            if (follows_word) {
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1032
                EC_WRITE_U16(follows_word,
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1033
                        EC_READ_U16(follows_word) | 0x8000);
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1034
            }
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1035
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1036
            // EtherCAT datagram header
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1037
            EC_WRITE_U8 (cur_data, datagram->type);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1038
            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
  1039
            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
  1040
            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
  1041
            EC_WRITE_U16(cur_data + 8, 0x0000);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1042
            follows_word = cur_data + 6;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1043
            cur_data += EC_DATAGRAM_HEADER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1044
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1045
            // EtherCAT datagram data
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1046
            memcpy(cur_data, datagram->data, datagram->data_size);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1047
            cur_data += datagram->data_size;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1048
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1049
            // EtherCAT datagram footer
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1050
            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
  1051
            cur_data += EC_DATAGRAM_FOOTER_SIZE;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1052
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1053
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1054
        if (list_empty(&sent_datagrams)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1055
            EC_MASTER_DBG(master, 2, "nothing to send.\n");
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1056
            break;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1057
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1058
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1059
        // EtherCAT frame header
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1060
        EC_WRITE_U16(frame_data, ((cur_data - frame_data
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1061
                        - EC_FRAME_HEADER_SIZE) & 0x7FF) | 0x1000);
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1062
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1063
        // pad frame
211
c684b6b7adaf Using kernel Ethernet constants.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
  1064
        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
  1065
            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
  1066
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1067
        EC_MASTER_DBG(master, 2, "frame size: %zu\n", cur_data - frame_data);
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1068
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1069
        // send frame
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1070
        ec_device_send(&master->devices[device_index],
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1071
                cur_data - frame_data);
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1072
#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
  1073
        cycles_sent = get_cycles();
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1074
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1075
        jiffies_sent = jiffies;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1076
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1077
        // 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
  1078
        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
  1079
            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
  1080
#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
  1081
            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
  1082
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1083
            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
  1084
            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
  1085
        }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1086
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1087
        frame_count++;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1088
    }
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1089
    while (more_datagrams_waiting);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1090
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1091
#ifdef EC_HAVE_CYCLES
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1092
    if (unlikely(master->debug_level > 1)) {
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1093
        cycles_end = get_cycles();
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1094
        EC_MASTER_DBG(master, 0, "%s()"
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  1095
                " sent %u frames in %uus.\n", __func__, frame_count,
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1096
               (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
  1097
    }
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1098
#endif
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1099
}
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1100
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1101
/*****************************************************************************/
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1102
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1103
/** Processes a received frame.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1104
 *
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1105
 * This function is called by the network driver for every received frame.
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
  1106
 *
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1107
 * \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
  1108
 */
331
17f58fe99511 Renamed ec_master_receive() to ec_master_receive_datagrams().
Florian Pose <fp@igh-essen.com>
parents: 330
diff changeset
  1109
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
  1110
                                 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
  1111
                                 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
  1112
                                 )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1113
{
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1114
    size_t frame_size, data_size;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1115
    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
  1116
    unsigned int cmd_follows, matched;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1117
    const uint8_t *cur_data;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1118
    ec_datagram_t *datagram;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1119
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1120
    if (unlikely(size < EC_FRAME_HEADER_SIZE)) {
1303
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1121
        if (master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1122
            EC_MASTER_DBG(master, 0, "Corrupted frame received"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1123
                    " (size %zu < %u byte):\n",
1303
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1124
                    size, EC_FRAME_HEADER_SIZE);
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1125
            ec_print_data(frame_data, size);
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1126
        }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1127
        master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1128
        ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1129
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1130
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1131
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1132
    cur_data = frame_data;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1133
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1134
    // 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
  1135
    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
  1136
    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
  1137
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1138
    if (unlikely(frame_size > size)) {
1303
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1139
        if (master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1140
            EC_MASTER_DBG(master, 0, "Corrupted frame received"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1141
                    " (invalid frame size %zu for "
1543
373cd456dc26 Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  1142
                    "received size %zu):\n", frame_size, size);
1303
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1143
            ec_print_data(frame_data, size);
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1144
        }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1145
        master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1146
        ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1147
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1148
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1149
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1150
    cmd_follows = 1;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1151
    while (cmd_follows) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1152
        // process datagram header
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1153
        datagram_type  = EC_READ_U8 (cur_data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1154
        datagram_index = EC_READ_U8 (cur_data + 1);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1155
        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
  1156
        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
  1157
        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
  1158
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1159
        if (unlikely(cur_data - frame_data
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1160
                     + data_size + EC_DATAGRAM_FOOTER_SIZE > size)) {
1303
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1161
            if (master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1162
                EC_MASTER_DBG(master, 0, "Corrupted frame received"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1163
                        " (invalid data size %zu):\n", data_size);
1303
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1164
                ec_print_data(frame_data, size);
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1165
            }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1166
            master->stats.corrupted++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1167
            ec_master_output_stats(master);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1168
            return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1169
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1170
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1171
        // 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
  1172
        matched = 0;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1173
        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
  1174
            if (datagram->index == datagram_index
5e231f6a3d2e Re-ordered criteria for datagram matching.
Florian Pose <fp@igh-essen.com>
parents: 688
diff changeset
  1175
                && datagram->state == EC_DATAGRAM_SENT
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1176
                && datagram->type == datagram_type
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1177
                && 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
  1178
                matched = 1;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1179
                break;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1180
            }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1181
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1182
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1183
        // 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
  1184
        if (!matched) {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1185
            master->stats.unmatched++;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1186
            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
  1187
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1188
            if (unlikely(master->debug_level > 0)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1189
                EC_MASTER_DBG(master, 0, "UNMATCHED datagram:\n");
684
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1190
                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
  1191
                        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
  1192
                        + 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
  1193
#ifdef EC_DEBUG_RING
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1194
                ec_device_debug_ring_print(&master->devices[EC_DEVICE_MAIN]);
692
fe7cf37c33f1 Implemented debug frame ring to output the last n frames for debugging
Florian Pose <fp@igh-essen.com>
parents: 691
diff changeset
  1195
#endif
684
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1196
            }
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1197
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1198
            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
  1199
            continue;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1200
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1201
2114
b91bb9b96823 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
  1202
        if (datagram->type != EC_DATAGRAM_APWR &&
b91bb9b96823 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
  1203
                datagram->type != EC_DATAGRAM_FPWR &&
b91bb9b96823 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
  1204
                datagram->type != EC_DATAGRAM_BWR &&
b91bb9b96823 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
  1205
                datagram->type != EC_DATAGRAM_LWR) {
b91bb9b96823 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
  1206
            // copy received data into the datagram memory,
b91bb9b96823 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
  1207
            // if something has been read
b91bb9b96823 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
  1208
            memcpy(datagram->data, cur_data, data_size);
b91bb9b96823 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
  1209
        }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1210
        cur_data += data_size;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1211
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1212
        // set the datagram's working counter
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1213
        datagram->working_counter = EC_READ_U16(cur_data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1214
        cur_data += EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1215
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1216
        // 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
  1217
        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
  1218
#ifdef EC_HAVE_CYCLES
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1219
        datagram->cycles_received =
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1220
            master->devices[EC_DEVICE_MAIN].cycles_poll;
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1221
#endif
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1222
        datagram->jiffies_received =
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1223
            master->devices[EC_DEVICE_MAIN].jiffies_poll;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1224
        list_del_init(&datagram->queue);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1225
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1226
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1227
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1228
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1229
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
  1230
/** Output master statistics.
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1231
 *
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1232
 * 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
  1233
 * 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
  1234
 */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1235
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
  1236
{
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1237
    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
  1238
        master->stats.output_jiffies = jiffies;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1239
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1240
        if (master->stats.timeouts) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1241
            EC_MASTER_WARN(master, "%u datagram%s TIMED OUT!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1242
                    master->stats.timeouts,
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
  1243
                    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
  1244
            master->stats.timeouts = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1245
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1246
        if (master->stats.corrupted) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1247
            EC_MASTER_WARN(master, "%u frame%s CORRUPTED!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1248
                    master->stats.corrupted,
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
  1249
                    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
  1250
            master->stats.corrupted = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1251
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1252
        if (master->stats.unmatched) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1253
            EC_MASTER_WARN(master, "%u datagram%s UNMATCHED!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1254
                    master->stats.unmatched,
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
  1255
                    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
  1256
            master->stats.unmatched = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1257
        }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1258
    }
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1259
}
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1260
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1261
/*****************************************************************************/
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1262
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1263
/** Clears the common device statistics.
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1264
 */
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1265
void ec_master_clear_device_stats(
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1266
        ec_master_t *master /**< EtherCAT master */
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1267
        )
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1268
{
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1269
    unsigned int i;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1270
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1271
    // zero frame statistics
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1272
    master->device_stats.tx_count = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1273
    master->device_stats.last_tx_count = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1274
    master->device_stats.rx_count = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1275
    master->device_stats.last_rx_count = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1276
    master->device_stats.tx_bytes = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1277
    master->device_stats.last_tx_bytes = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1278
    master->device_stats.rx_bytes = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1279
    master->device_stats.last_rx_bytes = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1280
    master->device_stats.last_loss = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1281
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1282
    for (i = 0; i < EC_RATE_COUNT; i++) {
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1283
        master->device_stats.tx_frame_rates[i] = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1284
        master->device_stats.tx_byte_rates[i] = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1285
        master->device_stats.loss_rates[i] = 0;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1286
    }
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1287
}
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1288
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1289
/*****************************************************************************/
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1290
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1291
/** Updates the common device statistics.
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1292
 */
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1293
void ec_master_update_device_stats(
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1294
        ec_master_t *master /**< EtherCAT master */
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1295
        )
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1296
{
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1297
    ec_device_stats_t *s = &master->device_stats;
2372
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1298
    s32 tx_frame_rate, rx_frame_rate, tx_byte_rate, rx_byte_rate, loss_rate;
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1299
    u64 loss;
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  1300
    unsigned int i, dev_idx;
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1301
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1302
    // frame statistics
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1303
    if (likely(jiffies - s->jiffies < HZ)) {
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1304
        return;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1305
    }
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1306
2372
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1307
    tx_frame_rate = (s->tx_count - s->last_tx_count) * 1000;
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1308
    rx_frame_rate = (s->rx_count - s->last_rx_count) * 1000;
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1309
    tx_byte_rate = s->tx_bytes - s->last_tx_bytes;
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1310
    rx_byte_rate = s->rx_bytes - s->last_rx_bytes;
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1311
    loss = s->tx_count - s->rx_count;
2372
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1312
    loss_rate = (loss - s->last_loss) * 1000;
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1313
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1314
    /* Low-pass filter:
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1315
     *      Y_n = y_(n - 1) + T / tau * (x - y_(n - 1))   | T = 1
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1316
     *   -> Y_n += (x - y_(n - 1)) / tau
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1317
     */
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1318
    for (i = 0; i < EC_RATE_COUNT; i++) {
2372
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1319
        s32 n = rate_intervals[i];
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1320
        s->tx_frame_rates[i] += (tx_frame_rate - s->tx_frame_rates[i]) / n;
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1321
        s->rx_frame_rates[i] += (rx_frame_rate - s->rx_frame_rates[i]) / n;
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1322
        s->tx_byte_rates[i] += (tx_byte_rate - s->tx_byte_rates[i]) / n;
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1323
        s->rx_byte_rates[i] += (rx_byte_rate - s->rx_byte_rates[i]) / n;
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1324
        s->loss_rates[i] += (loss_rate - s->loss_rates[i]) / n;
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1325
    }
d895cd1db2bf Improved/fixed frame statistics (low-pass filters).
Florian Pose <fp@igh-essen.com>
parents: 2371
diff changeset
  1326
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1327
    s->last_tx_count = s->tx_count;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1328
    s->last_rx_count = s->rx_count;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1329
    s->last_tx_bytes = s->tx_bytes;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1330
    s->last_rx_bytes = s->rx_bytes;
2371
a5052376202b Fixed frame loss statistics.
Florian Pose <fp@igh-essen.com>
parents: 2370
diff changeset
  1331
    s->last_loss = loss;
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1332
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  1333
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  1334
            dev_idx++) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  1335
        ec_device_update_stats(&master->devices[dev_idx]);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  1336
    }
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1337
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1338
    s->jiffies = jiffies;
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  1339
}
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1340
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1341
/*****************************************************************************/
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1342
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1343
#ifdef EC_USE_HRTIMER
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1344
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1345
/*
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1346
 * Sleep related functions:
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1347
 */
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1348
static enum hrtimer_restart ec_master_nanosleep_wakeup(struct hrtimer *timer)
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1349
{
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1350
    struct hrtimer_sleeper *t =
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1351
        container_of(timer, struct hrtimer_sleeper, timer);
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1352
    struct task_struct *task = t->task;
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1353
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1354
    t->task = NULL;
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1355
    if (task)
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1356
        wake_up_process(task);
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1357
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1358
    return HRTIMER_NORESTART;
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1359
}
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1360
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1361
/*****************************************************************************/
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1362
1603
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1363
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1364
1603
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1365
/* compatibility with new hrtimer interface */
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1366
static inline ktime_t hrtimer_get_expires(const struct hrtimer *timer)
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1367
{
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1368
    return timer->expires;
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1369
}
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1370
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1371
/*****************************************************************************/
1603
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1372
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1373
static inline void hrtimer_set_expires(struct hrtimer *timer, ktime_t time)
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1374
{
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1375
    timer->expires = time;
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1376
}
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1377
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1378
#endif
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1379
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1380
/*****************************************************************************/
1603
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1381
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1382
void ec_master_nanosleep(const unsigned long nsecs)
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1383
{
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1384
    struct hrtimer_sleeper t;
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1385
    enum hrtimer_mode mode = HRTIMER_MODE_REL;
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1386
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1387
    hrtimer_init(&t.timer, CLOCK_MONOTONIC, mode);
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1388
    t.timer.function = ec_master_nanosleep_wakeup;
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1389
    t.task = current;
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1390
#ifdef CONFIG_HIGH_RES_TIMERS
1603
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1391
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 24)
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1392
    t.timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_RESTART;
1603
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1393
#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 26)
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1394
    t.timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ;
1603
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1395
#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 28)
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1396
    t.timer.cb_mode = HRTIMER_CB_IRQSAFE_UNLOCKED;
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1397
#endif
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1398
#endif
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1399
    hrtimer_set_expires(&t.timer, ktime_set(0, nsecs));
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1400
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1401
    do {
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1402
        set_current_state(TASK_INTERRUPTIBLE);
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1403
        hrtimer_start(&t.timer, hrtimer_get_expires(&t.timer), mode);
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1404
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1405
        if (likely(t.task))
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1406
            schedule();
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1407
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1408
        hrtimer_cancel(&t.timer);
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1409
        mode = HRTIMER_MODE_ABS;
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1410
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1411
    } while (t.task && !signal_pending(current));
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1412
}
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1413
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1414
#endif // EC_USE_HRTIMER
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1415
68
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
  1416
/*****************************************************************************/
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
  1417
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1418
/** Execute slave FSMs.
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1419
 */
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1420
void ec_master_exec_slave_fsms(
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1421
        ec_master_t *master /**< EtherCAT master. */
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1422
        )
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1423
{
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1424
    ec_datagram_t *datagram;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1425
    ec_fsm_slave_t *fsm, *next;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1426
    unsigned int count = 0;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1427
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1428
    list_for_each_entry_safe(fsm, next, &master->fsm_exec_list, list) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1429
        if (!fsm->datagram) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1430
            EC_MASTER_WARN(master, "Slave %u FSM has zero datagram."
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1431
                    "This is a bug!\n", fsm->slave->ring_position);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1432
            list_del_init(&fsm->list);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1433
            master->fsm_exec_count--;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1434
            return;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1435
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1436
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1437
        if (fsm->datagram->state == EC_DATAGRAM_INIT ||
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1438
                fsm->datagram->state == EC_DATAGRAM_QUEUED ||
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1439
                fsm->datagram->state == EC_DATAGRAM_SENT) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1440
            // previous datagram was not sent or received yet.
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1441
            // wait until next thread execution
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1442
            return;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1443
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1444
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1445
        datagram = ec_master_get_external_datagram(master);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1446
        if (!datagram) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1447
            // no free datagrams at the moment
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1448
            EC_MASTER_WARN(master, "No free datagram during"
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1449
                    " slave FSM execution. This is a bug!\n");
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1450
            continue;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1451
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1452
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1453
#if DEBUG_INJECT
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1454
        EC_MASTER_DBG(master, 1, "Executing slave %u FSM.\n",
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1455
                fsm->slave->ring_position);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1456
#endif
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1457
        if (ec_fsm_slave_exec(fsm, datagram)) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1458
            // FSM consumed datagram
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1459
#if DEBUG_INJECT
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1460
            EC_MASTER_DBG(master, 1, "FSM consumed datagram %s\n",
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1461
                    datagram->name);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1462
#endif
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1463
            master->ext_ring_idx_fsm =
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1464
                (master->ext_ring_idx_fsm + 1) % EC_EXT_RING_SIZE;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1465
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1466
        else {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1467
            // FSM finished
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1468
            list_del_init(&fsm->list);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1469
            master->fsm_exec_count--;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1470
#if DEBUG_INJECT
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1471
            EC_MASTER_DBG(master, 1, "FSM finished. %u remaining.\n",
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1472
                    master->fsm_exec_count);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1473
#endif
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1474
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1475
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1476
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1477
    while (master->fsm_exec_count < EC_EXT_RING_SIZE / 2
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1478
            && count < master->slave_count) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1479
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1480
        if (ec_fsm_slave_is_ready(&master->fsm_slave->fsm)) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1481
            datagram = ec_master_get_external_datagram(master);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1482
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1483
            if (ec_fsm_slave_exec(&master->fsm_slave->fsm, datagram)) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1484
                master->ext_ring_idx_fsm =
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1485
                    (master->ext_ring_idx_fsm + 1) % EC_EXT_RING_SIZE;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1486
                list_add_tail(&master->fsm_slave->fsm.list,
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1487
                        &master->fsm_exec_list);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1488
                master->fsm_exec_count++;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1489
#if DEBUG_INJECT
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1490
                EC_MASTER_DBG(master, 1, "New slave %u FSM"
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1491
                        " consumed datagram %s, now %u FSMs in list.\n",
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1492
                        master->fsm_slave->ring_position, datagram->name,
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1493
                        master->fsm_exec_count);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1494
#endif
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1495
            }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1496
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1497
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1498
        master->fsm_slave++;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1499
        if (master->fsm_slave >= master->slaves + master->slave_count) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1500
            master->fsm_slave = master->slaves;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1501
        }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1502
        count++;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1503
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1504
}
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1505
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1506
/*****************************************************************************/
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1507
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
  1508
/** 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
  1509
 */
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1510
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
  1511
{
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1512
    ec_master_t *master = (ec_master_t *) priv_data;
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1513
    int fsm_exec;
2336
dc82f7d09767 Avoided unused variable warnings.
Florian Pose <fp@igh-essen.com>
parents: 2305
diff changeset
  1514
#ifdef EC_USE_HRTIMER
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1515
    size_t sent_bytes;
2336
dc82f7d09767 Avoided unused variable warnings.
Florian Pose <fp@igh-essen.com>
parents: 2305
diff changeset
  1516
#endif
1774
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
  1517
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
  1518
    // send interval in IDLE phase
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
  1519
    ec_master_set_send_interval(master, 1000000 / HZ);
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1520
1930
59a50053ccc6 Made send_interval variable an unsigned int; fixed format specifiers for
Florian Pose <fp@igh-essen.com>
parents: 1925
diff changeset
  1521
    EC_MASTER_DBG(master, 1, "Idle thread running with send interval = %u us,"
59a50053ccc6 Made send_interval variable an unsigned int; fixed format specifiers for
Florian Pose <fp@igh-essen.com>
parents: 1925
diff changeset
  1522
            " max data size=%zu\n", master->send_interval,
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1523
            master->max_queue_size);
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1524
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1525
    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
  1526
        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
  1527
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1528
        // receive
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1529
        down(&master->io_sem);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1530
        ecrt_master_receive(master);
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1531
        up(&master->io_sem);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1532
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1533
        // execute master & slave state machines
2455
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  1534
        if (down_interruptible(&master->master_sem)) {
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1535
            break;
2455
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  1536
        }
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  1537
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1538
        fsm_exec = ec_fsm_master_exec(&master->fsm);
2455
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  1539
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1540
        ec_master_exec_slave_fsms(master);
2455
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  1541
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
  1542
        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
  1543
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1544
        // queue and send
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1545
        down(&master->io_sem);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1546
        if (fsm_exec) {
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  1547
            ec_master_queue_datagram(master, &master->fsm_datagram);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1548
        }
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1549
        ecrt_master_send(master);
2336
dc82f7d09767 Avoided unused variable warnings.
Florian Pose <fp@igh-essen.com>
parents: 2305
diff changeset
  1550
#ifdef EC_USE_HRTIMER
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1551
        sent_bytes = master->devices[EC_DEVICE_MAIN].tx_skb[
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  1552
            master->devices[EC_DEVICE_MAIN].tx_ring_index]->len;
2336
dc82f7d09767 Avoided unused variable warnings.
Florian Pose <fp@igh-essen.com>
parents: 2305
diff changeset
  1553
#endif
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1554
        up(&master->io_sem);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1555
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1556
        if (ec_fsm_master_idle(&master->fsm)) {
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1557
#ifdef EC_USE_HRTIMER
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1558
            ec_master_nanosleep(master->send_interval * 1000);
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1559
#else
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1560
            set_current_state(TASK_INTERRUPTIBLE);
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1561
            schedule_timeout(1);
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1562
#endif
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1563
        } else {
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1564
#ifdef EC_USE_HRTIMER
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1565
            ec_master_nanosleep(sent_bytes * EC_BYTE_TRANSMISSION_TIME_NS);
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1566
#else
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1567
            schedule();
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1568
#endif
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1569
        }
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
  1570
    }
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
  1571
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1572
    EC_MASTER_DBG(master, 1, "Master IDLE thread exiting...\n");
1774
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
  1573
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1574
    return 0;
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1575
}
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1576
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1577
/*****************************************************************************/
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1578
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1579
/** Master kernel thread function for OPERATION phase.
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1580
 */
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1581
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
  1582
{
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1583
    ec_master_t *master = (ec_master_t *) priv_data;
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1584
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1585
    EC_MASTER_DBG(master, 1, "Operation thread running"
1930
59a50053ccc6 Made send_interval variable an unsigned int; fixed format specifiers for
Florian Pose <fp@igh-essen.com>
parents: 1925
diff changeset
  1586
            " with fsm interval = %u us, max data size=%zu\n",
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1587
            master->send_interval, master->max_queue_size);
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1588
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1589
    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
  1590
        ec_datagram_output_stats(&master->fsm_datagram);
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1591
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1592
        if (master->injection_seq_rt == master->injection_seq_fsm) {
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1593
            // output statistics
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1594
            ec_master_output_stats(master);
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1595
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1596
            // execute master & slave state machines
2455
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  1597
            if (down_interruptible(&master->master_sem)) {
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1598
                break;
2455
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  1599
            }
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  1600
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1601
            if (ec_fsm_master_exec(&master->fsm)) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1602
                // Inject datagrams (let the RT thread queue them, see
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1603
                // ecrt_master_send())
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1604
                master->injection_seq_fsm++;
2455
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  1605
            }
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1606
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1607
            ec_master_exec_slave_fsms(master);
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1608
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  1609
            up(&master->master_sem);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1580
diff changeset
  1610
        }
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1611
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1612
#ifdef EC_USE_HRTIMER
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1613
        // the op thread should not work faster than the sending RT thread
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1614
        ec_master_nanosleep(master->send_interval * 1000);
1773
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1615
#else
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1616
        if (ec_fsm_master_idle(&master->fsm)) {
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1617
            set_current_state(TASK_INTERRUPTIBLE);
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1618
            schedule_timeout(1);
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1619
        }
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1620
        else {
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1621
            schedule();
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1622
        }
5371f3e5f6a1 Disable use of hrtimer for scheduling by default. Does not work on some PPC targets.
Florian Pose <fp@igh-essen.com>
parents: 1611
diff changeset
  1623
#endif
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1624
    }
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
  1625
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1626
    EC_MASTER_DBG(master, 1, "Master OP thread exiting...\n");
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1627
    return 0;
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1628
}
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1629
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1630
/*****************************************************************************/
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1631
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1632
#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
  1633
/** 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
  1634
 */
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1635
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
  1636
{
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1637
    struct sched_param param = { .sched_priority = 0 };
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1638
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1639
    if (master->eoe_thread) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1640
        EC_MASTER_WARN(master, "EoE already running!\n");
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1641
        return;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1642
    }
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1643
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1644
    if (list_empty(&master->eoe_handlers))
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1645
        return;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
  1646
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  1647
    if (!master->send_cb || !master->receive_cb) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1648
        EC_MASTER_WARN(master, "No EoE processing"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1649
                " because of missing callbacks!\n");
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1650
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1651
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1652
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1653
    EC_MASTER_INFO(master, "Starting EoE thread.\n");
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1654
    master->eoe_thread = kthread_run(ec_master_eoe_thread, master,
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1655
            "EtherCAT-EoE");
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1656
    if (IS_ERR(master->eoe_thread)) {
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1657
        int err = (int) PTR_ERR(master->eoe_thread);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1658
        EC_MASTER_ERR(master, "Failed to start EoE thread (error %i)!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1659
                err);
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1660
        master->eoe_thread = NULL;
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1661
        return;
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1662
    }
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1663
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1664
    sched_setscheduler(master->eoe_thread, SCHED_NORMAL, &param);
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1665
    set_user_nice(master->eoe_thread, 0);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1666
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1667
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1668
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1669
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1670
/** 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
  1671
 */
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1672
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
  1673
{
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1674
    if (master->eoe_thread) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1675
        EC_MASTER_INFO(master, "Stopping EoE thread.\n");
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1676
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1677
        kthread_stop(master->eoe_thread);
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1678
        master->eoe_thread = NULL;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1679
        EC_MASTER_INFO(master, "EoE thread exited.\n");
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1680
    }
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1681
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1682
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1683
/*****************************************************************************/
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1684
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1685
/** 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
  1686
 */
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1687
static int ec_master_eoe_thread(void *priv_data)
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1688
{
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1689
    ec_master_t *master = (ec_master_t *) priv_data;
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1690
    ec_eoe_t *eoe;
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1691
    unsigned int none_open, sth_to_send, all_idle;
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1692
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1693
    EC_MASTER_DBG(master, 1, "EoE thread running.\n");
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1694
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1695
    while (!kthread_should_stop()) {
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1696
        none_open = 1;
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1697
        all_idle = 1;
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1698
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1699
        list_for_each_entry(eoe, &master->eoe_handlers, list) {
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1700
            if (ec_eoe_is_open(eoe)) {
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1701
                none_open = 0;
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1702
                break;
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1703
            }
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1704
        }
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1705
        if (none_open)
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1706
            goto schedule;
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1707
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1708
        // receive datagrams
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1709
        master->receive_cb(master->cb_data);
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1710
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1711
        // actual EoE processing
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1712
        sth_to_send = 0;
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1713
        list_for_each_entry(eoe, &master->eoe_handlers, list) {
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1714
            ec_eoe_run(eoe);
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1715
            if (eoe->queue_datagram) {
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1716
                sth_to_send = 1;
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1717
            }
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1718
            if (!ec_eoe_is_idle(eoe)) {
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1719
                all_idle = 0;
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1720
            }
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1721
        }
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1722
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1723
        if (sth_to_send) {
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1724
            list_for_each_entry(eoe, &master->eoe_handlers, list) {
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1725
                ec_eoe_queue(eoe);
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1726
            }
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  1727
            // (try to) send datagrams
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  1728
            down(&master->ext_queue_sem);
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1729
            master->send_cb(master->cb_data);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  1730
            up(&master->ext_queue_sem);
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1731
        }
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1732
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1733
schedule:
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1734
        if (all_idle) {
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1735
            set_current_state(TASK_INTERRUPTIBLE);
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1736
            schedule_timeout(1);
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1737
        } else {
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1738
            schedule();
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1739
        }
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1740
    }
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
  1741
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1742
    EC_MASTER_DBG(master, 1, "EoE thread exiting...\n");
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1743
    return 0;
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1744
}
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1745
#endif
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1746
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1747
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  1748
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1749
/** 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
  1750
 */
1028
afdd4bdbb7ec Removed configs_attached flag; changed return value of
Florian Pose <fp@igh-essen.com>
parents: 1024
diff changeset
  1751
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
  1752
        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
  1753
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1754
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1755
    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
  1756
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1757
    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
  1758
        ec_slave_config_attach(sc);
afdd4bdbb7ec Removed configs_attached flag; changed return value of
Florian Pose <fp@igh-essen.com>
parents: 1024
diff changeset
  1759
    }
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1760
}
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1761
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1762
/*****************************************************************************/
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1763
1077
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1764
/** Common implementation for ec_master_find_slave()
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1765
 * and ec_master_find_slave_const().
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1766
 */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1767
#define EC_FIND_SLAVE \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1768
    do { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1769
        if (alias) { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1770
            for (; slave < master->slaves + master->slave_count; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1771
                    slave++) { \
1909
ea3eb4c74c1b Introduced effective_alias variable to separate reg12 alias from SII alias.
Florian Pose <fp@igh-essen.com>
parents: 1906
diff changeset
  1772
                if (slave->effective_alias == alias) \
1077
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1773
                break; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1774
            } \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1775
            if (slave == master->slaves + master->slave_count) \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1776
            return NULL; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1777
        } \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1778
        \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1779
        slave += position; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1780
        if (slave < master->slaves + master->slave_count) { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1781
            return slave; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1782
        } else { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1783
            return NULL; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1784
        } \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1785
    } while (0)
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1786
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1787
/** Finds a slave in the bus, given the alias and position.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  1788
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  1789
 * \return Search result, or NULL.
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1790
 */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1791
ec_slave_t *ec_master_find_slave(
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1792
        ec_master_t *master, /**< EtherCAT master. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1793
        uint16_t alias, /**< Slave alias. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1794
        uint16_t position /**< Slave position. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1795
        )
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1796
{
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
  1797
    ec_slave_t *slave = master->slaves;
1077
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1798
    EC_FIND_SLAVE;
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1799
}
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1800
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1801
/** 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
  1802
 *
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1803
 * Const version.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  1804
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  1805
 * \return Search result, or NULL.
1077
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1806
 */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1807
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
  1808
        const ec_master_t *master, /**< EtherCAT master. */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1809
        uint16_t alias, /**< Slave alias. */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1810
        uint16_t position /**< Slave position. */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1811
        )
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1812
{
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1813
    const ec_slave_t *slave = master->slaves;
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1814
    EC_FIND_SLAVE;
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1815
}
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1816
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1817
/*****************************************************************************/
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1818
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1819
/** 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
  1820
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1821
 * \return Number of configurations.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1822
 */
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1823
unsigned int ec_master_config_count(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1824
        const ec_master_t *master /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1825
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1826
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1827
    const ec_slave_config_t *sc;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1828
    unsigned int count = 0;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1829
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1830
    list_for_each_entry(sc, &master->configs, list) {
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1831
        count++;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1832
    }
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1833
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1834
    return count;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1835
}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1836
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1837
/*****************************************************************************/
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1838
1252
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1839
/** Common implementation for ec_master_get_config()
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1840
 * and ec_master_get_config_const().
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1841
 */
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1842
#define EC_FIND_CONFIG \
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1843
    do { \
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1844
        list_for_each_entry(sc, &master->configs, list) { \
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1845
            if (pos--) \
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1846
                continue; \
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1847
            return sc; \
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1848
        } \
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1849
        return NULL; \
1252
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1850
    } while (0)
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1851
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1852
/** 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
  1853
 *
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1854
 * \return Slave configuration or \a NULL.
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1855
 */
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1856
ec_slave_config_t *ec_master_get_config(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1857
        const ec_master_t *master, /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1858
        unsigned int pos /**< List position. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1859
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1860
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1861
    ec_slave_config_t *sc;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1862
    EC_FIND_CONFIG;
1252
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1863
}
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1864
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1865
/** 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
  1866
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1867
 * Const version.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1868
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1869
 * \return Slave configuration or \a NULL.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1870
 */
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1871
const ec_slave_config_t *ec_master_get_config_const(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1872
        const ec_master_t *master, /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1873
        unsigned int pos /**< List position. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1874
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1875
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1876
    const ec_slave_config_t *sc;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1877
    EC_FIND_CONFIG;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1878
}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1879
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1880
/*****************************************************************************/
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1881
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1882
/** Get the number of domains.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1883
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1884
 * \return Number of domains.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1885
 */
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1886
unsigned int ec_master_domain_count(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1887
        const ec_master_t *master /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1888
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1889
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1890
    const ec_domain_t *domain;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1891
    unsigned int count = 0;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1892
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1893
    list_for_each_entry(domain, &master->domains, list) {
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1894
        count++;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1895
    }
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1896
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1897
    return count;
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1898
}
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1899
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1900
/*****************************************************************************/
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1901
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1902
/** 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
  1903
 * 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
  1904
 */
1078
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1905
#define EC_FIND_DOMAIN \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1906
    do { \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1907
        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
  1908
            if (index--) \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1909
                continue; \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1910
            return domain; \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1911
        } \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1912
        \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1913
        return NULL; \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1914
    } while (0)
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1915
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1916
/** Get a domain via its position in the list.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1917
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1918
 * \return Domain pointer, or \a NULL if not found.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1919
 */
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1920
ec_domain_t *ec_master_find_domain(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1921
        ec_master_t *master, /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1922
        unsigned int index /**< Domain index. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1923
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1924
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1925
    ec_domain_t *domain;
1078
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1926
    EC_FIND_DOMAIN;
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1927
}
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1928
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1929
/** Get a domain via its position in the list.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1930
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1931
 * Const version.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1932
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1933
 * \return Domain pointer, or \a NULL if not found.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1934
 */
1078
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1935
const ec_domain_t *ec_master_find_domain_const(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1936
        const ec_master_t *master, /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1937
        unsigned int index /**< Domain index. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1938
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1939
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1940
    const ec_domain_t *domain;
1078
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1941
    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
  1942
}
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1943
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1944
/*****************************************************************************/
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1945
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  1946
#ifdef EC_EOE
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  1947
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1948
/** Get the number of EoE handlers.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1949
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1950
 * \return Number of EoE handlers.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1951
 */
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1952
uint16_t ec_master_eoe_handler_count(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1953
        const ec_master_t *master /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1954
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1955
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1956
    const ec_eoe_t *eoe;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1957
    unsigned int count = 0;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1958
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1959
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1960
        count++;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1961
    }
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1962
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1963
    return count;
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1964
}
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1965
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1966
/*****************************************************************************/
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1967
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1968
/** Get an EoE handler via its position in the list.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1969
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1970
 * Const version.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1971
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1972
 * \return EoE handler pointer, or \a NULL if not found.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1973
 */
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1974
const ec_eoe_t *ec_master_get_eoe_handler_const(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1975
        const ec_master_t *master, /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1976
        uint16_t index /**< EoE handler index. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1977
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1978
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1979
    const ec_eoe_t *eoe;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1980
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1981
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1982
        if (index--)
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1983
            continue;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1984
        return eoe;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1985
    }
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1986
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1987
    return NULL;
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1988
}
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1989
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  1990
#endif
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  1991
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1992
/*****************************************************************************/
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1993
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1994
/** Set the debug level.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1995
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1996
 * \retval       0 Success.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1997
 * \retval -EINVAL Invalid debug level.
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1998
 */
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1999
int ec_master_debug_level(
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  2000
        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
  2001
        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
  2002
        )
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2003
{
1399
f79d4bb5b23a Added debug_level module parameter. debug_level is now unsigned int.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
  2004
    if (level > 2) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2005
        EC_MASTER_ERR(master, "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
  2006
        return -EINVAL;
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2007
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2008
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2009
    if (level != master->debug_level) {
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2010
        master->debug_level = level;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2011
        EC_MASTER_INFO(master, "Master debug level set to %u.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2012
                master->debug_level);
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2013
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2014
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2015
    return 0;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2016
}
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2017
1408
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2018
/*****************************************************************************/
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2019
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2020
/** Finds the DC reference clock.
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2021
 */
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2022
void ec_master_find_dc_ref_clock(
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2023
        ec_master_t *master /**< EtherCAT master. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2024
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2025
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2026
    ec_slave_t *slave, *ref = NULL;
1408
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2027
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2028
    if (master->dc_ref_config) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2029
        // Use application-selected reference clock
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2030
        slave = master->dc_ref_config->slave;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2031
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2032
        if (slave) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2033
            if (slave->base_dc_supported && slave->has_dc_system_time) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2034
                ref = slave;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2035
            }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2036
            else {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2037
                EC_MASTER_WARN(master, "Slave %u can not act as a"
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2038
                        " DC reference clock!", slave->ring_position);
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2039
            }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2040
        }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2041
        else {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2042
            EC_MASTER_WARN(master, "DC reference clock config (%u-%u)"
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2043
                    " has no slave attached!\n", master->dc_ref_config->alias,
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2044
                    master->dc_ref_config->position);
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2045
        }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2046
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2047
    else {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2048
        // Use first slave with DC support as reference clock
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2049
        for (slave = master->slaves;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2050
                slave < master->slaves + master->slave_count;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2051
                slave++) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2052
            if (slave->base_dc_supported && slave->has_dc_system_time) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2053
                ref = slave;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2054
                break;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2055
            }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2056
        }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2057
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2058
    }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2059
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2060
    master->dc_ref_clock = ref;
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
  2061
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2062
    if (ref) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2063
        EC_MASTER_INFO(master, "Using slave %u as DC reference clock.\n",
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2064
                ref->ring_position);
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2065
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2066
    else {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2067
        EC_MASTER_INFO(master, "No DC reference clock found.\n");
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2068
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2069
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2070
    // These calls always succeed, because the
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2071
    // datagrams have been pre-allocated.
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2072
    ec_datagram_fpwr(&master->ref_sync_datagram,
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2073
            ref ? ref->station_address : 0xffff, 0x0910, 4);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2074
    ec_datagram_frmw(&master->sync_datagram,
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2075
            ref ? ref->station_address : 0xffff, 0x0910, 4);
1408
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2076
}
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2077
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2078
/*****************************************************************************/
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2079
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2080
/** Calculates the bus topology; recursion function.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2081
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2082
 * \return Zero on success, otherwise a negative error code.
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2083
 */
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2084
int ec_master_calc_topology_rec(
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2085
        ec_master_t *master, /**< EtherCAT master. */
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2086
        ec_slave_t *port0_slave, /**< Slave at port 0. */
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2087
        unsigned int *slave_position /**< Slave position. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2088
        )
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2089
{
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2090
    ec_slave_t *slave = master->slaves + *slave_position;
2360
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2091
    unsigned int port_index;
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2092
    int ret;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2093
2360
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2094
    static const unsigned int next_table[EC_MAX_PORTS] = {
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2095
        3, 2, 0, 1
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2096
    };
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2097
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2098
    slave->ports[0].next_slave = port0_slave;
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2099
2360
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2100
    port_index = 3;
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2101
    while (port_index != 0) {
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2102
        if (!slave->ports[port_index].link.loop_closed) {
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2103
            *slave_position = *slave_position + 1;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2104
            if (*slave_position < master->slave_count) {
2360
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2105
                slave->ports[port_index].next_slave =
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2106
                    master->slaves + *slave_position;
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2107
                ret = ec_master_calc_topology_rec(master,
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2108
                        slave, slave_position);
2360
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2109
                if (ret) {
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2110
                    return ret;
2360
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2111
                }
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2112
            } else {
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2113
                return -1;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2114
            }
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2115
        }
2360
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2116
622a7faa07df Added fix for ESC port order (DC delay calculation).
Florian Pose <fp@igh-essen.com>
parents: 2349
diff changeset
  2117
        port_index = next_table[port_index];
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2118
    }
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2119
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2120
    return 0;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2121
}
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2122
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2123
/*****************************************************************************/
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2124
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2125
/** Calculates the bus topology.
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2126
 */
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2127
void ec_master_calc_topology(
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2128
        ec_master_t *master /**< EtherCAT master. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2129
        )
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2130
{
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2131
    unsigned int slave_position = 0;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2132
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2133
    if (master->slave_count == 0)
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2134
        return;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2135
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2136
    if (ec_master_calc_topology_rec(master, NULL, &slave_position))
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2137
        EC_MASTER_ERR(master, "Failed to calculate bus topology.\n");
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2138
}
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2139
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2140
/*****************************************************************************/
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2141
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  2142
/** Calculates the bus transmission delays.
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  2143
 */
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  2144
void ec_master_calc_transmission_delays(
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2145
        ec_master_t *master /**< EtherCAT master. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2146
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2147
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2148
    ec_slave_t *slave;
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2149
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2150
    for (slave = master->slaves;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2151
            slave < master->slaves + master->slave_count;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2152
            slave++) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2153
        ec_slave_calc_port_delays(slave);
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2154
    }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2155
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2156
    if (master->dc_ref_clock) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2157
        uint32_t delay = 0;
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  2158
        ec_slave_calc_transmission_delays_rec(master->dc_ref_clock, &delay);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2159
    }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2160
}
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2161
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2162
/*****************************************************************************/
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2163
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2164
/** Distributed-clocks calculations.
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2165
 */
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2166
void ec_master_calc_dc(
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2167
        ec_master_t *master /**< EtherCAT master. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2168
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2169
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2170
    // find DC reference clock
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2171
    ec_master_find_dc_ref_clock(master);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2172
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2173
    // calculate bus topology
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2174
    ec_master_calc_topology(master);
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2175
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  2176
    ec_master_calc_transmission_delays(master);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2177
}
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2178
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2179
/*****************************************************************************/
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2180
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2181
/** Request OP state for configured slaves.
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2182
 */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2183
void ec_master_request_op(
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2184
        ec_master_t *master /**< EtherCAT master. */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2185
        )
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2186
{
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2187
    unsigned int i;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2188
    ec_slave_t *slave;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2189
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2190
    if (!master->active)
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2191
        return;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2192
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2193
    EC_MASTER_DBG(master, 1, "Requesting OP...\n");
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2194
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2195
    // request OP for all configured slaves
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2196
    for (i = 0; i < master->slave_count; i++) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2197
        slave = master->slaves + i;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2198
        if (slave->config) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2199
            ec_slave_request_state(slave, EC_SLAVE_STATE_OP);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2200
        }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2201
    }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2202
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2203
    // always set DC reference clock to OP
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2204
    if (master->dc_ref_clock) {
2476
9a0d30056e70 Send sync datagrams only if reference clock is found.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2205
        ec_slave_request_state(master->dc_ref_clock, EC_SLAVE_STATE_OP);
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2206
    }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2207
}
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2208
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
  2209
/******************************************************************************
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  2210
 *  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
  2211
 *****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2212
1332
d62633fea8ed merge -c1610 branches/stable-1.4: Added missing doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 1329
diff changeset
  2213
/** Same as ecrt_master_create_domain(), but with ERR_PTR() return value.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2214
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2215
 * \return New domain, or ERR_PTR() return value.
1332
d62633fea8ed merge -c1610 branches/stable-1.4: Added missing doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 1329
diff changeset
  2216
 */
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2217
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
  2218
        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
  2219
        )
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
  2220
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2221
    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
  2222
    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
  2223
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2224
    EC_MASTER_DBG(master, 1, "ecrt_master_create_domain(master = 0x%p)\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2225
            master);
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  2226
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  2227
    if (!(domain =
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  2228
                (ec_domain_t *) kmalloc(sizeof(ec_domain_t), GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2229
        EC_MASTER_ERR(master, "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
  2230
        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
  2231
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2232
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
  2233
    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
  2234
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  2235
    if (list_empty(&master->domains)) {
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  2236
        index = 0;
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  2237
    } 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
  2238
        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
  2239
        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
  2240
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2241
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  2242
    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
  2243
    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
  2244
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
  2245
    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
  2246
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2247
    EC_MASTER_DBG(master, 1, "Created domain %u.\n", domain->index);
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  2248
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
  2249
    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
  2250
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2251
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2252
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2253
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2254
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
  2255
        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
  2256
        )
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2257
{
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2258
    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
  2259
    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
  2260
}
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2261
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2262
/*****************************************************************************/
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2263
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2264
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
  2265
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2266
    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
  2267
    ec_domain_t *domain;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2268
    int ret;
1914
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2269
#ifdef EC_EOE
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2270
    int eoe_was_running;
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2271
#endif
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
  2272
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2273
    EC_MASTER_DBG(master, 1, "ecrt_master_activate(master = 0x%p)\n", master);
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  2274
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2275
    if (master->active) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2276
        EC_MASTER_WARN(master, "%s: Master already active!\n", __func__);
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2277
        return 0;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2278
    }
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2279
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
  2280
    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
  2281
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2282
    // 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
  2283
    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
  2284
    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
  2285
        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
  2286
        if (ret < 0) {
1197
f65f9c36ba33 Fixed missing up().
Florian Pose <fp@igh-essen.com>
parents: 1181
diff changeset
  2287
            up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2288
            EC_MASTER_ERR(master, "Failed to finish domain 0x%p!\n", domain);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2289
            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
  2290
        }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2291
        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
  2292
    }
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
  2293
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
  2294
    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
  2295
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  2296
    // restart EoE process and master thread with new locking
1914
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2297
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2298
    ec_master_thread_stop(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  2299
#ifdef EC_EOE
1914
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2300
    eoe_was_running = master->eoe_thread != NULL;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  2301
    ec_master_eoe_stop(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  2302
#endif
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  2303
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2304
    EC_MASTER_DBG(master, 1, "FSM datagram is %p.\n", &master->fsm_datagram);
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
  2305
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  2306
    master->injection_seq_fsm = 0;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  2307
    master->injection_seq_rt = 0;
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2308
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2309
    master->send_cb = master->app_send_cb;
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2310
    master->receive_cb = master->app_receive_cb;
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2311
    master->cb_data = master->app_cb_data;
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
  2312
1914
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2313
#ifdef EC_EOE
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2314
    if (eoe_was_running) {
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2315
        ec_master_eoe_start(master);
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2316
    }
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2317
#endif
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2318
    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
  2319
                "EtherCAT-OP");
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2320
    if (ret < 0) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2321
        EC_MASTER_ERR(master, "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
  2322
        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
  2323
    }
902
ad703091a32b Moved setting of the allow flags.
Florian Pose <fp@igh-essen.com>
parents: 901
diff changeset
  2324
2349
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
  2325
    /* Allow scanning after a topology change. */
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
  2326
    master->allow_scan = 1;
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
  2327
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2328
    master->active = 1;
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2329
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2330
    // notify state machine, that the configuration shall now be applied
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2331
    master->config_changed = 1;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2332
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
  2333
    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
  2334
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2335
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2336
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2337
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2338
void ecrt_master_deactivate(ec_master_t *master)
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2339
{
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2340
    ec_slave_t *slave;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2341
#ifdef EC_EOE
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2342
    ec_eoe_t *eoe;
1914
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2343
    int eoe_was_running;
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2344
#endif
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2345
1939
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
  2346
    EC_MASTER_DBG(master, 1, "%s(master = 0x%p)\n", __func__, master);
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2347
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2348
    if (!master->active) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2349
        EC_MASTER_WARN(master, "%s: Master not active.\n", __func__);
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2350
        return;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2351
    }
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2352
1914
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2353
    ec_master_thread_stop(master);
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2354
#ifdef EC_EOE
1914
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2355
    eoe_was_running = master->eoe_thread != NULL;
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2356
    ec_master_eoe_stop(master);
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2357
#endif
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
  2358
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2359
    master->send_cb = ec_master_internal_send_cb;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2360
    master->receive_cb = ec_master_internal_receive_cb;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2361
    master->cb_data = master;
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 2419
diff changeset
  2362
1939
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
  2363
    ec_master_clear_config(master);
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2364
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2365
    for (slave = master->slaves;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2366
            slave < master->slaves + master->slave_count;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2367
            slave++) {
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2368
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2369
        // set states for all slaves
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2370
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2371
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2372
        // mark for reconfiguration, because the master could have no
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2373
        // possibility for a reconfiguration between two sequential operation
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2374
        // phases.
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2375
        slave->force_config = 1;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2376
    }
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2377
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2378
#ifdef EC_EOE
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2379
    // ... but leave EoE slaves in OP
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2380
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2381
        if (ec_eoe_is_open(eoe))
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2382
            ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP);
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2383
    }
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2384
#endif
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2385
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2386
    master->app_time = 0ULL;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2387
    master->app_start_time = 0ULL;
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2388
    master->has_app_time = 0;
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2389
1914
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2390
#ifdef EC_EOE
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2391
    if (eoe_was_running) {
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2392
        ec_master_eoe_start(master);
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2393
    }
da7adbde2625 Fixed possible bug in EoE code: Only restart EoE process, when it was running
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2394
#endif
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2395
    if (ec_master_thread_start(master, ec_master_idle_thread,
2455
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  2396
                "EtherCAT-IDLE")) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2397
        EC_MASTER_WARN(master, "Failed to restart master thread!\n");
2455
c6b1c8fd20f4 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  2398
    }
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2399
2349
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
  2400
    /* Disallow scanning to get into the same state like after a master
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
  2401
     * request (after ec_master_enter_operation_phase() is called). */
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
  2402
    master->allow_scan = 0;
2f5993d86ea5 Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2340
diff changeset
  2403
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2404
    master->active = 0;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2405
}
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2406
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2407
/*****************************************************************************/
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2408
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2409
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
  2410
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2411
    ec_datagram_t *datagram, *n;
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2412
    ec_device_index_t dev_idx;
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
  2413
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2414
    if (master->injection_seq_rt != master->injection_seq_fsm) {
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2485
diff changeset
  2415
        // inject datagram produced by master FSM
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2416
        ec_master_queue_datagram(master, &master->fsm_datagram);
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
  2417
        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
  2418
    }
2305
668bdb89879b Removed unnecessary call of ec_master_inject_external_datagrams().
Florian Pose <fp@igh-essen.com>
parents: 2301
diff changeset
  2419
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
  2420
    ec_master_inject_external_datagrams(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
  2421
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  2422
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  2423
            dev_idx++) {
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2424
        if (unlikely(!master->devices[dev_idx].link_state)) {
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2425
            // link is down, no datagram can be sent
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2426
            list_for_each_entry_safe(datagram, n,
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2427
                    &master->datagram_queue, queue) {
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2428
                if (datagram->device_index == dev_idx) {
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2429
                    datagram->state = EC_DATAGRAM_ERROR;
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2430
                    list_del_init(&datagram->queue);
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2431
                }
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2432
            }
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2433
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2434
            if (!master->devices[dev_idx].dev) {
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2435
                continue;
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2436
            }
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2437
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2438
            // query link state
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2439
            ec_device_poll(&master->devices[dev_idx]);
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2440
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2441
            // clear frame statistics
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2442
            ec_device_clear_stats(&master->devices[dev_idx]);
2370
18e1e8b30ff7 Fixed sending on backup link if main link is down.
Florian Pose <fp@igh-essen.com>
parents: 2360
diff changeset
  2443
            continue;
2269
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2444
        }
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2445
1d0711235a61 Redundant outputs via datagram pairs.
Florian Pose <fp@igh-essen.com>
parents: 2268
diff changeset
  2446
        // send frames
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2447
        ec_master_send_datagrams(master, dev_idx);
2268
5e1d3c9430e0 Datagram device_index member.
Florian Pose <fp@igh-essen.com>
parents: 2267
diff changeset
  2448
    }
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
  2449
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2450
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2451
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2452
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2453
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
  2454
{
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  2455
    unsigned int dev_idx;
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
  2456
    ec_datagram_t *datagram, *next;
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2457
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2458
    // receive datagrams
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  2459
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  2460
            dev_idx++) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  2461
        ec_device_poll(&master->devices[dev_idx]);
2157
8fa0571f9996 Poll both devices.
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2462
    }
2158
69f2b2702336 Adjusted frame statistics for the use with two devices.
Florian Pose <fp@igh-essen.com>
parents: 2157
diff changeset
  2463
    ec_master_update_device_stats(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
  2464
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2465
    // 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
  2466
    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
  2467
        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
  2468
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  2469
#ifdef EC_HAVE_CYCLES
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  2470
        if (master->devices[EC_DEVICE_MAIN].cycles_poll -
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  2471
                datagram->cycles_sent > timeout_cycles) {
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  2472
#else
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  2473
        if (master->devices[EC_DEVICE_MAIN].jiffies_poll -
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  2474
                datagram->jiffies_sent > timeout_jiffies) {
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  2475
#endif
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
  2476
            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
  2477
            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
  2478
            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
  2479
            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
  2480
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  2481
            if (unlikely(master->debug_level > 0)) {
1237
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  2482
                unsigned int time_us;
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  2483
#ifdef EC_HAVE_CYCLES
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  2484
                time_us = (unsigned int)
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  2485
                    (master->devices[EC_DEVICE_MAIN].cycles_poll -
1237
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  2486
                        datagram->cycles_sent) * 1000 / cpu_khz;
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  2487
#else
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  2488
                time_us = (unsigned int)
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  2489
                    ((master->devices[EC_DEVICE_MAIN].jiffies_poll -
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
  2490
                            datagram->jiffies_sent) * 1000000 / HZ);
1237
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  2491
#endif
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2492
                EC_MASTER_DBG(master, 0, "TIMED OUT datagram %p,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2493
                        " index %02X waited %u us.\n",
1543
373cd456dc26 Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2494
                        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
  2495
            }
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
  2496
        }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2497
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2498
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2499
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2500
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2501
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2502
void ecrt_master_send_ext(ec_master_t *master)
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2503
{
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2504
    ec_datagram_t *datagram, *next;
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2505
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2506
    list_for_each_entry_safe(datagram, next, &master->ext_datagram_queue,
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2507
            queue) {
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2508
        list_del(&datagram->queue);
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2509
        ec_master_queue_datagram(master, datagram);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2510
    }
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2511
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2512
    ecrt_master_send(master);
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2513
}
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2514
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2515
/*****************************************************************************/
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2516
1332
d62633fea8ed merge -c1610 branches/stable-1.4: Added missing doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 1329
diff changeset
  2517
/** 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
  2518
 */
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2519
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
  2520
        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
  2521
        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
  2522
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2523
    ec_slave_config_t *sc;
697
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2524
    unsigned int found = 0;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2525
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  2526
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2527
    EC_MASTER_DBG(master, 1, "ecrt_master_slave_config(master = 0x%p,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2528
            " alias = %u, position = %u, vendor_id = 0x%08x,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2529
            " product_code = 0x%08x)\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2530
            master, alias, position, vendor_id, product_code);
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  2531
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2532
    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
  2533
        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
  2534
            found = 1;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2535
            break;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2536
        }
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2537
    }
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2538
1024
fef0b1953770 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1023
diff changeset
  2539
    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
  2540
        if (sc->vendor_id != vendor_id || sc->product_code != product_code) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2541
            EC_MASTER_ERR(master, "Slave type mismatch. Slave was"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2542
                    " configured as 0x%08X/0x%08X before. Now configuring"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2543
                    " with 0x%08X/0x%08X.\n", sc->vendor_id, sc->product_code,
1010
6672b86e7b10 Reverted revision number checking from r1228.
Florian Pose <fp@igh-essen.com>
parents: 1009
diff changeset
  2544
                    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
  2545
            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
  2546
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2547
    } else {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2548
        EC_MASTER_DBG(master, 1, "Creating slave configuration for %u:%u,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2549
                " 0x%08X/0x%08X.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2550
                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
  2551
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2552
        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
  2553
                        GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2554
            EC_MASTER_ERR(master, "Failed to allocate memory"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2555
                    " 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
  2556
            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
  2557
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2558
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
  2559
        ec_slave_config_init(sc, master,
1010
6672b86e7b10 Reverted revision number checking from r1228.
Florian Pose <fp@igh-essen.com>
parents: 1009
diff changeset
  2560
                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
  2561
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
  2562
        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
  2563
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2564
        // 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
  2565
        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
  2566
        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
  2567
        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
  2568
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
  2569
        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
  2570
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2571
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2572
    return sc;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2573
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2574
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2575
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2576
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2577
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
  2578
        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
  2579
        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
  2580
{
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2581
    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
  2582
            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
  2583
    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
  2584
}
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2585
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2586
/*****************************************************************************/
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2587
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2588
int ecrt_master_select_reference_clock(ec_master_t *master,
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2589
        ec_slave_config_t *sc)
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2590
{
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2591
    if (sc) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2592
        ec_slave_t *slave = sc->slave;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2593
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2594
        // output an early warning
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2595
        if (slave &&
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2596
                (!slave->base_dc_supported || !slave->has_dc_system_time)) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2597
            EC_MASTER_WARN(master, "Slave %u can not act as"
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2598
                    " a reference clock!", slave->ring_position);
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2599
        }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2600
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2601
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2602
    master->dc_ref_config = sc;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2603
    return 0;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2604
}
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2605
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2606
/*****************************************************************************/
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2607
1594
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2608
int ecrt_master(ec_master_t *master, ec_master_info_t *master_info)
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2609
{
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2610
    EC_MASTER_DBG(master, 1, "ecrt_master(master = 0x%p,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2611
            " master_info = 0x%p)\n", master, master_info);
1594
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2612
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2613
    master_info->slave_count = master->slave_count;
2267
2d36f36a433c Devices as array; lock all device modules with module_get().
Florian Pose <fp@igh-essen.com>
parents: 2158
diff changeset
  2614
    master_info->link_up = master->devices[EC_DEVICE_MAIN].link_state;
1594
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2615
    master_info->scan_busy = master->scan_busy;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2616
    master_info->app_time = master->app_time;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2617
    return 0;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2618
}
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2619
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2620
/*****************************************************************************/
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2621
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2622
int ecrt_master_get_slave(ec_master_t *master, uint16_t slave_position,
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2623
        ec_slave_info_t *slave_info)
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2624
{
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2625
    const ec_slave_t *slave;
2340
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2626
    unsigned int i;
1594
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2627
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2628
    if (down_interruptible(&master->master_sem)) {
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2629
        return -EINTR;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2630
    }
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2631
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2632
    slave = ec_master_find_slave_const(master, 0, slave_position);
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2633
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2634
    slave_info->position = slave->ring_position;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2635
    slave_info->vendor_id = slave->sii.vendor_id;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2636
    slave_info->product_code = slave->sii.product_code;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2637
    slave_info->revision_number = slave->sii.revision_number;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2638
    slave_info->serial_number = slave->sii.serial_number;
1909
ea3eb4c74c1b Introduced effective_alias variable to separate reg12 alias from SII alias.
Florian Pose <fp@igh-essen.com>
parents: 1906
diff changeset
  2639
    slave_info->alias = slave->effective_alias;
1594
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2640
    slave_info->current_on_ebus = slave->sii.current_on_ebus;
2340
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2641
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2642
    for (i = 0; i < EC_MAX_PORTS; i++) {
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2643
        slave_info->ports[i].desc = slave->ports[i].desc;
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2644
        slave_info->ports[i].link.link_up = slave->ports[i].link.link_up;
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2645
        slave_info->ports[i].link.loop_closed =
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2646
            slave->ports[i].link.loop_closed;
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2647
        slave_info->ports[i].link.signal_detected =
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2648
            slave->ports[i].link.signal_detected;
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2649
        slave_info->ports[i].receive_time = slave->ports[i].receive_time;
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2650
        if (slave->ports[i].next_slave) {
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2651
            slave_info->ports[i].next_slave =
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2652
                slave->ports[i].next_slave->ring_position;
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2653
        } else {
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2654
            slave_info->ports[i].next_slave = 0xffff;
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2655
        }
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2656
        slave_info->ports[i].delay_to_next_dc =
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2657
            slave->ports[i].delay_to_next_dc;
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2658
    }
3f2a4f9ff786 Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2336
diff changeset
  2659
1594
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2660
    slave_info->al_state = slave->current_state;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2661
    slave_info->error_flag = slave->error_flag;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2662
    slave_info->sync_count = slave->sii.sync_count;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2663
    slave_info->sdo_count = ec_slave_sdo_count(slave);
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2664
    if (slave->sii.name) {
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2665
        strncpy(slave_info->name, slave->sii.name, EC_MAX_STRING_LENGTH);
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2666
    } else {
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2667
        slave_info->name[0] = 0;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2668
    }
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2669
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2670
    up(&master->master_sem);
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2671
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2672
    return 0;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2673
}
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2674
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2675
/*****************************************************************************/
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2676
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2677
void ecrt_master_callbacks(ec_master_t *master,
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2678
        void (*send_cb)(void *), void (*receive_cb)(void *), void *cb_data)
204
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  2679
{
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2680
    EC_MASTER_DBG(master, 1, "ecrt_master_callbacks(master = 0x%p,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2681
            " send_cb = 0x%p, receive_cb = 0x%p, cb_data = 0x%p)\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2682
            master, send_cb, receive_cb, cb_data);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2683
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2684
    master->app_send_cb = send_cb;
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2685
    master->app_receive_cb = receive_cb;
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2686
    master->app_cb_data = cb_data;
204
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  2687
}
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  2688
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  2689
/*****************************************************************************/
5ab50514d9b2 Locking callback interface.
Florian Pose <fp@igh-essen.com>
parents: 203
diff changeset
  2690
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2691
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
  2692
{
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2693
    ec_device_index_t dev_idx;
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2694
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2695
    state->slaves_responding = 0U;
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2696
    state->al_states = 0;
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2697
    state->link_up = 0U;
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2698
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  2699
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  2700
            dev_idx++) {
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2701
        /* Announce sum of responding slaves on all links. */
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2702
        state->slaves_responding += master->fsm.slaves_responding[dev_idx];
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2703
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2704
        /* Binary-or slave states of all links. */
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2705
        state->al_states |= master->fsm.slave_states[dev_idx];
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2706
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2707
        /* Signal link up if at least one device has link. */
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2708
        state->link_up |= master->devices[dev_idx].link_state;
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2709
    }
612
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  2710
}
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  2711
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  2712
/*****************************************************************************/
aede068f9a74 Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
  2713
2380
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2714
int ecrt_master_link_state(const ec_master_t *master, unsigned int dev_idx,
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2715
        ec_master_link_state_t *state)
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2716
{
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
  2717
    if (dev_idx >= ec_master_num_devices(master)) {
2380
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2718
        return -EINVAL;
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2719
    }
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2720
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2721
    state->slaves_responding = master->fsm.slaves_responding[dev_idx];
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2722
    state->al_states = master->fsm.slave_states[dev_idx];
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2723
    state->link_up = master->devices[dev_idx].link_state;
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2724
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2725
    return 0;
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2726
}
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2727
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2728
/*****************************************************************************/
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  2729
1434
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2730
void ecrt_master_application_time(ec_master_t *master, uint64_t app_time)
1417
7c2d5d69134c Replaced timeval by 64-bit EtherCAT time.
Florian Pose <fp@igh-essen.com>
parents: 1415
diff changeset
  2731
{
7c2d5d69134c Replaced timeval by 64-bit EtherCAT time.
Florian Pose <fp@igh-essen.com>
parents: 1415
diff changeset
  2732
    master->app_time = app_time;
1436
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1434
diff changeset
  2733
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2734
    if (unlikely(!master->has_app_time)) {
1436
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1434
diff changeset
  2735
        master->app_start_time = app_time;
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  2736
        master->has_app_time = 1;
1436
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1434
diff changeset
  2737
    }
1434
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2738
}
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2739
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2740
/*****************************************************************************/
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2741
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2742
int ecrt_master_reference_clock_time(ec_master_t *master, uint32_t *time)
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2743
{
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2744
    if (!master->dc_ref_clock) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2745
        return -ENXIO;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2746
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2747
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2748
    if (master->sync_datagram.state != EC_DATAGRAM_RECEIVED) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2749
        return -EIO;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2750
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2751
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2752
    // Get returned datagram time, transmission delay removed.
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2753
    *time = EC_READ_U32(master->sync_datagram.data) -
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2754
        master->dc_ref_clock->transmission_delay;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2755
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2756
    return 0;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2757
}
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2758
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2759
/*****************************************************************************/
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2760
1434
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2761
void ecrt_master_sync_reference_clock(ec_master_t *master)
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2762
{
2476
9a0d30056e70 Send sync datagrams only if reference clock is found.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2763
    if (master->dc_ref_clock) {
9a0d30056e70 Send sync datagrams only if reference clock is found.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2764
        EC_WRITE_U32(master->ref_sync_datagram.data, master->app_time);
9a0d30056e70 Send sync datagrams only if reference clock is found.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2765
        ec_master_queue_datagram(master, &master->ref_sync_datagram);
9a0d30056e70 Send sync datagrams only if reference clock is found.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2766
    }
1410
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  2767
}
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  2768
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  2769
/*****************************************************************************/
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  2770
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  2771
void ecrt_master_sync_slave_clocks(ec_master_t *master)
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  2772
{
2476
9a0d30056e70 Send sync datagrams only if reference clock is found.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2773
    if (master->dc_ref_clock) {
9a0d30056e70 Send sync datagrams only if reference clock is found.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2774
        ec_datagram_zero(&master->sync_datagram);
9a0d30056e70 Send sync datagrams only if reference clock is found.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2775
        ec_master_queue_datagram(master, &master->sync_datagram);
9a0d30056e70 Send sync datagrams only if reference clock is found.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2776
    }
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  2777
}
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  2778
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  2779
/*****************************************************************************/
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  2780
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2781
void ecrt_master_sync_monitor_queue(ec_master_t *master)
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2782
{
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2783
    ec_datagram_zero(&master->sync_mon_datagram);
2374
e898451c054a Slave scanning and configuration on all links.
Florian Pose <fp@igh-essen.com>
parents: 2372
diff changeset
  2784
    ec_master_queue_datagram(master, &master->sync_mon_datagram);
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2785
}
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2786
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2787
/*****************************************************************************/
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2788
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2789
uint32_t ecrt_master_sync_monitor_process(ec_master_t *master)
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2790
{
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2791
    if (master->sync_mon_datagram.state == EC_DATAGRAM_RECEIVED) {
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2792
        return EC_READ_U32(master->sync_mon_datagram.data) & 0x7fffffff;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2793
    } else {
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2794
        return 0xffffffff;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2795
    }
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2796
}
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2797
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2798
/*****************************************************************************/
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2799
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2800
int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position,
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2801
        uint16_t index, uint8_t subindex, uint8_t *data,
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2802
        size_t data_size, uint32_t *abort_code)
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2803
{
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2804
    ec_sdo_request_t request;
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2805
    ec_slave_t *slave;
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2806
    int ret;
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2807
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2808
    EC_MASTER_DBG(master, 1, "%s(master = 0x%p,"
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2809
            " slave_position = %u, index = 0x%04X, subindex = 0x%02X,"
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2810
            " data = 0x%p, data_size = %zu, abort_code = 0x%p)\n",
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2811
            __func__, master, slave_position, index, subindex,
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2812
            data, data_size, abort_code);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2813
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2814
    if (!data_size) {
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2815
        EC_MASTER_ERR(master, "Zero data size!\n");
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2816
        return -EINVAL;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2817
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2818
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2819
    ec_sdo_request_init(&request);
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2820
    ecrt_sdo_request_index(&request, index, subindex);
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2821
    ret = ec_sdo_request_alloc(&request, data_size);
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2822
    if (ret) {
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2823
        ec_sdo_request_clear(&request);
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2824
        return ret;
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2825
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2826
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2827
    memcpy(request.data, data, data_size);
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2828
    request.data_size = data_size;
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2829
    ecrt_sdo_request_write(&request);
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2830
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2831
    if (down_interruptible(&master->master_sem)) {
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2832
        ec_sdo_request_clear(&request);
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2833
        return -EINTR;
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2834
    }
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2835
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2836
    if (!(slave = ec_master_find_slave(master, 0, slave_position))) {
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2837
        up(&master->master_sem);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2838
        EC_MASTER_ERR(master, "Slave %u does not exist!\n", slave_position);
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2839
        ec_sdo_request_clear(&request);
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2840
        return -EINVAL;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2841
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2842
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2843
    EC_SLAVE_DBG(slave, 1, "Scheduling SDO download request.\n");
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2844
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2845
    // schedule request.
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2846
    list_add_tail(&request.list, &slave->sdo_requests);
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2847
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2848
    up(&master->master_sem);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2849
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2850
    // wait for processing through FSM
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2851
    if (wait_event_interruptible(master->request_queue,
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2852
                request.state != EC_INT_REQUEST_QUEUED)) {
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2853
        // interrupted by signal
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2854
        down(&master->master_sem);
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2855
        if (request.state == EC_INT_REQUEST_QUEUED) {
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2856
            list_del(&request.list);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2857
            up(&master->master_sem);
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2858
            ec_sdo_request_clear(&request);
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2859
            return -EINTR;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2860
        }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2861
        // request already processing: interrupt not possible.
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2862
        up(&master->master_sem);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2863
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2864
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2865
    // wait until master FSM has finished processing
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2866
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2867
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2868
    *abort_code = request.abort_code;
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2869
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2870
    if (request.state == EC_INT_REQUEST_SUCCESS) {
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2871
        ret = 0;
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2872
    } else if (request.errno) {
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2873
        ret = -request.errno;
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2874
    } else {
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2875
        ret = -EIO;
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2876
    }
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2877
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2878
    ec_sdo_request_clear(&request);
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2879
    return ret;
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2880
}
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2881
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2882
/*****************************************************************************/
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2883
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2884
int ecrt_master_sdo_download_complete(ec_master_t *master,
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2885
        uint16_t slave_position, uint16_t index, uint8_t *data,
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2886
        size_t data_size, uint32_t *abort_code)
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2887
{
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2888
    ec_sdo_request_t request;
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2889
    ec_slave_t *slave;
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2890
    int ret;
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2891
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2892
    EC_MASTER_DBG(master, 1, "%s(master = 0x%p,"
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2893
            " slave_position = %u, index = 0x%04X,"
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2894
            " data = 0x%p, data_size = %zu, abort_code = 0x%p)\n",
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2895
            __func__, master, slave_position, index, data, data_size,
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2896
            abort_code);
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2897
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2898
    if (!data_size) {
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2899
        EC_MASTER_ERR(master, "Zero data size!\n");
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2900
        return -EINVAL;
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2901
    }
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2902
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2903
    ec_sdo_request_init(&request);
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2904
    ecrt_sdo_request_index(&request, index, 0);
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2905
    ret = ec_sdo_request_alloc(&request, data_size);
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2906
    if (ret) {
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2907
        ec_sdo_request_clear(&request);
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2908
        return ret;
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2909
    }
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2910
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2911
    request.complete_access = 1;
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2912
    memcpy(request.data, data, data_size);
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2913
    request.data_size = data_size;
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2914
    ecrt_sdo_request_write(&request);
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2915
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2916
    if (down_interruptible(&master->master_sem)) {
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2917
        ec_sdo_request_clear(&request);
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2918
        return -EINTR;
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2919
    }
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2920
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2921
    if (!(slave = ec_master_find_slave(master, 0, slave_position))) {
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2922
        up(&master->master_sem);
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2923
        EC_MASTER_ERR(master, "Slave %u does not exist!\n", slave_position);
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2924
        ec_sdo_request_clear(&request);
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2925
        return -EINVAL;
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2926
    }
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2927
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2928
    EC_SLAVE_DBG(slave, 1, "Scheduling SDO download request"
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2929
            " (complete access).\n");
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2930
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2931
    // schedule request.
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2932
    list_add_tail(&request.list, &slave->sdo_requests);
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2933
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2934
    up(&master->master_sem);
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2935
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2936
    // wait for processing through FSM
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2937
    if (wait_event_interruptible(master->request_queue,
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2938
                request.state != EC_INT_REQUEST_QUEUED)) {
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2939
        // interrupted by signal
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2940
        down(&master->master_sem);
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2941
        if (request.state == EC_INT_REQUEST_QUEUED) {
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2942
            list_del(&request.list);
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2943
            up(&master->master_sem);
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2944
            ec_sdo_request_clear(&request);
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2945
            return -EINTR;
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2946
        }
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2947
        // request already processing: interrupt not possible.
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2948
        up(&master->master_sem);
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2949
    }
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2950
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2951
    // wait until master FSM has finished processing
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2952
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2953
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2954
    *abort_code = request.abort_code;
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2955
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2956
    if (request.state == EC_INT_REQUEST_SUCCESS) {
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2957
        ret = 0;
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2958
    } else if (request.errno) {
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2959
        ret = -request.errno;
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2960
    } else {
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2961
        ret = -EIO;
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2962
    }
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2963
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2964
    ec_sdo_request_clear(&request);
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2965
    return ret;
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2966
}
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2967
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2968
/*****************************************************************************/
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  2969
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2970
int ecrt_master_sdo_upload(ec_master_t *master, uint16_t slave_position,
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2971
        uint16_t index, uint8_t subindex, uint8_t *target,
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2972
        size_t target_size, size_t *result_size, uint32_t *abort_code)
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2973
{
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2974
    ec_sdo_request_t request;
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2975
    ec_slave_t *slave;
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  2976
    int ret = 0;
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2977
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2978
    EC_MASTER_DBG(master, 1, "%s(master = 0x%p,"
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2979
            " slave_position = %u, index = 0x%04X, subindex = 0x%02X,"
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2980
            " target = 0x%p, target_size = %zu, result_size = 0x%p,"
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2981
            " abort_code = 0x%p)\n",
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2982
            __func__, master, slave_position, index, subindex,
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2983
            target, target_size, result_size, abort_code);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2984
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2985
    ec_sdo_request_init(&request);
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2986
    ecrt_sdo_request_index(&request, index, subindex);
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2987
    ecrt_sdo_request_read(&request);
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2988
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2989
    if (down_interruptible(&master->master_sem)) {
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2990
        ec_sdo_request_clear(&request);
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2991
        return -EINTR;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2992
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2993
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2994
    if (!(slave = ec_master_find_slave(master, 0, slave_position))) {
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2995
        up(&master->master_sem);
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  2996
        ec_sdo_request_clear(&request);
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2997
        EC_MASTER_ERR(master, "Slave %u does not exist!\n", slave_position);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2998
        return -EINVAL;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  2999
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3000
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3001
    EC_SLAVE_DBG(slave, 1, "Scheduling SDO upload request.\n");
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3002
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3003
    // schedule request.
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3004
    list_add_tail(&request.list, &slave->sdo_requests);
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3005
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3006
    up(&master->master_sem);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3007
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3008
    // wait for processing through FSM
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3009
    if (wait_event_interruptible(master->request_queue,
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3010
                request.state != EC_INT_REQUEST_QUEUED)) {
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3011
        // interrupted by signal
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3012
        down(&master->master_sem);
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3013
        if (request.state == EC_INT_REQUEST_QUEUED) {
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3014
            list_del(&request.list);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3015
            up(&master->master_sem);
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3016
            ec_sdo_request_clear(&request);
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3017
            return -EINTR;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3018
        }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3019
        // request already processing: interrupt not possible.
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3020
        up(&master->master_sem);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3021
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3022
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3023
    // wait until master FSM has finished processing
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3024
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3025
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3026
    *abort_code = request.abort_code;
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3027
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3028
    if (request.state != EC_INT_REQUEST_SUCCESS) {
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3029
        *result_size = 0;
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3030
        if (request.errno) {
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3031
            ret = -request.errno;
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3032
        } else {
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3033
            ret = -EIO;
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3034
        }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3035
    } else {
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3036
        if (request.data_size > target_size) {
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3037
            EC_MASTER_ERR(master, "Buffer too small.\n");
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3038
            ret = -EOVERFLOW;
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3039
        }
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3040
        else {
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3041
            memcpy(target, request.data, request.data_size);
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3042
            *result_size = request.data_size;
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3043
            ret = 0;
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3044
        }
2461
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3045
    }
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3046
d2c48550acd0 Removed unnecessary ec_master_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 2460
diff changeset
  3047
    ec_sdo_request_clear(&request);
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3048
    return ret;
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3049
}
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3050
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3051
/*****************************************************************************/
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3052
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3053
int ecrt_master_write_idn(ec_master_t *master, uint16_t slave_position,
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3054
        uint8_t drive_no, uint16_t idn, uint8_t *data, size_t data_size,
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3055
        uint16_t *error_code)
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3056
{
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3057
    ec_soe_request_t request;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3058
    ec_slave_t *slave;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3059
    int ret;
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3060
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3061
    if (drive_no > 7) {
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3062
        EC_MASTER_ERR(master, "Invalid drive number!\n");
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3063
        return -EINVAL;
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3064
    }
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3065
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3066
    ec_soe_request_init(&request);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3067
    ec_soe_request_set_drive_no(&request, drive_no);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3068
    ec_soe_request_set_idn(&request, idn);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3069
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3070
    ret = ec_soe_request_alloc(&request, data_size);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3071
    if (ret) {
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3072
        ec_soe_request_clear(&request);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3073
        return ret;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3074
    }
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3075
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3076
    memcpy(request.data, data, data_size);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3077
    request.data_size = data_size;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3078
    ec_soe_request_write(&request);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3079
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3080
    if (down_interruptible(&master->master_sem)) {
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3081
        ec_soe_request_clear(&request);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3082
        return -EINTR;
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3083
    }
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3084
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3085
    if (!(slave = ec_master_find_slave(master, 0, slave_position))) {
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3086
        up(&master->master_sem);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3087
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3088
                slave_position);
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3089
        ec_soe_request_clear(&request);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3090
        return -EINVAL;
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3091
    }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3092
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3093
    EC_SLAVE_DBG(slave, 1, "Scheduling SoE write request.\n");
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3094
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3095
    // schedule SoE write request.
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3096
    list_add_tail(&request.list, &slave->soe_requests);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3097
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3098
    up(&master->master_sem);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3099
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3100
    // wait for processing through FSM
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3101
    if (wait_event_interruptible(master->request_queue,
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3102
                request.state != EC_INT_REQUEST_QUEUED)) {
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3103
        // interrupted by signal
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3104
        down(&master->master_sem);
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3105
        if (request.state == EC_INT_REQUEST_QUEUED) {
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3106
            // abort request
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3107
            list_del(&request.list);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3108
            up(&master->master_sem);
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3109
            ec_soe_request_clear(&request);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3110
            return -EINTR;
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3111
        }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3112
        up(&master->master_sem);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3113
    }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3114
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3115
    // wait until master FSM has finished processing
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3116
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3117
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3118
    if (error_code) {
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3119
        *error_code = request.error_code;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3120
    }
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3121
    ret = request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3122
    ec_soe_request_clear(&request);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3123
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3124
    return ret;
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3125
}
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3126
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3127
/*****************************************************************************/
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3128
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3129
int ecrt_master_read_idn(ec_master_t *master, uint16_t slave_position,
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3130
        uint8_t drive_no, uint16_t idn, uint8_t *target, size_t target_size,
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3131
        size_t *result_size, uint16_t *error_code)
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3132
{
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3133
    ec_soe_request_t request;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3134
    ec_slave_t *slave;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3135
    int ret;
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3136
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3137
    if (drive_no > 7) {
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3138
        EC_MASTER_ERR(master, "Invalid drive number!\n");
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3139
        return -EINVAL;
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3140
    }
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3141
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3142
    ec_soe_request_init(&request);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3143
    ec_soe_request_set_drive_no(&request, drive_no);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3144
    ec_soe_request_set_idn(&request, idn);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3145
    ec_soe_request_read(&request);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3146
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3147
    if (down_interruptible(&master->master_sem)) {
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3148
        ec_soe_request_clear(&request);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3149
        return -EINTR;
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3150
    }
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3151
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3152
    if (!(slave = ec_master_find_slave(master, 0, slave_position))) {
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3153
        up(&master->master_sem);
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3154
        ec_soe_request_clear(&request);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3155
        EC_MASTER_ERR(master, "Slave %u does not exist!\n", slave_position);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3156
        return -EINVAL;
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3157
    }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3158
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3159
    EC_SLAVE_DBG(slave, 1, "Scheduling SoE read request.\n");
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3160
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3161
    // schedule request.
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3162
    list_add_tail(&request.list, &slave->soe_requests);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3163
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3164
    up(&master->master_sem);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3165
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3166
    // wait for processing through FSM
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3167
    if (wait_event_interruptible(master->request_queue,
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3168
                request.state != EC_INT_REQUEST_QUEUED)) {
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3169
        // interrupted by signal
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3170
        down(&master->master_sem);
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3171
        if (request.state == EC_INT_REQUEST_QUEUED) {
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3172
            list_del(&request.list);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3173
            up(&master->master_sem);
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3174
            ec_soe_request_clear(&request);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3175
            return -EINTR;
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3176
        }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3177
        // request already processing: interrupt not possible.
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3178
        up(&master->master_sem);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3179
    }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3180
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3181
    // wait until master FSM has finished processing
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2465
diff changeset
  3182
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3183
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3184
    if (error_code) {
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3185
        *error_code = request.error_code;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3186
    }
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3187
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3188
    if (request.state != EC_INT_REQUEST_SUCCESS) {
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3189
        if (result_size) {
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3190
            *result_size = 0;
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3191
        }
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3192
        ret = -EIO;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3193
    } else { // success
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3194
        if (request.data_size > target_size) {
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3195
            EC_MASTER_ERR(master, "Buffer too small.\n");
2465
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3196
            ret = -EOVERFLOW;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3197
        }
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3198
        else { // data fits in buffer
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3199
            if (result_size) {
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3200
                *result_size = request.data_size;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3201
            }
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3202
            memcpy(target, request.data, request.data_size);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3203
            ret = 0;
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3204
        }
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3205
    }
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3206
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3207
    ec_soe_request_clear(&request);
35611452b785 Removed unnecessary ec_master_soe_request_t type.
Florian Pose <fp@igh-essen.com>
parents: 2461
diff changeset
  3208
    return ret;
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3209
}
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3210
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3211
/*****************************************************************************/
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3212
2009
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3213
void ecrt_master_reset(ec_master_t *master)
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3214
{
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3215
    ec_slave_config_t *sc;
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3216
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3217
    list_for_each_entry(sc, &master->configs, list) {
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3218
        if (sc->slave) {
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3219
            ec_slave_request_state(sc->slave, EC_SLAVE_STATE_OP);
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3220
        }
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3221
    }
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3222
}
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3223
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3224
/*****************************************************************************/
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3225
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  3226
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  3227
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  3228
EXPORT_SYMBOL(ecrt_master_create_domain);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  3229
EXPORT_SYMBOL(ecrt_master_activate);
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  3230
EXPORT_SYMBOL(ecrt_master_deactivate);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  3231
EXPORT_SYMBOL(ecrt_master_send);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  3232
EXPORT_SYMBOL(ecrt_master_send_ext);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
  3233
EXPORT_SYMBOL(ecrt_master_receive);
206
60a10d85c20b Prepared EoE processing with workqueue.
Florian Pose <fp@igh-essen.com>
parents: 204
diff changeset
  3234
EXPORT_SYMBOL(ecrt_master_callbacks);
1594
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  3235
EXPORT_SYMBOL(ecrt_master);
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  3236
EXPORT_SYMBOL(ecrt_master_get_slave);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  3237
EXPORT_SYMBOL(ecrt_master_slave_config);
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  3238
EXPORT_SYMBOL(ecrt_master_select_reference_clock);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  3239
EXPORT_SYMBOL(ecrt_master_state);
2380
cf9db49bcce8 Added ecrt_master_link_state() to retrieve information about a redundant link.
Florian Pose <fp@igh-essen.com>
parents: 2374
diff changeset
  3240
EXPORT_SYMBOL(ecrt_master_link_state);
1434
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  3241
EXPORT_SYMBOL(ecrt_master_application_time);
1410
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  3242
EXPORT_SYMBOL(ecrt_master_sync_reference_clock);
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  3243
EXPORT_SYMBOL(ecrt_master_sync_slave_clocks);
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  3244
EXPORT_SYMBOL(ecrt_master_reference_clock_time);
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  3245
EXPORT_SYMBOL(ecrt_master_sync_monitor_queue);
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  3246
EXPORT_SYMBOL(ecrt_master_sync_monitor_process);
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3247
EXPORT_SYMBOL(ecrt_master_sdo_download);
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2115
diff changeset
  3248
EXPORT_SYMBOL(ecrt_master_sdo_download_complete);
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2085
diff changeset
  3249
EXPORT_SYMBOL(ecrt_master_sdo_upload);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3250
EXPORT_SYMBOL(ecrt_master_write_idn);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3251
EXPORT_SYMBOL(ecrt_master_read_idn);
2009
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3252
EXPORT_SYMBOL(ecrt_master_reset);
42
a22a202d0f42 Domains, Warten beim Senden, 10kHz.
Florian Pose <fp@igh-essen.com>
parents: 39
diff changeset
  3253
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  3254
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  3255
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  3256
/*****************************************************************************/