master/master.c
author Florian Pose <fp@gh.de>
Tue, 03 May 2016 14:13:11 +0200
changeset 2642 9dc0b2262f90
parent 2630 a380cce7d6f0
child 2645 b7ac213beac5
permissions -rw-r--r--
Fixed endianess of EoE parameters.
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
 *
2240
b45438edf869 Avoided unused variable warnings.
Florian Pose <fp@igh-essen.com>
parents: 2166
diff changeset
     3
 *  $Id$
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    59
/** Set to 1 to enable external datagram injection debugging.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    60
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    61
#define DEBUG_INJECT 0
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    62
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    63
/** Always output corrupted frames.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    64
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    65
#define FORCE_OUTPUT_CORRUPTED 0
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    66
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    67
#ifdef EC_HAVE_CYCLES
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    68
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    69
/** Frame timeout in cycles.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    70
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    71
static cycles_t timeout_cycles;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    72
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    73
/** Timeout for external datagram injection [cycles].
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    74
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    75
static cycles_t ext_injection_timeout_cycles;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    76
2037
ea0319750e13 Optionally compile with trace_printk support
Martin Troxler <ch1010277@ch10pc446>
parents: 2036
diff changeset
    77
#else
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    78
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    79
/** 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
    80
 */
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    81
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
    82
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    83
/** Timeout for external datagram injection [jiffies].
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    84
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    85
static unsigned long ext_injection_timeout_jiffies;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    86
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    87
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    88
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    89
/** List of intervals for statistics [s].
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    90
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    91
const unsigned int rate_intervals[] = {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    92
    1, 10, 60
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
    93
};
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    94
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    95
/*****************************************************************************/
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
    96
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
    97
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
    98
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
    99
static int ec_master_idle_thread(void *);
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   100
static int ec_master_operation_thread(void *);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   101
#ifdef EC_EOE
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   102
static int ec_master_eoe_thread(void *);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   103
#endif
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   104
void ec_master_find_dc_ref_clock(ec_master_t *);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   105
void ec_master_clear_device_stats(ec_master_t *);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   106
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
   107
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
   108
/*****************************************************************************/
fb4c9dd11ca0 Sourced SysFS attribute show method prototypes out of headers.
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
   109
1279
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   110
/** 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
   111
*/
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   112
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
   113
{
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   114
#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
   115
    timeout_cycles = (cycles_t) EC_IO_TIMEOUT /* us */ * (cpu_khz / 1000);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   116
    ext_injection_timeout_cycles =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   117
        (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
   118
#else
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   119
    // 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
   120
    timeout_jiffies = max(EC_IO_TIMEOUT * HZ / 1000000, 1);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   121
    ext_injection_timeout_jiffies =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   122
        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
   123
#endif
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   124
}
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   125
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   126
/*****************************************************************************/
6911450535b7 merge -c1522 branches/stable-1.4: Fixed jace in jiffies timeout calculation.
Florian Pose <fp@igh-essen.com>
parents: 1252
diff changeset
   127
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   129
   Master constructor.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   130
   \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
   131
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   132
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   133
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
   134
        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
   135
        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
   136
        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
   137
        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
   138
        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
   139
        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
   140
        )
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   141
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   142
    int ret;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   143
    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
   144
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   145
    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
   146
    master->reserved = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   147
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   148
    sema_init(&master->master_sem, 1);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   149
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   150
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < EC_MAX_NUM_DEVICES; dev_idx++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   151
        master->macs[dev_idx] = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   152
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   153
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   154
    master->macs[EC_DEVICE_MAIN] = main_mac;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   155
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   156
#if EC_MAX_NUM_DEVICES > 1
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   157
    master->macs[EC_DEVICE_BACKUP] = backup_mac;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   158
    master->num_devices = 1 + !ec_mac_is_zero(backup_mac);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   159
#else
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   160
    if (!ec_mac_is_zero(backup_mac)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   161
        EC_MASTER_WARN(master, "Ignoring backup MAC address!");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   162
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   163
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   164
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   165
    ec_master_clear_device_stats(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   166
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   167
    sema_init(&master->device_sem, 1);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   168
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   169
    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
   170
    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
   171
    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
   172
    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
   173
    master->injection_seq_rt = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   174
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   175
    master->slaves = NULL;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   176
    master->slave_count = 0;
1987
f452c93f7723 Improved distributed clock offset calculation to speed-up initial drift compensation
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1981
diff changeset
   177
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   178
    INIT_LIST_HEAD(&master->configs);
2165
1d94f77784a0 Fixed missing initialisation of allow_config flag.
Florian Pose <fp@igh-essen.com>
parents: 2164
diff changeset
   179
    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
   180
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
   181
    master->app_time = 0ULL;
2165
1d94f77784a0 Fixed missing initialisation of allow_config flag.
Florian Pose <fp@igh-essen.com>
parents: 2164
diff changeset
   182
    master->app_start_time = 0ULL;
1d94f77784a0 Fixed missing initialisation of allow_config flag.
Florian Pose <fp@igh-essen.com>
parents: 2164
diff changeset
   183
    master->has_app_time = 0;
1408
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
   184
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   185
    master->scan_busy = 0;
2165
1d94f77784a0 Fixed missing initialisation of allow_config flag.
Florian Pose <fp@igh-essen.com>
parents: 2164
diff changeset
   186
    master->allow_scan = 1;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   187
    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
   188
    init_waitqueue_head(&master->scan_queue);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   189
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   190
    master->config_busy = 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   191
    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
   192
    init_waitqueue_head(&master->config_queue);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   193
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   194
    INIT_LIST_HEAD(&master->datagram_queue);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   195
    master->datagram_index = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   196
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   197
    INIT_LIST_HEAD(&master->ext_datagram_queue);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   198
    sema_init(&master->ext_queue_sem, 1);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   199
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   200
    master->ext_ring_idx_rt = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   201
    master->ext_ring_idx_fsm = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   202
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   203
    // init external datagram ring
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   204
    for (i = 0; i < EC_EXT_RING_SIZE; i++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   205
        ec_datagram_t *datagram = &master->ext_datagram_ring[i];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   206
        ec_datagram_init(datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   207
        snprintf(datagram->name, EC_DATAGRAM_NAME_SIZE, "ext-%u", i);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   208
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   209
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
   210
    // 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
   211
    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
   212
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   213
    master->fsm_slave = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   214
    INIT_LIST_HEAD(&master->fsm_exec_list);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   215
    master->fsm_exec_count = 0U;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   216
1399
f79d4bb5b23a Added debug_level module parameter. debug_level is now unsigned int.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
   217
    master->debug_level = debug_level;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   218
    master->stats.timeouts = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   219
    master->stats.corrupted = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   220
    master->stats.unmatched = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   221
    master->stats.output_jiffies = 0;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   222
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   223
    master->thread = NULL;
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   224
1041
42c9ac58d9ce Removed state machine cycle time measuring.
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   225
#ifdef EC_EOE
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
   226
    master->eoe_thread = NULL;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   227
    INIT_LIST_HEAD(&master->eoe_handlers);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   228
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   229
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   230
    sema_init(&master->io_sem, 1);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   231
    master->send_cb = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   232
    master->receive_cb = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   233
    master->cb_data = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   234
    master->app_send_cb = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   235
    master->app_receive_cb = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   236
    master->app_cb_data = NULL;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   237
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   238
    INIT_LIST_HEAD(&master->sii_requests);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   239
    INIT_LIST_HEAD(&master->emerg_reg_requests);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   240
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   241
    init_waitqueue_head(&master->request_queue);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1198
diff changeset
   242
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   243
    // init devices
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   244
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   245
            dev_idx++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   246
        ret = ec_device_init(&master->devices[dev_idx], master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   247
        if (ret < 0) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   248
            goto out_clear_devices;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   249
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   250
    }
579
17c6fd3b076e Made master devices persistent; added ec_device_attach() and ec_device_detach().
Florian Pose <fp@igh-essen.com>
parents: 578
diff changeset
   251
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
   252
    // 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
   253
    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
   254
    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
   255
    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
   256
    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
   257
        ec_datagram_clear(&master->fsm_datagram);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   258
        EC_MASTER_ERR(master, "Failed to allocate FSM datagram.\n");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   259
        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
   260
    }
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
   261
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   262
    // 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
   263
    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
   264
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   265
    // alloc external datagram ring
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   266
    for (i = 0; i < EC_EXT_RING_SIZE; i++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   267
        ec_datagram_t *datagram = &master->ext_datagram_ring[i];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   268
        ret = ec_datagram_prealloc(datagram, EC_MAX_DATA_SIZE);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   269
        if (ret) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   270
            EC_MASTER_ERR(master, "Failed to allocate external"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   271
                    " datagram %u.\n", i);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   272
            goto out_clear_ext_datagrams;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   273
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   274
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   275
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   276
    // init reference sync datagram
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   277
    ec_datagram_init(&master->ref_sync_datagram);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   278
    snprintf(master->ref_sync_datagram.name, EC_DATAGRAM_NAME_SIZE,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   279
            "refsync");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   280
    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
   281
    if (ret < 0) {
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   282
        ec_datagram_clear(&master->ref_sync_datagram);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   283
        EC_MASTER_ERR(master, "Failed to allocate reference"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   284
                " synchronisation datagram.\n");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   285
        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
   286
    }
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   287
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   288
    // 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
   289
    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
   290
    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
   291
    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
   292
    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
   293
        ec_datagram_clear(&master->sync_datagram);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   294
        EC_MASTER_ERR(master, "Failed to allocate"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   295
                " synchronisation datagram.\n");
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   296
        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
   297
    }
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   298
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   299
    // init sync monitor datagram
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   300
    ec_datagram_init(&master->sync_mon_datagram);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   301
    snprintf(master->sync_mon_datagram.name, EC_DATAGRAM_NAME_SIZE,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   302
            "syncmon");
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   303
    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
   304
    if (ret < 0) {
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   305
        ec_datagram_clear(&master->sync_mon_datagram);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   306
        EC_MASTER_ERR(master, "Failed to allocate sync"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   307
                " monitoring datagram.\n");
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   308
        goto out_clear_sync;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   309
    }
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   310
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   311
    master->dc_ref_config = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   312
    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
   313
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   314
    // init character device
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   315
    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
   316
    if (ret)
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   317
        goto out_clear_sync_mon;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   318
1369
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   319
#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
   320
    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
   321
            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
   322
            "EtherCAT%u", master->index);
61793d845ad6 Preparations to compile against 2.6.27.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   323
#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
   324
    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
   325
            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
   326
            "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
   327
#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
   328
    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
   329
            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
   330
            "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
   331
#else
1250
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   332
    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
   333
            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
   334
            "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
   335
#endif
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   336
    if (IS_ERR(master->class_device)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   337
        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
   338
        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
   339
        goto out_clear_cdev;
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   340
    }
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 140
diff changeset
   341
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   342
#ifdef EC_RTDM
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   343
    // init RTDM device
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   344
    ret = ec_rtdm_dev_init(&master->rtdm_dev, master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   345
    if (ret) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   346
        goto out_unregister_class_device;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   347
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   348
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   349
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 176
diff changeset
   350
    return 0;
226
07247920a7ba EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   351
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   352
#ifdef EC_RTDM
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   353
out_unregister_class_device:
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   354
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   355
    device_unregister(master->class_device);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   356
#else
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   357
    class_device_unregister(master->class_device);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   358
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   359
#endif
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   360
out_clear_cdev:
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   361
    ec_cdev_clear(&master->cdev);
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   362
out_clear_sync_mon:
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   363
    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
   364
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
   365
    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
   366
out_clear_ref_sync:
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1394
diff changeset
   367
    ec_datagram_clear(&master->ref_sync_datagram);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   368
out_clear_ext_datagrams:
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   369
    for (i = 0; i < EC_EXT_RING_SIZE; i++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   370
        ec_datagram_clear(&master->ext_datagram_ring[i]);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   371
    }
659
d7c5a958bad0 Removed unecessary clearing of EoE handlers in master init function;
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   372
    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
   373
    ec_datagram_clear(&master->fsm_datagram);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   374
out_clear_devices:
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   375
    for (; dev_idx > 0; dev_idx--) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   376
        ec_device_clear(&master->devices[dev_idx - 1]);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   377
    }
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   378
    return ret;
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
}
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 35
diff changeset
   381
/*****************************************************************************/
0
05c992bf5847 trunk, tags und branches
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   382
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   383
/** Destructor.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   384
*/
639
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   385
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
   386
        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
   387
        )
aa23c48dca2d Allow only MAC addresses as device identifiers; replaced master list by
Florian Pose <fp@igh-essen.com>
parents: 637
diff changeset
   388
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   389
    unsigned int dev_idx, i;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   390
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   391
#ifdef EC_RTDM
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   392
    ec_rtdm_dev_clear(&master->rtdm_dev);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   393
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   394
1250
642048176899 Applied patch by Mario Witkowski to support the new class/device
Florian Pose <fp@igh-essen.com>
parents: 1245
diff changeset
   395
#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
   396
    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
   397
#else
1013
52256b75f975 Create class device with device_number information in sysfs.
Florian Pose <fp@igh-essen.com>
parents: 1010
diff changeset
   398
    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
   399
#endif
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   400
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   401
    ec_cdev_clear(&master->cdev);
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 2040
diff changeset
   402
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   403
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   404
    ec_master_clear_eoe_handlers(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   405
#endif
994
e29edcced328 Clear domains before slave configs, because domain references the FMMU
Florian Pose <fp@igh-essen.com>
parents: 993
diff changeset
   406
    ec_master_clear_domains(master);
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   407
    ec_master_clear_slave_configs(master);
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   408
    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
   409
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
   410
    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
   411
    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
   412
    ec_datagram_clear(&master->ref_sync_datagram);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   413
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   414
    for (i = 0; i < EC_EXT_RING_SIZE; i++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   415
        ec_datagram_clear(&master->ext_datagram_ring[i]);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   416
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   417
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
   418
    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
   419
    ec_datagram_clear(&master->fsm_datagram);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   420
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   421
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   422
            dev_idx++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   423
        ec_device_clear(&master->devices[dev_idx]);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   424
    }
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   425
}
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
/*****************************************************************************/
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   428
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   429
#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
   430
/** Clear and free all EoE handlers.
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   431
 */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   432
void ec_master_clear_eoe_handlers(
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   433
        ec_master_t *master /**< EtherCAT master */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   434
        )
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   435
{
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   436
    ec_eoe_t *eoe, *next;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   437
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   438
    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
   439
        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
   440
        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
   441
        kfree(eoe);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   442
    }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   443
}
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   444
#endif
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   445
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   446
/*****************************************************************************/
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
   447
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   448
/** 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
   449
 */
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   450
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
   451
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   452
    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
   453
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   454
    master->dc_ref_config = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   455
    master->fsm.sdo_request = NULL; // mark sdo_request as invalid
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   456
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   457
    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
   458
        list_del(&sc->list);
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   459
        ec_slave_config_clear(sc);
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
   460
        kfree(sc);
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   461
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   462
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   463
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   464
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   465
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   466
/** 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
   467
 */
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   468
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
   469
{
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   470
    ec_slave_t *slave;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   471
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   472
    master->dc_ref_clock = NULL;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   473
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   474
    // External requests are obsolete, so we wake pending waiters and remove
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   475
    // them from the list.
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   476
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   477
    while (!list_empty(&master->sii_requests)) {
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   478
        ec_sii_write_request_t *request =
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   479
            list_entry(master->sii_requests.next,
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   480
                    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
   481
        list_del_init(&request->list); // dequeue
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   482
        EC_MASTER_WARN(master, "Discarding SII request, slave %u about"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   483
                " 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
   484
        request->state = EC_INT_REQUEST_FAILURE;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   485
        wake_up_all(&master->request_queue);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   486
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   487
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   488
    master->fsm_slave = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   489
    INIT_LIST_HEAD(&master->fsm_exec_list);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   490
    master->fsm_exec_count = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   491
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   492
    for (slave = master->slaves;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   493
            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
   494
            slave++) {
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   495
        ec_slave_clear(slave);
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
    if (master->slaves) {
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   499
        kfree(master->slaves);
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   500
        master->slaves = NULL;
1004
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   501
    }
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   502
990b89d8ad03 Fixed duplicate kfree() bug.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   503
    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
   504
}
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   505
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   506
/*****************************************************************************/
9bf603942791 Neues Slave-Interface, CRC-Pr?fung und mehrfaches Scannen nun ungef?hrlich.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
   507
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   508
/** Clear all domains.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   509
 */
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   510
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
   511
{
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   512
    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
   513
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   514
    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
   515
        list_del(&domain->list);
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   516
        ec_domain_clear(domain);
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
   517
        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
   518
    }
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   519
}
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   520
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   521
/*****************************************************************************/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   522
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
   523
/** 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
   524
 */
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
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
   526
        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
   527
        )
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
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   529
    down(&master->master_sem);
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
   530
    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
   531
    ec_master_clear_slave_configs(master);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   532
    up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   533
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   534
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   535
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   536
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   537
/** Internal sending callback.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   538
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   539
void ec_master_internal_send_cb(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   540
        void *cb_data /**< Callback data. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   541
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   542
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   543
    ec_master_t *master = (ec_master_t *) cb_data;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   544
    down(&master->io_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   545
    ecrt_master_send_ext(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   546
    up(&master->io_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   547
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   548
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   549
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   550
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   551
/** Internal receiving callback.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   552
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   553
void ec_master_internal_receive_cb(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   554
        void *cb_data /**< Callback data. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   555
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   556
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   557
    ec_master_t *master = (ec_master_t *) cb_data;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   558
    down(&master->io_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   559
    ecrt_master_receive(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   560
    up(&master->io_sem);
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
   561
}
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   562
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   563
/*****************************************************************************/
1ba48f78a0a5 Fixed bug that caused the configuration not to be cleared when reserved but
Florian Pose <fp@igh-essen.com>
parents: 1930
diff changeset
   564
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   565
/** Starts the master thread.
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   566
 *
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   567
 * \retval  0 Success.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   568
 * \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
   569
 */
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   570
int ec_master_thread_start(
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   571
        ec_master_t *master, /**< EtherCAT master */
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   572
        int (*thread_func)(void *), /**< thread function to start */
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   573
        const char *name /**< Thread name. */
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   574
        )
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   575
{
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   576
    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
   577
    master->thread = kthread_run(thread_func, master, name);
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   578
    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
   579
        int err = (int) PTR_ERR(master->thread);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   580
        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
   581
                err);
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   582
        master->thread = NULL;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   583
        return err;
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   584
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   585
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   586
    return 0;
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   587
}
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   588
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   589
/*****************************************************************************/
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   590
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   591
/** Stops the master thread.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   592
 */
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   593
void ec_master_thread_stop(
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   594
        ec_master_t *master /**< EtherCAT master */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   595
        )
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   596
{
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   597
    unsigned long sleep_jiffies;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   598
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   599
    if (!master->thread) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   600
        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
   601
        return;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   602
    }
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   603
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   604
    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
   605
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   606
    kthread_stop(master->thread);
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
   607
    master->thread = NULL;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   608
    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
   609
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   610
    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
   611
        return;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   612
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   613
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   614
    // wait for FSM datagram
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   615
    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
   616
    schedule_timeout(sleep_jiffies);
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   617
}
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   618
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   619
/*****************************************************************************/
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   620
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   621
/** Transition function from ORPHANED to IDLE phase.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   622
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   623
 * \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
   624
 */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   625
int ec_master_enter_idle_phase(
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   626
        ec_master_t *master /**< EtherCAT master */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   627
        )
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   628
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   629
    int ret;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   630
    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
   631
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   632
    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
   633
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   634
    master->send_cb = ec_master_internal_send_cb;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   635
    master->receive_cb = ec_master_internal_receive_cb;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   636
    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
   637
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   638
    master->phase = EC_IDLE;
2166
1d5a5303f15c Improved resetting number of responding slaves.
Florian Pose <fp@igh-essen.com>
parents: 2165
diff changeset
   639
1d5a5303f15c Improved resetting number of responding slaves.
Florian Pose <fp@igh-essen.com>
parents: 2165
diff changeset
   640
    // reset number of responding slaves to trigger scanning
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   641
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   642
            dev_idx++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   643
        master->fsm.slaves_responding[dev_idx] = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   644
    }
2166
1d5a5303f15c Improved resetting number of responding slaves.
Florian Pose <fp@igh-essen.com>
parents: 2165
diff changeset
   645
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   646
    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
   647
            "EtherCAT-IDLE");
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   648
    if (ret)
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   649
        master->phase = EC_ORPHANED;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   650
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   651
    return ret;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   652
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   653
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   654
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   655
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   656
/** Transition function from IDLE to ORPHANED phase.
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   657
 */
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   658
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
   659
{
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   660
    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
   661
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   662
    master->phase = EC_ORPHANED;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   663
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   664
#ifdef EC_EOE
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   665
    ec_master_eoe_stop(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   666
#endif
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
   667
    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
   668
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   669
    down(&master->master_sem);
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   670
    ec_master_clear_slaves(master);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   671
    up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   672
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   673
    ec_fsm_master_reset(&master->fsm);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   674
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   675
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   676
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   677
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   678
/** Transition function from IDLE to OPERATION phase.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   679
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   680
 * \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
   681
 */
2110
455126b35650 Fixed compiler error; added SDO debugging.
Florian Pose <fp@igh-essen.com>
parents: 2107
diff changeset
   682
int ec_master_enter_operation_phase(
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
   683
        ec_master_t *master /**< EtherCAT master */
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
   684
        )
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   685
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   686
    int ret = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   687
    ec_slave_t *slave;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   688
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   689
    ec_eoe_t *eoe;
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   690
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   691
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   692
    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
   693
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   694
    down(&master->config_sem);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   695
    if (master->config_busy) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   696
        up(&master->config_sem);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   697
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   698
        // 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
   699
        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
   700
                    !master->config_busy);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   701
        if (ret) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   702
            EC_MASTER_INFO(master, "Finishing slave configuration"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   703
                    " interrupted by signal.\n");
2270
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
   704
            goto out_return;
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   705
        }
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   706
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   707
        EC_MASTER_DBG(master, 1, "Waiting for pending slave"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   708
                " configuration returned.\n");
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   709
    } else {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   710
        up(&master->config_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   711
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   712
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   713
    down(&master->scan_sem);
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   714
    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
   715
    if (!master->scan_busy) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   716
        up(&master->scan_sem);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   717
    } else {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   718
        up(&master->scan_sem);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   719
794
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   720
        // wait for slave scan to complete
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   721
        ret = wait_event_interruptible(master->scan_queue,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   722
                !master->scan_busy);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   723
        if (ret) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   724
            EC_MASTER_INFO(master, "Waiting for slave scan"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   725
                    " interrupted by signal.\n");
794
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   726
            goto out_allow;
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   727
        }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   728
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   729
        EC_MASTER_DBG(master, 1, "Waiting for pending"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   730
                " slave scan returned.\n");
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   731
    }
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   732
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   733
    // 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
   734
    for (slave = master->slaves;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
   735
            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
   736
            slave++) {
643
78929d878b2c Removed X:Y addressing scheme, ec_slave_is_coupler(),
Florian Pose <fp@igh-essen.com>
parents: 640
diff changeset
   737
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   738
    }
1451
78fbafbf08ba Always set DC reference clock to OP.
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
   739
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   740
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   741
    // ... but set EoE slaves to OP
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   742
    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
   743
        if (ec_eoe_is_open(eoe))
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 659
diff changeset
   744
            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
   745
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
   746
#endif
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   747
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   748
    master->phase = EC_OPERATION;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   749
    master->app_send_cb = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   750
    master->app_receive_cb = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   751
    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
   752
    return ret;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   753
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   754
out_allow:
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   755
    master->allow_scan = 1;
2270
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
   756
out_return:
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   757
    return ret;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   758
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   759
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   760
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   761
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   762
/** Transition function from OPERATION to IDLE phase.
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   763
 */
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   764
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
   765
        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
   766
        )
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
   767
{
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
   768
    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
   769
        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
   770
    } 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
   771
        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
   772
    }
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
   773
2270
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
   774
    /* Re-allow scanning for IDLE phase. */
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
   775
    master->allow_scan = 1;
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
   776
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
   777
    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
   778
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   779
    master->phase = EC_IDLE;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   780
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   781
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
   782
/*****************************************************************************/
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
   783
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   784
/** Injects external datagrams that fit into the datagram queue.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   785
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   786
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
   787
        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
   788
        )
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
   789
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   790
    ec_datagram_t *datagram;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   791
    size_t queue_size = 0, new_queue_size = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   792
#if DEBUG_INJECT
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   793
    unsigned int datagram_count = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   794
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   795
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   796
    if (master->ext_ring_idx_rt == master->ext_ring_idx_fsm) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   797
        // nothing to inject
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   798
        return;
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2084
diff changeset
   799
    }
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2084
diff changeset
   800
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
   801
    list_for_each_entry(datagram, &master->datagram_queue, queue) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   802
        if (datagram->state == EC_DATAGRAM_QUEUED) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   803
            queue_size += datagram->data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   804
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   805
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   806
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   807
#if DEBUG_INJECT
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   808
    EC_MASTER_DBG(master, 1, "Injecting datagrams, queue_size=%zu\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   809
            queue_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   810
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   811
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   812
    while (master->ext_ring_idx_rt != master->ext_ring_idx_fsm) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   813
        datagram = &master->ext_datagram_ring[master->ext_ring_idx_rt];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   814
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   815
        if (datagram->state != EC_DATAGRAM_INIT) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   816
            // skip datagram
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   817
            master->ext_ring_idx_rt =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   818
                (master->ext_ring_idx_rt + 1) % EC_EXT_RING_SIZE;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   819
            continue;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   820
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   821
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   822
        new_queue_size = queue_size + datagram->data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   823
        if (new_queue_size <= master->max_queue_size) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   824
#if DEBUG_INJECT
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   825
            EC_MASTER_DBG(master, 1, "Injecting datagram %s"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   826
                    " size=%zu, queue_size=%zu\n", datagram->name,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   827
                    datagram->data_size, new_queue_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   828
            datagram_count++;
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   829
#endif
1585
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
   830
#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
   831
            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
   832
#endif
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   833
            datagram->jiffies_sent = 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
   834
            ec_master_queue_datagram(master, datagram);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   835
            queue_size = new_queue_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   836
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   837
        else if (datagram->data_size > master->max_queue_size) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   838
            datagram->state = EC_DATAGRAM_ERROR;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   839
            EC_MASTER_ERR(master, "External datagram %s is too large,"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   840
                    " size=%zu, max_queue_size=%zu\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   841
                    datagram->name, datagram->data_size,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   842
                    master->max_queue_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   843
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   844
        else { // datagram does not fit in the current cycle
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   845
#ifdef EC_HAVE_CYCLES
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   846
            cycles_t cycles_now = get_cycles();
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   847
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   848
            if (cycles_now - datagram->cycles_sent
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   849
                    > ext_injection_timeout_cycles)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   850
#else
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   851
            if (jiffies - datagram->jiffies_sent
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   852
                    > ext_injection_timeout_jiffies)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   853
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   854
            {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   855
#if defined EC_RT_SYSLOG || DEBUG_INJECT
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   856
                unsigned int time_us;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   857
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   858
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
   859
                datagram->state = EC_DATAGRAM_ERROR;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   860
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   861
#if defined EC_RT_SYSLOG || DEBUG_INJECT
1585
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
   862
#ifdef EC_HAVE_CYCLES
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   863
                time_us = (unsigned int)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   864
                    ((cycles_now - datagram->cycles_sent) * 1000LL)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   865
                    / cpu_khz;
1585
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
   866
#else
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   867
                time_us = (unsigned int)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   868
                    ((jiffies - datagram->jiffies_sent) * 1000000 / HZ);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   869
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   870
                EC_MASTER_ERR(master, "Timeout %u us: Injecting"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   871
                        " external datagram %s size=%zu,"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   872
                        " max_queue_size=%zu\n", time_us, datagram->name,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   873
                        datagram->data_size, master->max_queue_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   874
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   875
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   876
            else {
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   877
#if DEBUG_INJECT
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   878
                EC_MASTER_DBG(master, 1, "Deferred injecting"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   879
                        " external datagram %s size=%u, queue_size=%u\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   880
                        datagram->name, datagram->data_size, queue_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   881
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   882
                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
   883
            }
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
   884
        }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   885
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   886
        master->ext_ring_idx_rt =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   887
            (master->ext_ring_idx_rt + 1) % EC_EXT_RING_SIZE;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   888
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   889
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   890
#if DEBUG_INJECT
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   891
    EC_MASTER_DBG(master, 1, "Injected %u datagrams.\n", datagram_count);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   892
#endif
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
/*****************************************************************************/
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   896
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   897
/** 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
   898
 * 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
   899
 */
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   900
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
   901
        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
   902
        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
   903
        )
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   904
{
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
   905
    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
   906
    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
   907
        (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
   908
    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
   909
}
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
   910
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
   911
/*****************************************************************************/
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
   912
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   913
/** Searches for a free datagram in the external datagram ring.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   914
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   915
 * \return Next free datagram, or NULL.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   916
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   917
ec_datagram_t *ec_master_get_external_datagram(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   918
        ec_master_t *master /**< EtherCAT master */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   919
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   920
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   921
    if ((master->ext_ring_idx_fsm + 1) % EC_EXT_RING_SIZE !=
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   922
            master->ext_ring_idx_rt) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   923
        ec_datagram_t *datagram =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   924
            &master->ext_datagram_ring[master->ext_ring_idx_fsm];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   925
        return datagram;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   926
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   927
    else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   928
        return NULL;
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2084
diff changeset
   929
    }
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
   930
}
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
   931
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   932
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 444
diff changeset
   933
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
   934
/** 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
   935
 */
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   936
void ec_master_queue_datagram(
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   937
        ec_master_t *master, /**< EtherCAT master */
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   938
        ec_datagram_t *datagram /**< datagram */
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   939
        )
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   940
{
2084
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   941
    ec_datagram_t *queued_datagram;
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   942
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   943
    /* It is possible, that a datagram in the queue is re-initialized with the
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   944
     * ec_datagram_<type>() methods and then shall be queued with this method.
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   945
     * In that case, the state is already reset to EC_DATAGRAM_INIT. Check if
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   946
     * the datagram is queued to avoid duplicate queuing (which results in an
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   947
     * infinite loop!). Set the state to EC_DATAGRAM_QUEUED again, probably
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   948
     * causing an unmatched datagram. */
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   949
    list_for_each_entry(queued_datagram, &master->datagram_queue, queue) {
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   950
        if (queued_datagram == datagram) {
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   951
            datagram->skip_count++;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   952
#ifdef EC_RT_SYSLOG
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   953
            EC_MASTER_DBG(master, 1,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   954
                    "Datagram %p already queued (skipping).\n", datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   955
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   956
            datagram->state = EC_DATAGRAM_QUEUED;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   957
            return;
2084
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   958
        }
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   959
    }
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   960
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   961
    list_add_tail(&datagram->queue, &master->datagram_queue);
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   962
    datagram->state = EC_DATAGRAM_QUEUED;
eefccfa312ef Fixed bug in ec_master_queue_datagram() introduced in c9d32805d984.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   963
}
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
   964
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   967
/** Places a datagram in the non-application datagram queue.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   968
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   969
void ec_master_queue_datagram_ext(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   970
        ec_master_t *master, /**< EtherCAT master */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   971
        ec_datagram_t *datagram /**< datagram */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   972
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   973
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   974
    down(&master->ext_queue_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   975
    list_add_tail(&datagram->queue, &master->ext_datagram_queue);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   976
    up(&master->ext_queue_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   977
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   978
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   979
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   980
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   981
/** Sends the datagrams in the queue for a certain device.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   982
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   983
 */
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
   984
size_t ec_master_send_datagrams(
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   985
        ec_master_t *master, /**< EtherCAT master */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   986
        ec_device_index_t device_index /**< Device index. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   987
        )
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   988
{
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   989
    ec_datagram_t *datagram, *next;
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
   990
    size_t datagram_size;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
   991
    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
   992
    void *follows_word;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   993
#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
   994
    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
   995
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   996
    unsigned long jiffies_sent;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   997
    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
   998
    struct list_head sent_datagrams;
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
   999
    size_t sent_bytes = 0;
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1000
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1001
#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
  1002
    cycles_start = get_cycles();
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1003
#endif
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1004
    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
  1005
    INIT_LIST_HEAD(&sent_datagrams);
208
b7797f8a813d command timeout, EoE processing with kernel timer.
Florian Pose <fp@igh-essen.com>
parents: 206
diff changeset
  1006
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1007
    EC_MASTER_DBG(master, 2, "%s(device_index = %u)\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1008
            __func__, device_index);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1009
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1010
    do {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1011
        frame_data = NULL;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1012
        follows_word = NULL;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1013
        more_datagrams_waiting = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1014
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1015
        // fill current frame with datagrams
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1016
        list_for_each_entry(datagram, &master->datagram_queue, queue) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1017
            if (datagram->state != EC_DATAGRAM_QUEUED ||
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1018
                    datagram->device_index != device_index) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1019
                continue;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1020
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1021
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1022
            if (!frame_data) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1023
                // fetch pointer to transmit socket buffer
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1024
                frame_data =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1025
                    ec_device_tx_data(&master->devices[device_index]);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1026
                cur_data = frame_data + EC_FRAME_HEADER_SIZE;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1027
            }
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1028
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1029
            // does the current datagram fit in the frame?
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1030
            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
  1031
                + EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1032
            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
  1033
                more_datagrams_waiting = 1;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1034
                break;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1035
            }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1036
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1037
            list_add_tail(&datagram->sent, &sent_datagrams);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1038
            datagram->index = master->datagram_index++;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1039
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1040
            EC_MASTER_DBG(master, 2, "Adding datagram 0x%02X\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1041
                    datagram->index);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1042
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1043
            // set "datagram following" flag in previous datagram
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2084
diff changeset
  1044
            if (follows_word) {
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2084
diff changeset
  1045
                EC_WRITE_U16(follows_word,
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2084
diff changeset
  1046
                        EC_READ_U16(follows_word) | 0x8000);
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2084
diff changeset
  1047
            }
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1048
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1049
            // EtherCAT datagram header
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1050
            EC_WRITE_U8 (cur_data, datagram->type);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1051
            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
  1052
            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
  1053
            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
  1054
            EC_WRITE_U16(cur_data + 8, 0x0000);
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1055
            follows_word = cur_data + 6;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1056
            cur_data += EC_DATAGRAM_HEADER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1057
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1058
            // EtherCAT datagram data
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1059
            memcpy(cur_data, datagram->data, datagram->data_size);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1060
            cur_data += datagram->data_size;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1061
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1062
            // EtherCAT datagram footer
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1063
            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
  1064
            cur_data += EC_DATAGRAM_FOOTER_SIZE;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1065
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1066
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1067
        if (list_empty(&sent_datagrams)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1068
            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
  1069
            break;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1070
        }
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1071
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1072
        // EtherCAT frame header
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1073
        EC_WRITE_U16(frame_data, ((cur_data - frame_data
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1074
                        - EC_FRAME_HEADER_SIZE) & 0x7FF) | 0x1000);
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1075
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1076
        // pad frame
211
c684b6b7adaf Using kernel Ethernet constants.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
  1077
        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
  1078
            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
  1079
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1080
        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
  1081
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1082
        // send frame
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1083
        ec_device_send(&master->devices[device_index],
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1084
                cur_data - frame_data);
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  1085
        /* preamble and inter-frame gap */
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  1086
        sent_bytes += ETH_HLEN + cur_data - frame_data + ETH_FCS_LEN + 20;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1087
#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
  1088
        cycles_sent = get_cycles();
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1089
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1090
        jiffies_sent = jiffies;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1091
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1092
        // 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
  1093
        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
  1094
            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
  1095
#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
  1096
            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
  1097
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1098
            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
  1099
            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
  1100
        }
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
  1101
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1102
        frame_count++;
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1103
    }
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  1104
    while (more_datagrams_waiting && frame_count < EC_TX_RING_SIZE);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1105
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1106
#ifdef EC_HAVE_CYCLES
303
03fd45bc13ef SysFS entry for debug level.
Florian Pose <fp@igh-essen.com>
parents: 298
diff changeset
  1107
    if (unlikely(master->debug_level > 1)) {
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1108
        cycles_end = get_cycles();
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1109
        EC_MASTER_DBG(master, 0, "%s()"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1110
                " 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
  1111
               (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
  1112
    }
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  1113
#endif
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  1114
    return sent_bytes;
176
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1115
}
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1116
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1117
/*****************************************************************************/
1ac0fc378b95 Sending of multiple frames
Florian Pose <fp@igh-essen.com>
parents: 173
diff changeset
  1118
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1119
/** Processes a received frame.
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1120
 *
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1121
 * This function is called by the network driver for every received frame.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1122
 *
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1123
 * \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
  1124
 */
2103
8c63d804ead9 Fixed spacing and added some thoughts about the overlapping PDOs
Florian Pose <fp@igh-essen.com>
parents: 2095
diff changeset
  1125
void ec_master_receive_datagrams(
8c63d804ead9 Fixed spacing and added some thoughts about the overlapping PDOs
Florian Pose <fp@igh-essen.com>
parents: 2095
diff changeset
  1126
        ec_master_t *master, /**< EtherCAT master */
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1127
        ec_device_t *device, /**< EtherCAT device */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1128
        const uint8_t *frame_data, /**< frame data */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1129
        size_t size /**< size of the received data */
2103
8c63d804ead9 Fixed spacing and added some thoughts about the overlapping PDOs
Florian Pose <fp@igh-essen.com>
parents: 2095
diff changeset
  1130
        )
98
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
    size_t frame_size, data_size;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1133
    uint8_t datagram_type, datagram_index;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1134
    unsigned int cmd_follows, matched;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1135
    const uint8_t *cur_data;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1136
    ec_datagram_t *datagram;
98
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(size < EC_FRAME_HEADER_SIZE)) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1139
        if (master->debug_level || FORCE_OUTPUT_CORRUPTED) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1140
            EC_MASTER_DBG(master, 0, "Corrupted frame received"
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1141
                    " on %s (size %zu < %u byte):\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1142
                    device->dev->name, size, EC_FRAME_HEADER_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++;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1146
#ifdef EC_RT_SYSLOG
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1147
        ec_master_output_stats(master);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1148
#endif
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1149
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1150
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1151
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1152
    cur_data = frame_data;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1153
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1154
    // 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
  1155
    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
  1156
    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
  1157
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1158
    if (unlikely(frame_size > size)) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1159
        if (master->debug_level || FORCE_OUTPUT_CORRUPTED) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1160
            EC_MASTER_DBG(master, 0, "Corrupted frame received"
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1161
                    " on %s (invalid frame size %zu for "
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1162
                    "received size %zu):\n", device->dev->name,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1163
                    frame_size, 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++;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1167
#ifdef EC_RT_SYSLOG
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1168
        ec_master_output_stats(master);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1169
#endif
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1170
        return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1171
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1172
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1173
    cmd_follows = 1;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1174
    while (cmd_follows) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1175
        // process datagram header
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1176
        datagram_type  = EC_READ_U8 (cur_data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1177
        datagram_index = EC_READ_U8 (cur_data + 1);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1178
        data_size      = EC_READ_U16(cur_data + 6) & 0x07FF;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1179
        cmd_follows    = EC_READ_U16(cur_data + 6) & 0x8000;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1180
        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
  1181
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1182
        if (unlikely(cur_data - frame_data
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1183
                     + data_size + EC_DATAGRAM_FOOTER_SIZE > size)) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1184
            if (master->debug_level || FORCE_OUTPUT_CORRUPTED) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1185
                EC_MASTER_DBG(master, 0, "Corrupted frame received"
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1186
                        " on %s (invalid data size %zu):\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1187
                        device->dev->name, data_size);
1303
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1188
                ec_print_data(frame_data, size);
448f2e9fa483 Output corrupted frame reasons.
Florian Pose <fp@igh-essen.com>
parents: 1279
diff changeset
  1189
            }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1190
            master->stats.corrupted++;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1191
#ifdef EC_RT_SYSLOG
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1192
            ec_master_output_stats(master);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1193
#endif
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1194
            return;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1195
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1196
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1197
        // 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
  1198
        matched = 0;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1199
        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
  1200
            if (datagram->index == datagram_index
5e231f6a3d2e Re-ordered criteria for datagram matching.
Florian Pose <fp@igh-essen.com>
parents: 688
diff changeset
  1201
                && datagram->state == EC_DATAGRAM_SENT
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1202
                && datagram->type == datagram_type
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1203
                && 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
  1204
                matched = 1;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1205
                break;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1206
            }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1207
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1208
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1209
        // 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
  1210
        if (!matched) {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1211
            master->stats.unmatched++;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1212
#ifdef EC_RT_SYSLOG
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1213
            ec_master_output_stats(master);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1214
#endif
684
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1215
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1216
            if (unlikely(master->debug_level > 0)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1217
                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
  1218
                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
  1219
                        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
  1220
                        + 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
  1221
#ifdef EC_DEBUG_RING
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1222
                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
  1223
#endif
684
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1224
            }
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  1225
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1226
            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
  1227
            continue;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1228
        }
2103
8c63d804ead9 Fixed spacing and added some thoughts about the overlapping PDOs
Florian Pose <fp@igh-essen.com>
parents: 2095
diff changeset
  1229
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1230
        if (datagram->type != EC_DATAGRAM_APWR &&
2116
1448a40b5af5 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2110
diff changeset
  1231
                datagram->type != EC_DATAGRAM_FPWR &&
1448a40b5af5 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2110
diff changeset
  1232
                datagram->type != EC_DATAGRAM_BWR &&
1448a40b5af5 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2110
diff changeset
  1233
                datagram->type != EC_DATAGRAM_LWR) {
1448a40b5af5 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2110
diff changeset
  1234
            // copy received data into the datagram memory,
1448a40b5af5 Don not copy frame data to datagram memory, if datagram type is write-only.
Florian Pose <fp@igh-essen.com>
parents: 2110
diff changeset
  1235
            // if something has been read
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1236
            memcpy(datagram->data, cur_data, data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1237
        }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1238
        cur_data += data_size;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1239
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1240
        // set the datagram's working counter
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1241
        datagram->working_counter = EC_READ_U16(cur_data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1242
        cur_data += EC_DATAGRAM_FOOTER_SIZE;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1243
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1244
        // 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
  1245
        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
  1246
#ifdef EC_HAVE_CYCLES
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1247
        datagram->cycles_received =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1248
            master->devices[EC_DEVICE_MAIN].cycles_poll;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1249
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1250
        datagram->jiffies_received =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1251
            master->devices[EC_DEVICE_MAIN].jiffies_poll;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1252
        list_del_init(&datagram->queue);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1253
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1254
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1255
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1256
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1257
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
  1258
/** Output master statistics.
997
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1259
 *
652180478e95 Removed kobject from master and module. Sysfs is gone!
Florian Pose <fp@igh-essen.com>
parents: 995
diff changeset
  1260
 * 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
  1261
 * 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
  1262
 */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
  1263
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
  1264
{
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1265
    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
  1266
        master->stats.output_jiffies = jiffies;
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 341
diff changeset
  1267
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1268
        if (master->stats.timeouts) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1269
            EC_MASTER_WARN(master, "%u datagram%s TIMED OUT!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1270
                    master->stats.timeouts,
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
  1271
                    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
  1272
            master->stats.timeouts = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1273
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1274
        if (master->stats.corrupted) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1275
            EC_MASTER_WARN(master, "%u frame%s CORRUPTED!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1276
                    master->stats.corrupted,
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
  1277
                    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
  1278
            master->stats.corrupted = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1279
        }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1280
        if (master->stats.unmatched) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1281
            EC_MASTER_WARN(master, "%u datagram%s UNMATCHED!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1282
                    master->stats.unmatched,
396
189909f92019 Minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 382
diff changeset
  1283
                    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
  1284
            master->stats.unmatched = 0;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 95
diff changeset
  1285
        }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 68
diff changeset
  1286
    }
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1287
}
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
  1288
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1289
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1290
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1291
/** Clears the common device statistics.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1292
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1293
void ec_master_clear_device_stats(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1294
        ec_master_t *master /**< EtherCAT master */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1295
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1296
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1297
    unsigned int i;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1298
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1299
    // zero frame statistics
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1300
    master->device_stats.tx_count = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1301
    master->device_stats.last_tx_count = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1302
    master->device_stats.rx_count = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1303
    master->device_stats.last_rx_count = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1304
    master->device_stats.tx_bytes = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1305
    master->device_stats.last_tx_bytes = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1306
    master->device_stats.rx_bytes = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1307
    master->device_stats.last_rx_bytes = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1308
    master->device_stats.last_loss = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1309
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1310
    for (i = 0; i < EC_RATE_COUNT; i++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1311
        master->device_stats.tx_frame_rates[i] = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1312
        master->device_stats.tx_byte_rates[i] = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1313
        master->device_stats.loss_rates[i] = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1314
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1315
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1316
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1317
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1318
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1319
/** Updates the common device statistics.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1320
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1321
void ec_master_update_device_stats(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1322
        ec_master_t *master /**< EtherCAT master */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1323
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1324
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1325
    ec_device_stats_t *s = &master->device_stats;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1326
    s32 tx_frame_rate, rx_frame_rate, tx_byte_rate, rx_byte_rate, loss_rate;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1327
    u64 loss;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1328
    unsigned int i, dev_idx;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1329
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1330
    // frame statistics
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1331
    if (likely(jiffies - s->jiffies < HZ)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1332
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1333
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1334
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1335
    tx_frame_rate = (s->tx_count - s->last_tx_count) * 1000;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1336
    rx_frame_rate = (s->rx_count - s->last_rx_count) * 1000;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1337
    tx_byte_rate = s->tx_bytes - s->last_tx_bytes;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1338
    rx_byte_rate = s->rx_bytes - s->last_rx_bytes;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1339
    loss = s->tx_count - s->rx_count;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1340
    loss_rate = (loss - s->last_loss) * 1000;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1341
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1342
    /* Low-pass filter:
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1343
     *      Y_n = y_(n - 1) + T / tau * (x - y_(n - 1))   | T = 1
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1344
     *   -> Y_n += (x - y_(n - 1)) / tau
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1345
     */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1346
    for (i = 0; i < EC_RATE_COUNT; i++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1347
        s32 n = rate_intervals[i];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1348
        s->tx_frame_rates[i] += (tx_frame_rate - s->tx_frame_rates[i]) / n;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1349
        s->rx_frame_rates[i] += (rx_frame_rate - s->rx_frame_rates[i]) / n;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1350
        s->tx_byte_rates[i] += (tx_byte_rate - s->tx_byte_rates[i]) / n;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1351
        s->rx_byte_rates[i] += (rx_byte_rate - s->rx_byte_rates[i]) / n;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1352
        s->loss_rates[i] += (loss_rate - s->loss_rates[i]) / n;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1353
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1354
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1355
    s->last_tx_count = s->tx_count;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1356
    s->last_rx_count = s->rx_count;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1357
    s->last_tx_bytes = s->tx_bytes;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1358
    s->last_rx_bytes = s->rx_bytes;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1359
    s->last_loss = loss;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1360
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1361
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1362
            dev_idx++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1363
        ec_device_update_stats(&master->devices[dev_idx]);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1364
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1365
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1366
    s->jiffies = jiffies;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1367
}
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1368
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1369
/*****************************************************************************/
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
  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
#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
  1372
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1373
/*
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1374
 * Sleep related functions:
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1375
 */
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1376
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
  1377
{
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
  1378
    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
  1379
        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
  1380
    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
  1381
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
  1382
    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
  1383
    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
  1384
        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
  1385
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
    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
  1387
}
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
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
/*****************************************************************************/
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1390
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,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
  1392
1603
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1393
/* 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
  1394
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
  1395
{
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
    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
  1397
}
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
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
/*****************************************************************************/
1603
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1400
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1401
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
  1402
{
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
  1403
    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
  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
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
#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
  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
/*****************************************************************************/
1603
8e528f806dc5 fix build for recent kernel versions (tested with 2.6.31)
Matthias Luescher <ch1010472@ch10lt140>
parents: 1600
diff changeset
  1409
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1410
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
  1411
{
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
  1412
    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
  1413
    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
  1414
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
  1415
    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
  1416
    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
  1417
    t.task = current;
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1418
#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
  1419
#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
  1420
    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
  1421
#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
  1422
    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
  1423
#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
  1424
    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
  1425
#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
  1426
#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
  1427
    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
  1428
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
  1429
    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
  1430
        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
  1431
        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
  1432
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
  1433
        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
  1434
            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
  1435
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
  1436
        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
  1437
        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
  1438
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
  1439
    } 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
  1440
}
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
  1441
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
  1442
#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
  1443
68
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
  1444
/*****************************************************************************/
a452700db994 Neue ASCII-Adressierung und Code-Dokumantation.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
  1445
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1446
/** Execute slave FSMs.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1447
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1448
void ec_master_exec_slave_fsms(
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1449
        ec_master_t *master /**< EtherCAT master. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1450
        )
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1451
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1452
    ec_datagram_t *datagram;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1453
    ec_fsm_slave_t *fsm, *next;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1454
    unsigned int count = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1455
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1456
    list_for_each_entry_safe(fsm, next, &master->fsm_exec_list, list) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1457
        if (!fsm->datagram) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1458
            EC_MASTER_WARN(master, "Slave %u FSM has zero datagram."
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1459
                    "This is a bug!\n", fsm->slave->ring_position);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1460
            list_del_init(&fsm->list);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1461
            master->fsm_exec_count--;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1462
            return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1463
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1464
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1465
        if (fsm->datagram->state == EC_DATAGRAM_INIT ||
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1466
                fsm->datagram->state == EC_DATAGRAM_QUEUED ||
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1467
                fsm->datagram->state == EC_DATAGRAM_SENT) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1468
            // previous datagram was not sent or received yet.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1469
            // wait until next thread execution
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1470
            return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1471
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1472
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1473
        datagram = ec_master_get_external_datagram(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1474
        if (!datagram) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1475
            // no free datagrams at the moment
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1476
            EC_MASTER_WARN(master, "No free datagram during"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1477
                    " slave FSM execution. This is a bug!\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1478
            continue;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1479
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1480
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1481
#if DEBUG_INJECT
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1482
        EC_MASTER_DBG(master, 1, "Executing slave %u FSM.\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1483
                fsm->slave->ring_position);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1484
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1485
        if (ec_fsm_slave_exec(fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1486
            // FSM consumed datagram
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1487
#if DEBUG_INJECT
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1488
            EC_MASTER_DBG(master, 1, "FSM consumed datagram %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1489
                    datagram->name);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1490
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1491
            master->ext_ring_idx_fsm =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1492
                (master->ext_ring_idx_fsm + 1) % EC_EXT_RING_SIZE;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1493
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1494
        else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1495
            // FSM finished
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1496
            list_del_init(&fsm->list);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1497
            master->fsm_exec_count--;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1498
#if DEBUG_INJECT
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1499
            EC_MASTER_DBG(master, 1, "FSM finished. %u remaining.\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1500
                    master->fsm_exec_count);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1501
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1502
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1503
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1504
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1505
    while (master->fsm_exec_count < EC_EXT_RING_SIZE / 2
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1506
            && count < master->slave_count) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1507
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1508
        if (ec_fsm_slave_is_ready(&master->fsm_slave->fsm)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1509
            datagram = ec_master_get_external_datagram(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1510
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1511
            if (ec_fsm_slave_exec(&master->fsm_slave->fsm, datagram)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1512
                master->ext_ring_idx_fsm =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1513
                    (master->ext_ring_idx_fsm + 1) % EC_EXT_RING_SIZE;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1514
                list_add_tail(&master->fsm_slave->fsm.list,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1515
                        &master->fsm_exec_list);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1516
                master->fsm_exec_count++;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1517
#if DEBUG_INJECT
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1518
                EC_MASTER_DBG(master, 1, "New slave %u FSM"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1519
                        " consumed datagram %s, now %u FSMs in list.\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1520
                        master->fsm_slave->ring_position, datagram->name,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1521
                        master->fsm_exec_count);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1522
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1523
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1524
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1525
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1526
        master->fsm_slave++;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1527
        if (master->fsm_slave >= master->slaves + master->slave_count) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1528
            master->fsm_slave = master->slaves;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1529
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1530
        count++;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1531
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1532
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1533
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1534
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1535
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
  1536
/** 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
  1537
 */
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1538
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
  1539
{
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1540
    ec_master_t *master = (ec_master_t *) priv_data;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1541
    int fsm_exec;
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1542
    size_t sent_bytes;
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2084
diff changeset
  1543
1774
a9143f82c7c5 Fixed name of byte transmission time define; changed coding style.
Florian Pose <fp@igh-essen.com>
parents: 1773
diff changeset
  1544
    // send interval in IDLE phase
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1545
    ec_master_set_send_interval(master, 1000000 / HZ);
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1546
1930
59a50053ccc6 Made send_interval variable an unsigned int; fixed format specifiers for
Florian Pose <fp@igh-essen.com>
parents: 1925
diff changeset
  1547
    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
  1548
            " max data size=%zu\n", master->send_interval,
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1549
            master->max_queue_size);
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1550
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1551
    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
  1552
        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
  1553
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1554
        // receive
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1555
        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
  1556
        ecrt_master_receive(master);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1557
        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
  1558
2018
6c05411fee9b replaced injection_seq mechanism with fsm datagram queue
Martin Troxler <ch1010277@ch10pc446>
parents: 2017
diff changeset
  1559
        // execute master & slave state machines
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1560
        if (down_interruptible(&master->master_sem)) {
2018
6c05411fee9b replaced injection_seq mechanism with fsm datagram queue
Martin Troxler <ch1010277@ch10pc446>
parents: 2017
diff changeset
  1561
            break;
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2084
diff changeset
  1562
        }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1563
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1564
        fsm_exec = ec_fsm_master_exec(&master->fsm);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1565
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1566
        ec_master_exec_slave_fsms(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1567
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1568
        up(&master->master_sem);
2018
6c05411fee9b replaced injection_seq mechanism with fsm datagram queue
Martin Troxler <ch1010277@ch10pc446>
parents: 2017
diff changeset
  1569
2017
4b16e2dce5fb Increment injection_seq on slave state changes
Martin Troxler <ch1010277@ch10pc446>
parents: 2016
diff changeset
  1570
        // queue and send
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1571
        down(&master->io_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1572
        if (fsm_exec) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1573
            ec_master_queue_datagram(master, &master->fsm_datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1574
        }
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  1575
        sent_bytes = ecrt_master_send(master);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1576
        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
  1577
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1578
        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
  1579
#ifdef EC_USE_HRTIMER
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1580
            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
  1581
#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
  1582
            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
  1583
            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
  1584
#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
  1585
        } 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
  1586
#ifdef EC_USE_HRTIMER
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  1587
            ec_master_nanosleep(
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  1588
                    sent_bytes * EC_BYTE_TRANSMISSION_TIME_NS * 6 / 5);
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
  1589
#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
  1590
            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
  1591
#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
  1592
        }
525
8b20781bd1e0 Master workqueue replaced with kernel thread.
Florian Pose <fp@igh-essen.com>
parents: 524
diff changeset
  1593
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1594
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1595
    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
  1596
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1597
    return 0;
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1598
}
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 188
diff changeset
  1599
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1600
/*****************************************************************************/
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1601
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
  1602
/** 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
  1603
 */
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1604
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
  1605
{
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1606
    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
  1607
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1608
    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
  1609
            " 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
  1610
            master->send_interval, master->max_queue_size);
1241
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1611
794cbccdcd00 Moved threads to kthread interface.
Florian Pose <fp@igh-essen.com>
parents: 1237
diff changeset
  1612
    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
  1613
        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
  1614
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1615
        if (master->injection_seq_rt == master->injection_seq_fsm) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1616
            // output statistics
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1617
            ec_master_output_stats(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1618
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1619
            // execute master & slave state machines
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1620
            if (down_interruptible(&master->master_sem)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1621
                break;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1622
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1623
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1624
            if (ec_fsm_master_exec(&master->fsm)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1625
                // Inject datagrams (let the RT thread queue them, see
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1626
                // ecrt_master_send())
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1627
                master->injection_seq_fsm++;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1628
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1629
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1630
            ec_master_exec_slave_fsms(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1631
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1632
            up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1633
        }
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
  1634
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
  1635
#ifdef EC_USE_HRTIMER
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1636
        // 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
  1637
        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
  1638
#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
  1639
        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
  1640
            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
  1641
            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
  1642
        }
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
  1643
        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
  1644
            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
  1645
        }
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
  1646
#endif
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1774
diff changeset
  1647
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1648
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  1649
    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
  1650
    return 0;
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
  1651
}
578
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1652
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1653
/*****************************************************************************/
f402b4bd2f4d Removed ktype for module kobject; added backup device for master; device
Florian Pose <fp@igh-essen.com>
parents: 576
diff changeset
  1654
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 714
diff changeset
  1655
#ifdef EC_EOE
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1656
/** Starts Ethernet over EtherCAT processing on demand.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1657
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1658
void ec_master_eoe_start(ec_master_t *master /**< EtherCAT master */)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1659
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1660
    struct sched_param param = { .sched_priority = 0 };
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1661
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1662
    if (master->eoe_thread) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1663
        EC_MASTER_WARN(master, "EoE already running!\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1664
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1665
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1666
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1667
    if (list_empty(&master->eoe_handlers))
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1668
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1669
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1670
    if (!master->send_cb || !master->receive_cb) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1671
        EC_MASTER_WARN(master, "No EoE processing"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1672
                " because of missing callbacks!\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1673
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1674
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1675
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1676
    EC_MASTER_INFO(master, "Starting EoE thread.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1677
    master->eoe_thread = kthread_run(ec_master_eoe_thread, master,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1678
            "EtherCAT-EoE");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1679
    if (IS_ERR(master->eoe_thread)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1680
        int err = (int) PTR_ERR(master->eoe_thread);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1681
        EC_MASTER_ERR(master, "Failed to start EoE thread (error %i)!\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1682
                err);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1683
        master->eoe_thread = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1684
        return;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1685
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1686
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1687
    sched_setscheduler(master->eoe_thread, SCHED_NORMAL, &param);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1688
    set_user_nice(master->eoe_thread, 0);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1689
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1690
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1691
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1692
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1693
/** Stops the Ethernet over EtherCAT processing.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1694
 */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1695
void ec_master_eoe_stop(ec_master_t *master /**< EtherCAT master */)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1696
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1697
    if (master->eoe_thread) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1698
        EC_MASTER_INFO(master, "Stopping EoE thread.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1699
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1700
        kthread_stop(master->eoe_thread);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1701
        master->eoe_thread = NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1702
        EC_MASTER_INFO(master, "EoE thread exited.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1703
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1704
}
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1705
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1706
/*****************************************************************************/
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1707
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1708
/** 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
  1709
 */
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1710
static int ec_master_eoe_thread(void *priv_data)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1711
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1712
    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
  1713
    ec_eoe_t *eoe;
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1714
    unsigned int none_open, sth_to_send, all_idle;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1715
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1716
    EC_MASTER_DBG(master, 1, "EoE thread running.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1717
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1718
    while (!kthread_should_stop()) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1719
        none_open = 1;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1720
        all_idle = 1;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1721
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1722
        list_for_each_entry(eoe, &master->eoe_handlers, list) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1723
            if (ec_eoe_is_open(eoe)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1724
                none_open = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1725
                break;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1726
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1727
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1728
        if (none_open)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1729
            goto schedule;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1730
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1731
        // receive datagrams
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1732
        master->receive_cb(master->cb_data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1733
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1734
        // actual EoE processing
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1735
        sth_to_send = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1736
        list_for_each_entry(eoe, &master->eoe_handlers, list) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1737
            ec_eoe_run(eoe);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1738
            if (eoe->queue_datagram) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1739
                sth_to_send = 1;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1740
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1741
            if (!ec_eoe_is_idle(eoe)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1742
                all_idle = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1743
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1744
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1745
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1746
        if (sth_to_send) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1747
            list_for_each_entry(eoe, &master->eoe_handlers, list) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1748
                ec_eoe_queue(eoe);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1749
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1750
            // (try to) send datagrams
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1751
            down(&master->ext_queue_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1752
            master->send_cb(master->cb_data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1753
            up(&master->ext_queue_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1754
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1755
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1756
schedule:
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1757
        if (all_idle) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1758
            set_current_state(TASK_INTERRUPTIBLE);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1759
            schedule_timeout(1);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1760
        } else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1761
            schedule();
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1762
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1763
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1764
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1765
    EC_MASTER_DBG(master, 1, "EoE thread exiting...\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1766
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1767
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1768
#endif
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1769
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1770
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1771
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1772
/** 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
  1773
 */
1028
afdd4bdbb7ec Removed configs_attached flag; changed return value of
Florian Pose <fp@igh-essen.com>
parents: 1024
diff changeset
  1774
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
  1775
        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
  1776
        )
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1777
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1778
    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
  1779
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  1780
    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
  1781
        ec_slave_config_attach(sc);
afdd4bdbb7ec Removed configs_attached flag; changed return value of
Florian Pose <fp@igh-essen.com>
parents: 1024
diff changeset
  1782
    }
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1783
}
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
  1784
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1785
/*****************************************************************************/
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1786
2620
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1787
/** Abort active requests for slave configs without attached slaves.
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1788
 */
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1789
void ec_master_expire_slave_config_requests(
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1790
        ec_master_t *master /**< EtherCAT master. */
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1791
        )
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1792
{
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1793
    ec_slave_config_t *sc;
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1794
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1795
    list_for_each_entry(sc, &master->configs, list) {
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1796
        ec_slave_config_expire_disconnected_requests(sc);
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1797
    }
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1798
}
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1799
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1800
/*****************************************************************************/
0e4d098db815 Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents: 2617
diff changeset
  1801
1077
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1802
/** Common implementation for ec_master_find_slave()
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1803
 * and ec_master_find_slave_const().
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1804
 */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1805
#define EC_FIND_SLAVE \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1806
    do { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1807
        if (alias) { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1808
            for (; slave < master->slaves + master->slave_count; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1809
                    slave++) { \
1909
ea3eb4c74c1b Introduced effective_alias variable to separate reg12 alias from SII alias.
Florian Pose <fp@igh-essen.com>
parents: 1906
diff changeset
  1810
                if (slave->effective_alias == alias) \
1077
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1811
                break; \
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
            if (slave == master->slaves + master->slave_count) \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1814
            return NULL; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1815
        } \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1816
        \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1817
        slave += position; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1818
        if (slave < master->slaves + master->slave_count) { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1819
            return slave; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1820
        } else { \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1821
            return NULL; \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1822
        } \
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1823
    } while (0)
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1824
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1825
/** Finds a slave in the bus, given the alias and position.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1826
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1827
 * \return Search result, or NULL.
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1828
 */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1829
ec_slave_t *ec_master_find_slave(
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1830
        ec_master_t *master, /**< EtherCAT master. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1831
        uint16_t alias, /**< Slave alias. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1832
        uint16_t position /**< Slave position. */
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1833
        )
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1834
{
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 997
diff changeset
  1835
    ec_slave_t *slave = master->slaves;
1077
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1836
    EC_FIND_SLAVE;
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1837
}
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1838
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1839
/** 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
  1840
 *
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1841
 * Const version.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1842
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  1843
 * \return Search result, or NULL.
1077
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1844
 */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1845
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
  1846
        const ec_master_t *master, /**< EtherCAT master. */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1847
        uint16_t alias, /**< Slave alias. */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1848
        uint16_t position /**< Slave position. */
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1849
        )
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1850
{
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1851
    const ec_slave_t *slave = master->slaves;
c95cd717b852 Added ec_master_find_slave_const().
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1852
    EC_FIND_SLAVE;
927
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1853
}
ffb7d1876ce0 Introduced ec_master_find_slave().
Florian Pose <fp@igh-essen.com>
parents: 926
diff changeset
  1854
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1855
/*****************************************************************************/
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1856
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1857
/** 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
  1858
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1859
 * \return Number of configurations.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1860
 */
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1861
unsigned int ec_master_config_count(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1862
        const ec_master_t *master /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1863
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1864
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1865
    const ec_slave_config_t *sc;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1866
    unsigned int count = 0;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1867
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1868
    list_for_each_entry(sc, &master->configs, list) {
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1869
        count++;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1870
    }
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1871
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1872
    return count;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1873
}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1874
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1875
/*****************************************************************************/
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1876
1252
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1877
/** Common implementation for ec_master_get_config()
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1878
 * and ec_master_get_config_const().
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1879
 */
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1880
#define EC_FIND_CONFIG \
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1881
    do { \
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1882
        list_for_each_entry(sc, &master->configs, list) { \
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1883
            if (pos--) \
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1884
                continue; \
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1885
            return sc; \
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1886
        } \
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1887
        return NULL; \
1252
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1888
    } while (0)
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1889
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1890
/** 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
  1891
 *
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1892
 * \return Slave configuration or \a NULL.
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1893
 */
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1894
ec_slave_config_t *ec_master_get_config(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1895
        const ec_master_t *master, /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1896
        unsigned int pos /**< List position. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1897
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1898
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1899
    ec_slave_config_t *sc;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1900
    EC_FIND_CONFIG;
1252
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1901
}
0b411da5fd24 Added ec_master_get_config().
Florian Pose <fp@igh-essen.com>
parents: 1250
diff changeset
  1902
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1903
/** 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
  1904
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1905
 * Const version.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1906
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1907
 * \return Slave configuration or \a NULL.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1908
 */
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1909
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
  1910
        const ec_master_t *master, /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1911
        unsigned int pos /**< List position. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1912
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1913
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1914
    const ec_slave_config_t *sc;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1915
    EC_FIND_CONFIG;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1916
}
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1917
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1918
/*****************************************************************************/
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
  1919
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1920
/** Get the number of domains.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1921
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1922
 * \return Number of domains.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1923
 */
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1924
unsigned int ec_master_domain_count(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1925
        const ec_master_t *master /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1926
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1927
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1928
    const ec_domain_t *domain;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1929
    unsigned int count = 0;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1930
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1931
    list_for_each_entry(domain, &master->domains, list) {
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1932
        count++;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1933
    }
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1934
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1935
    return count;
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1936
}
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1937
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1938
/*****************************************************************************/
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1939
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1940
/** 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
  1941
 * 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
  1942
 */
1078
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1943
#define EC_FIND_DOMAIN \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1944
    do { \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1945
        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
  1946
            if (index--) \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1947
                continue; \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1948
            return domain; \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1949
        } \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1950
        \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1951
        return NULL; \
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1952
    } while (0)
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1953
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1954
/** Get a domain via its position in the list.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1955
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1956
 * \return Domain pointer, or \a NULL if not found.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1957
 */
946
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1958
ec_domain_t *ec_master_find_domain(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1959
        ec_master_t *master, /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1960
        unsigned int index /**< Domain index. */
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
    ec_domain_t *domain;
1078
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1964
    EC_FIND_DOMAIN;
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1965
}
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1966
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1967
/** Get a domain via its position in the list.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1968
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1969
 * Const version.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1970
 *
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1971
 * \return Domain pointer, or \a NULL if not found.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1972
 */
1078
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1973
const ec_domain_t *ec_master_find_domain_const(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1974
        const ec_master_t *master, /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1975
        unsigned int index /**< Domain index. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1976
        )
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
    const ec_domain_t *domain;
1078
fce58ba8a912 Added ec_master_find_domain_const().
Florian Pose <fp@igh-essen.com>
parents: 1077
diff changeset
  1979
    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
  1980
}
6ef20c5de875 Introduced ec_master_domain_count() and ec_master_find_domain().
Florian Pose <fp@igh-essen.com>
parents: 927
diff changeset
  1981
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1982
/*****************************************************************************/
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  1983
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  1984
#ifdef EC_EOE
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  1985
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1986
/** Get the number of EoE handlers.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1987
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1988
 * \return Number of EoE handlers.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1989
 */
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  1990
uint16_t ec_master_eoe_handler_count(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1991
        const ec_master_t *master /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1992
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1993
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1994
    const ec_eoe_t *eoe;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1995
    unsigned int count = 0;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1996
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1997
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1998
        count++;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1999
    }
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2000
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2001
    return count;
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2002
}
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2003
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2004
/*****************************************************************************/
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2005
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2006
/** Get an EoE handler via its position in the list.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2007
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2008
 * Const version.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2009
 *
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2010
 * \return EoE handler pointer, or \a NULL if not found.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2011
 */
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2012
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
  2013
        const ec_master_t *master, /**< EtherCAT master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2014
        uint16_t index /**< EoE handler index. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2015
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2016
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2017
    const ec_eoe_t *eoe;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2018
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2019
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2020
        if (index--)
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2021
            continue;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2022
        return eoe;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2023
    }
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
    return NULL;
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2026
}
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2027
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  2028
#endif
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  2029
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2030
/*****************************************************************************/
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1483
diff changeset
  2031
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  2032
/** Set the debug level.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  2033
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2034
 * \retval       0 Success.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2035
 * \retval -EINVAL Invalid debug level.
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  2036
 */
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2037
int ec_master_debug_level(
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  2038
        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
  2039
        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
  2040
        )
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2041
{
1399
f79d4bb5b23a Added debug_level module parameter. debug_level is now unsigned int.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
  2042
    if (level > 2) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2043
        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
  2044
        return -EINVAL;
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2045
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2046
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2047
    if (level != master->debug_level) {
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2048
        master->debug_level = level;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2049
        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
  2050
                master->debug_level);
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2051
    }
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2052
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2053
    return 0;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2054
}
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 946
diff changeset
  2055
1408
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2056
/*****************************************************************************/
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2057
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2058
/** Finds the DC reference clock.
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2059
 */
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2060
void ec_master_find_dc_ref_clock(
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2061
        ec_master_t *master /**< EtherCAT master. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2062
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2063
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2064
    ec_slave_t *slave, *ref = NULL;
1408
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2065
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2066
    if (master->dc_ref_config) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2067
        // Use application-selected reference clock
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2068
        slave = master->dc_ref_config->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2069
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2070
        if (slave) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2071
            if (slave->base_dc_supported && slave->has_dc_system_time) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2072
                ref = slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2073
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2074
            else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2075
                EC_MASTER_WARN(master, "Slave %u can not act as a"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2076
                        " DC reference clock!", slave->ring_position);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2077
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2078
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2079
        else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2080
            EC_MASTER_WARN(master, "DC reference clock config (%u-%u)"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2081
                    " has no slave attached!\n", master->dc_ref_config->alias,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2082
                    master->dc_ref_config->position);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2083
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2084
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2085
    else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2086
        // Use first slave with DC support as reference clock
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2087
        for (slave = master->slaves;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2088
                slave < master->slaves + master->slave_count;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2089
                slave++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2090
            if (slave->base_dc_supported && slave->has_dc_system_time) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2091
                ref = slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2092
                break;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2093
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2094
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2095
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2096
    }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2097
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2098
    master->dc_ref_clock = ref;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2099
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2100
    if (ref) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2101
        EC_MASTER_INFO(master, "Using slave %u as DC reference clock.\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2102
                ref->ring_position);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2103
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2104
    else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2105
        EC_MASTER_INFO(master, "No DC reference clock found.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2106
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2107
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2108
    // These calls always succeed, because the
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2109
    // datagrams have been pre-allocated.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2110
    ec_datagram_fpwr(&master->ref_sync_datagram,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2111
            ref ? ref->station_address : 0xffff, 0x0910, 4);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2112
    ec_datagram_frmw(&master->sync_datagram,
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2113
            ref ? ref->station_address : 0xffff, 0x0910, 4);
1408
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2114
}
91b35db64a24 Find DC reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1399
diff changeset
  2115
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2116
/*****************************************************************************/
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2117
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2118
/** Calculates the bus topology; recursion function.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2119
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2120
 * \return Zero on success, otherwise a negative error code.
1421
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
int ec_master_calc_topology_rec(
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2123
        ec_master_t *master, /**< EtherCAT master. */
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2124
        ec_slave_t *port0_slave, /**< Slave at port 0. */
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2125
        unsigned int *slave_position /**< Slave position. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2126
        )
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2127
{
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2128
    ec_slave_t *slave = master->slaves + *slave_position;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2129
    unsigned int port_index;
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2130
    int ret;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2131
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2132
    static const unsigned int next_table[EC_MAX_PORTS] = {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2133
        3, 2, 0, 1
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2134
    };
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2135
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2136
    slave->ports[0].next_slave = port0_slave;
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2137
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2138
    port_index = 3;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2139
    while (port_index != 0) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2140
        if (!slave->ports[port_index].link.loop_closed) {
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2141
            *slave_position = *slave_position + 1;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2142
            if (*slave_position < master->slave_count) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2143
                slave->ports[port_index].next_slave =
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2144
                    master->slaves + *slave_position;
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2145
                ret = ec_master_calc_topology_rec(master,
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2146
                        slave, slave_position);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2147
                if (ret) {
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2148
                    return ret;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2149
                }
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2150
            } else {
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2151
                return -1;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2152
            }
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2153
        }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2154
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2155
        port_index = next_table[port_index];
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2156
    }
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2157
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2158
    return 0;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2159
}
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2160
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2161
/*****************************************************************************/
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2162
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2163
/** Calculates the bus topology.
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2164
 */
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2165
void ec_master_calc_topology(
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2166
        ec_master_t *master /**< EtherCAT master. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2167
        )
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2168
{
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2169
    unsigned int slave_position = 0;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2170
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2171
    if (master->slave_count == 0)
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2172
        return;
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2173
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2174
    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
  2175
        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
  2176
}
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
  2177
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2178
/*****************************************************************************/
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2179
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  2180
/** Calculates the bus transmission delays.
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  2181
 */
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  2182
void ec_master_calc_transmission_delays(
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2183
        ec_master_t *master /**< EtherCAT master. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2184
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2185
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2186
    ec_slave_t *slave;
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2187
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2188
    for (slave = master->slaves;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2189
            slave < master->slaves + master->slave_count;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2190
            slave++) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2191
        ec_slave_calc_port_delays(slave);
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2192
    }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2193
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2194
    if (master->dc_ref_clock) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2195
        uint32_t delay = 0;
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  2196
        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
  2197
    }
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2198
}
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2199
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2200
/*****************************************************************************/
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2201
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2202
/** Distributed-clocks calculations.
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2203
 */
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2204
void ec_master_calc_dc(
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2205
        ec_master_t *master /**< EtherCAT master. */
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2206
        )
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2207
{
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2208
    // find DC reference clock
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2209
    ec_master_find_dc_ref_clock(master);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2210
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2211
    // calculate bus topology
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2212
    ec_master_calc_topology(master);
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2213
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
  2214
    ec_master_calc_transmission_delays(master);
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2215
}
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
  2216
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
  2217
/*****************************************************************************/
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
  2218
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
  2219
/** 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
  2220
 */
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
  2221
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
  2222
        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
  2223
        )
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
  2224
{
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
  2225
    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
  2226
    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
  2227
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
  2228
    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
  2229
        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
  2230
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
  2231
    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
  2232
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
  2233
    // 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
  2234
    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
  2235
        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
  2236
        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
  2237
            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
  2238
        }
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
  2239
    }
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
  2240
2617
559f2f9c5b08 Do not force the DC reference clock to OP; if it is not configured it may refuse and flood the logs.
Gavin Lambert <gavinl@compacsort.com>
parents: 2589
diff changeset
  2241
#ifdef EC_REFCLKOP
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
  2242
    // 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
  2243
    if (master->dc_ref_clock) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2244
        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
  2245
    }
2617
559f2f9c5b08 Do not force the DC reference clock to OP; if it is not configured it may refuse and flood the logs.
Gavin Lambert <gavinl@compacsort.com>
parents: 2589
diff changeset
  2246
#endif
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
  2247
}
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
  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
/******************************************************************************
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  2250
 *  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
  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
1332
d62633fea8ed merge -c1610 branches/stable-1.4: Added missing doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 1329
diff changeset
  2253
/** Same as ecrt_master_create_domain(), but with ERR_PTR() return value.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2254
 *
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2255
 * \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
  2256
 */
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2257
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
  2258
        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
  2259
        )
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
  2260
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2261
    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
  2262
    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
  2263
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2264
    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
  2265
            master);
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  2266
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2267
    if (!(domain =
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2268
                (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
  2269
        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
  2270
        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
  2271
    }
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2273
    down(&master->master_sem);
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
  2274
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  2275
    if (list_empty(&master->domains)) {
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  2276
        index = 0;
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  2277
    } 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
  2278
        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
  2279
        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
  2280
    }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2281
993
8c32564252fd Removed kobject from domain.
Florian Pose <fp@igh-essen.com>
parents: 992
diff changeset
  2282
    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
  2283
    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
  2284
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2285
    up(&master->master_sem);
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
  2286
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2287
    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
  2288
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
  2289
    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
  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
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
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2293
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2294
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
  2295
        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
  2296
        )
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2297
{
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2298
    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
  2299
    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
  2300
}
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2301
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2302
/*****************************************************************************/
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2303
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2304
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
  2305
{
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2306
    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
  2307
    ec_domain_t *domain;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2308
    int ret;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2309
#ifdef EC_EOE
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2310
    int eoe_was_running;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2311
#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
  2312
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2313
    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
  2314
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2315
    if (master->active) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2316
        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
  2317
        return 0;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2318
    }
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2319
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2320
    down(&master->master_sem);
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
  2321
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2322
    // 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
  2323
    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
  2324
    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
  2325
        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
  2326
        if (ret < 0) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2327
            up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2328
            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
  2329
            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
  2330
        }
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2331
        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
  2332
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2333
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2334
    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
  2335
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  2336
    // 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
  2337
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
  2338
    ec_master_thread_stop(master);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2339
#ifdef EC_EOE
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2340
    eoe_was_running = master->eoe_thread != NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2341
    ec_master_eoe_stop(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2342
#endif
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  2343
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2344
    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
  2345
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  2346
    master->injection_seq_fsm = 0;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 651
diff changeset
  2347
    master->injection_seq_rt = 0;
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2348
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2349
    master->send_cb = master->app_send_cb;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2350
    master->receive_cb = master->app_receive_cb;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2351
    master->cb_data = master->app_cb_data;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2352
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2353
#ifdef EC_EOE
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2354
    if (eoe_was_running) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2355
        ec_master_eoe_start(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2356
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2357
#endif
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2358
    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
  2359
                "EtherCAT-OP");
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2360
    if (ret < 0) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2361
        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
  2362
        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
  2363
    }
902
ad703091a32b Moved setting of the allow flags.
Florian Pose <fp@igh-essen.com>
parents: 901
diff changeset
  2364
2270
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
  2365
    /* Allow scanning after a topology change. */
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
  2366
    master->allow_scan = 1;
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
  2367
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2368
    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
  2369
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
  2370
    // 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
  2371
    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
  2372
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
  2373
    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
  2374
}
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2375
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2376
/*****************************************************************************/
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2377
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2378
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
  2379
{
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2380
    ec_slave_t *slave;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2381
#ifdef EC_EOE
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2382
    ec_eoe_t *eoe;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2383
    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
  2384
#endif
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2385
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
  2386
    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
  2387
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2388
    if (!master->active) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2389
        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
  2390
        return;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2391
    }
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2392
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
  2393
    ec_master_thread_stop(master);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2394
#ifdef EC_EOE
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2395
    eoe_was_running = master->eoe_thread != NULL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2396
    ec_master_eoe_stop(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2397
#endif
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2398
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2399
    master->send_cb = ec_master_internal_send_cb;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2400
    master->receive_cb = ec_master_internal_receive_cb;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2401
    master->cb_data = master;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2402
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
  2403
    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
  2404
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2405
    for (slave = master->slaves;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2406
            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
  2407
            slave++) {
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2408
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2409
        // set states for all slaves
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2410
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2411
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2412
        // 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
  2413
        // 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
  2414
        // phases.
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2415
        slave->force_config = 1;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2416
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2417
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2418
#ifdef EC_EOE
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2419
    // ... but leave EoE slaves in OP
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2420
    list_for_each_entry(eoe, &master->eoe_handlers, list) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2421
        if (ec_eoe_is_open(eoe))
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2422
            ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2423
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2424
#endif
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2425
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2426
    master->app_time = 0ULL;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2427
    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
  2428
    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
  2429
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2430
#ifdef EC_EOE
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2431
    if (eoe_was_running) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2432
        ec_master_eoe_start(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2433
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2434
#endif
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2435
    if (ec_master_thread_start(master, ec_master_idle_thread,
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2436
                "EtherCAT-IDLE")) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2437
        EC_MASTER_WARN(master, "Failed to restart master thread!\n");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2438
    }
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2439
2270
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
  2440
    /* Disallow scanning to get into the same state like after a master
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
  2441
     * request (after ec_master_enter_operation_phase() is called). */
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
  2442
    master->allow_scan = 0;
51d2b26a5d1c Fixed reset of allow_scanning flag if ecrt_master_activate() was not called.
Florian Pose <fp@igh-essen.com>
parents: 2249
diff changeset
  2443
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2444
    master->active = 0;
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2445
}
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2446
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2447
/*****************************************************************************/
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  2448
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  2449
size_t 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
  2450
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2451
    ec_datagram_t *datagram, *n;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2452
    ec_device_index_t dev_idx;
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  2453
    size_t sent_bytes = 0;
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  2454
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2455
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2456
    if (master->injection_seq_rt != master->injection_seq_fsm) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2457
        // inject datagram produced by master FSM
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2458
        ec_master_queue_datagram(master, &master->fsm_datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2459
        master->injection_seq_rt = master->injection_seq_fsm;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2460
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2461
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2462
    ec_master_inject_external_datagrams(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2463
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2464
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2465
            dev_idx++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2466
        if (unlikely(!master->devices[dev_idx].link_state)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2467
            // link is down, no datagram can be sent
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2468
            list_for_each_entry_safe(datagram, n,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2469
                    &master->datagram_queue, queue) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2470
                if (datagram->device_index == dev_idx) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2471
                    datagram->state = EC_DATAGRAM_ERROR;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2472
                    list_del_init(&datagram->queue);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2473
                }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2474
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2475
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2476
            if (!master->devices[dev_idx].dev) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2477
                continue;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2478
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2479
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2480
            // query link state
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2481
            ec_device_poll(&master->devices[dev_idx]);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2482
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2483
            // clear frame statistics
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2484
            ec_device_clear_stats(&master->devices[dev_idx]);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2485
            continue;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2486
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2487
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2488
        // send frames
2630
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  2489
        sent_bytes = max(sent_bytes,
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  2490
            ec_master_send_datagrams(master, dev_idx));
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  2491
    }
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  2492
a380cce7d6f0 16-ethercat-1.5-frame-corruption.patch
Dave Page <dave.page@gleeble.com>
parents: 2622
diff changeset
  2493
    return sent_bytes;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2494
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2495
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2496
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2497
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2498
void ecrt_master_receive(ec_master_t *master)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2499
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2500
    unsigned int dev_idx;
2039
629d3cf05180 Minor changes (consistent variable naming)
Martin Troxler <ch1010277@ch10pc446>
parents: 2038
diff changeset
  2501
    ec_datagram_t *datagram, *next;
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
  2502
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2503
    // receive datagrams
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2504
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2505
            dev_idx++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2506
        ec_device_poll(&master->devices[dev_idx]);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2507
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2508
    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
  2509
16e9ad7d8e12 Added parameters for vendor ID and product code to ecrt_get_slave(); PDO
Florian Pose <fp@igh-essen.com>
parents: 639
diff changeset
  2510
    // 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
  2511
    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
  2512
        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
  2513
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
  2514
#ifdef EC_HAVE_CYCLES
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2515
        if (master->devices[EC_DEVICE_MAIN].cycles_poll -
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2516
                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
  2517
#else
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2518
        if (master->devices[EC_DEVICE_MAIN].jiffies_poll -
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2519
                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
  2520
#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
  2521
            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
  2522
            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
  2523
            master->stats.timeouts++;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2524
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2525
#ifdef EC_RT_SYSLOG
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
  2526
            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
  2527
bf991809dcf0 Added debugging output for unmatched frames and those that timed out.
Florian Pose <fp@igh-essen.com>
parents: 664
diff changeset
  2528
            if (unlikely(master->debug_level > 0)) {
1237
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  2529
                unsigned int time_us;
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  2530
#ifdef EC_HAVE_CYCLES
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2531
                time_us = (unsigned int)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2532
                    (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
  2533
                        datagram->cycles_sent) * 1000 / cpu_khz;
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  2534
#else
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2535
                time_us = (unsigned int)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2536
                    ((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
  2537
                            datagram->jiffies_sent) * 1000000 / HZ);
1237
33e8349b44bd Avoided using #ifdef inside a macro.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
  2538
#endif
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2539
                EC_MASTER_DBG(master, 0, "TIMED OUT datagram %p,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2540
                        " 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
  2541
                        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
  2542
            }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2543
#endif /* RT_SYSLOG */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2544
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2545
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2546
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2547
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2548
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2549
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2550
void ecrt_master_send_ext(ec_master_t *master)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2551
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2552
    ec_datagram_t *datagram, *next;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2553
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2554
    list_for_each_entry_safe(datagram, next, &master->ext_datagram_queue,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2555
            queue) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2556
        list_del(&datagram->queue);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2557
        ec_master_queue_datagram(master, datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2558
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2559
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2560
    ecrt_master_send(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2561
}
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2562
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2563
/*****************************************************************************/
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  2564
1332
d62633fea8ed merge -c1610 branches/stable-1.4: Added missing doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 1329
diff changeset
  2565
/** 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
  2566
 */
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2567
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
  2568
        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
  2569
        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
  2570
{
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2571
    ec_slave_config_t *sc;
697
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2572
    unsigned int found = 0;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2573
1181
9e5954a2a46e Added debugging for configuration function of the application interface.
Florian Pose <fp@igh-essen.com>
parents: 1178
diff changeset
  2574
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2575
    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
  2576
            " alias = %u, position = %u, vendor_id = 0x%08x,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2577
            " product_code = 0x%08x)\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2578
            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
  2579
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2580
    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
  2581
        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
  2582
            found = 1;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2583
            break;
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2584
        }
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2585
    }
6f658c2082fd Added ecrt_master_get_slave_by_pos().
Florian Pose <fp@igh-essen.com>
parents: 692
diff changeset
  2586
1024
fef0b1953770 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1023
diff changeset
  2587
    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
  2588
        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
  2589
            EC_MASTER_ERR(master, "Slave type mismatch. Slave was"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2590
                    " configured as 0x%08X/0x%08X before. Now configuring"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2591
                    " 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
  2592
                    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
  2593
            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
  2594
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2595
    } else {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2596
        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
  2597
                " 0x%08X/0x%08X.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2598
                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
  2599
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2600
        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
  2601
                        GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2602
            EC_MASTER_ERR(master, "Failed to allocate memory"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2603
                    " 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
  2604
            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
  2605
        }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2606
995
54149a703c47 Removed kobject from slave_config.
Florian Pose <fp@igh-essen.com>
parents: 994
diff changeset
  2607
        ec_slave_config_init(sc, master,
1010
6672b86e7b10 Reverted revision number checking from r1228.
Florian Pose <fp@igh-essen.com>
parents: 1009
diff changeset
  2608
                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
  2609
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2610
        down(&master->master_sem);
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
  2611
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2612
        // 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
  2613
        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
  2614
        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
  2615
        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
  2616
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2617
        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
  2618
    }
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2619
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2620
    return sc;
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2621
}
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2622
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2623
/*****************************************************************************/
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
  2624
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2625
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
  2626
        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
  2627
        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
  2628
{
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2629
    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
  2630
            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
  2631
    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
  2632
}
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2633
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2634
/*****************************************************************************/
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1303
diff changeset
  2635
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2636
int ecrt_master_select_reference_clock(ec_master_t *master,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2637
        ec_slave_config_t *sc)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2638
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2639
    if (sc) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2640
        ec_slave_t *slave = sc->slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2641
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2642
        // output an early warning
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2643
        if (slave &&
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2644
                (!slave->base_dc_supported || !slave->has_dc_system_time)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2645
            EC_MASTER_WARN(master, "Slave %u can not act as"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2646
                    " a reference clock!", slave->ring_position);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2647
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2648
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2649
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2650
    master->dc_ref_config = sc;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2651
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2652
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2653
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2654
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2655
1594
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2656
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
  2657
{
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2658
    EC_MASTER_DBG(master, 1, "ecrt_master(master = 0x%p,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1914
diff changeset
  2659
            " 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
  2660
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2661
    master_info->slave_count = master->slave_count;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2662
    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
  2663
    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
  2664
    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
  2665
    return 0;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2666
}
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2667
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
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
  2671
        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
  2672
{
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2673
    const ec_slave_t *slave;
2249
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2674
    unsigned int i;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2675
    int ret = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2676
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2677
    if (down_interruptible(&master->master_sem)) {
1594
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2678
        return -EINTR;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2679
    }
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2680
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2681
    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
  2682
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2683
    if (slave == NULL) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2684
       ret = -ENOENT;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2685
       goto out_get_slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2686
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2687
1594
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2688
    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
  2689
    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
  2690
    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
  2691
    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
  2692
    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
  2693
    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
  2694
    slave_info->current_on_ebus = slave->sii.current_on_ebus;
2249
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2695
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2696
    for (i = 0; i < EC_MAX_PORTS; i++) {
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2697
        slave_info->ports[i].desc = slave->ports[i].desc;
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2698
        slave_info->ports[i].link.link_up = slave->ports[i].link.link_up;
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2699
        slave_info->ports[i].link.loop_closed =
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2700
            slave->ports[i].link.loop_closed;
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2701
        slave_info->ports[i].link.signal_detected =
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2702
            slave->ports[i].link.signal_detected;
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2703
        slave_info->ports[i].receive_time = slave->ports[i].receive_time;
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2704
        if (slave->ports[i].next_slave) {
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2705
            slave_info->ports[i].next_slave =
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2706
                slave->ports[i].next_slave->ring_position;
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2707
        } else {
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2708
            slave_info->ports[i].next_slave = 0xffff;
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2709
        }
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2710
        slave_info->ports[i].delay_to_next_dc =
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2711
            slave->ports[i].delay_to_next_dc;
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2712
    }
6dbd7594dd1d Copy missing slave_info data in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 2240
diff changeset
  2713
1594
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2714
    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
  2715
    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
  2716
    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
  2717
    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
  2718
    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
  2719
        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
  2720
    } else {
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2721
        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
  2722
    }
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2723
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2724
out_get_slave:
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2725
    up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2726
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2727
    return ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2728
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2729
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2730
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2731
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2732
void ecrt_master_callbacks(ec_master_t *master,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2733
        void (*send_cb)(void *), void (*receive_cb)(void *), void *cb_data)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2734
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2735
    EC_MASTER_DBG(master, 1, "ecrt_master_callbacks(master = 0x%p,"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2736
            " send_cb = 0x%p, receive_cb = 0x%p, cb_data = 0x%p)\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2737
            master, send_cb, receive_cb, cb_data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2738
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2739
    master->app_send_cb = send_cb;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2740
    master->app_receive_cb = receive_cb;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2741
    master->app_cb_data = cb_data;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2742
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2743
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2744
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2745
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2746
void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2747
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2748
    ec_device_index_t dev_idx;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2749
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2750
    state->slaves_responding = 0U;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2751
    state->al_states = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2752
    state->link_up = 0U;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2753
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2754
    for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2755
            dev_idx++) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2756
        /* Announce sum of responding slaves on all links. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2757
        state->slaves_responding += master->fsm.slaves_responding[dev_idx];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2758
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2759
        /* Binary-or slave states of all links. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2760
        state->al_states |= master->fsm.slave_states[dev_idx];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2761
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2762
        /* Signal link up if at least one device has link. */
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2763
        state->link_up |= master->devices[dev_idx].link_state;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2764
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2765
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2766
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2767
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2768
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2769
int ecrt_master_link_state(const ec_master_t *master, unsigned int dev_idx,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2770
        ec_master_link_state_t *state)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2771
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2772
    if (dev_idx >= ec_master_num_devices(master)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2773
        return -EINVAL;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2774
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2775
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2776
    state->slaves_responding = master->fsm.slaves_responding[dev_idx];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2777
    state->al_states = master->fsm.slave_states[dev_idx];
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2778
    state->link_up = master->devices[dev_idx].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
  2779
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2780
    return 0;
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2781
}
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2782
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2783
/*****************************************************************************/
2019bec460ad Implemented ecrt_master() and ecrt_master_get_slave() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1586
diff changeset
  2784
1434
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2785
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
  2786
{
7c2d5d69134c Replaced timeval by 64-bit EtherCAT time.
Florian Pose <fp@igh-essen.com>
parents: 1415
diff changeset
  2787
    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
  2788
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
  2789
    if (unlikely(!master->has_app_time)) {
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2790
        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
  2791
        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
  2792
    }
1434
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2793
}
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2794
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2795
/*****************************************************************************/
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2796
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2797
int ecrt_master_reference_clock_time(ec_master_t *master, uint32_t *time)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2798
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2799
    if (!master->dc_ref_clock) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2800
        return -ENXIO;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2801
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2802
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2803
    if (master->sync_datagram.state != EC_DATAGRAM_RECEIVED) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2804
        return -EIO;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2805
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2806
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2807
    // Get returned datagram time, transmission delay removed.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2808
    *time = EC_READ_U32(master->sync_datagram.data) -
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2809
        master->dc_ref_clock->transmission_delay;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2810
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2811
    return 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2812
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2813
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2814
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2815
1434
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  2816
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
  2817
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2818
    if (master->dc_ref_clock) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2819
        EC_WRITE_U32(master->ref_sync_datagram.data, master->app_time);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2820
        ec_master_queue_datagram(master, &master->ref_sync_datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2821
    }
1410
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  2822
}
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  2823
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  2824
/*****************************************************************************/
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  2825
fb6719008bf5 Separated sync_reference_clock() and sync_slave_clocks().
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
  2826
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
  2827
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2828
    if (master->dc_ref_clock) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2829
        ec_datagram_zero(&master->sync_datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2830
        ec_master_queue_datagram(master, &master->sync_datagram);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2831
    }
1394
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  2832
}
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  2833
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  2834
/*****************************************************************************/
e77728ddf0f9 Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  2835
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2836
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
  2837
{
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2838
    ec_datagram_zero(&master->sync_mon_datagram);
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2839
    ec_master_queue_datagram(master, &master->sync_mon_datagram);
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2840
}
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2841
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2842
/*****************************************************************************/
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2843
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2844
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
  2845
{
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2846
    if (master->sync_mon_datagram.state == EC_DATAGRAM_RECEIVED) {
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2847
        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
  2848
    } else {
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2849
        return 0xffffffff;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2850
    }
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2851
}
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2852
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2853
/*****************************************************************************/
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  2854
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2855
int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position,
2622
1aee02c1e294 Mark download data as const.
Gavin Lambert <uecasm@users.sourceforge.net>
parents: 2620
diff changeset
  2856
        uint16_t index, uint8_t subindex, const uint8_t *data,
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2857
        size_t data_size, uint32_t *abort_code)
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2858
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2859
    ec_sdo_request_t request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2860
    ec_slave_t *slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2861
    int ret;
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2862
2110
455126b35650 Fixed compiler error; added SDO debugging.
Florian Pose <fp@igh-essen.com>
parents: 2107
diff changeset
  2863
    EC_MASTER_DBG(master, 1, "%s(master = 0x%p,"
455126b35650 Fixed compiler error; added SDO debugging.
Florian Pose <fp@igh-essen.com>
parents: 2107
diff changeset
  2864
            " slave_position = %u, index = 0x%04X, subindex = 0x%02X,"
455126b35650 Fixed compiler error; added SDO debugging.
Florian Pose <fp@igh-essen.com>
parents: 2107
diff changeset
  2865
            " data = 0x%p, data_size = %zu, abort_code = 0x%p)\n",
455126b35650 Fixed compiler error; added SDO debugging.
Florian Pose <fp@igh-essen.com>
parents: 2107
diff changeset
  2866
            __func__, master, slave_position, index, subindex,
455126b35650 Fixed compiler error; added SDO debugging.
Florian Pose <fp@igh-essen.com>
parents: 2107
diff changeset
  2867
            data, data_size, abort_code);
455126b35650 Fixed compiler error; added SDO debugging.
Florian Pose <fp@igh-essen.com>
parents: 2107
diff changeset
  2868
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2869
    if (!data_size) {
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2870
        EC_MASTER_ERR(master, "Zero data size!\n");
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2871
        return -EINVAL;
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2872
    }
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2873
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2874
    ec_sdo_request_init(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2875
    ecrt_sdo_request_index(&request, index, subindex);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2876
    ret = ec_sdo_request_alloc(&request, data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2877
    if (ret) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2878
        ec_sdo_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2879
        return ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2880
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2881
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2882
    memcpy(request.data, data, data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2883
    request.data_size = data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2884
    ecrt_sdo_request_write(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2885
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2886
    if (down_interruptible(&master->master_sem)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2887
        ec_sdo_request_clear(&request);
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2888
        return -EINTR;
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2889
    }
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2890
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2891
    if (!(slave = ec_master_find_slave(master, 0, slave_position))) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2892
        up(&master->master_sem);
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2893
        EC_MASTER_ERR(master, "Slave %u does not exist!\n", slave_position);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2894
        ec_sdo_request_clear(&request);
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2895
        return -EINVAL;
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2896
    }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2897
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2898
    EC_SLAVE_DBG(slave, 1, "Scheduling SDO download request.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2899
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2900
    // schedule request.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2901
    list_add_tail(&request.list, &slave->sdo_requests);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2902
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2903
    up(&master->master_sem);
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2904
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2905
    // wait for processing through FSM
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2906
    if (wait_event_interruptible(master->request_queue,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2907
                request.state != EC_INT_REQUEST_QUEUED)) {
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2908
        // interrupted by signal
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2909
        down(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2910
        if (request.state == EC_INT_REQUEST_QUEUED) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2911
            list_del(&request.list);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2912
            up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2913
            ec_sdo_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2914
            return -EINTR;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2915
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2916
        // request already processing: interrupt not possible.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2917
        up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2918
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2919
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2920
    // wait until master FSM has finished processing
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2921
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2922
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2923
    *abort_code = request.abort_code;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2924
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2925
    if (request.state == EC_INT_REQUEST_SUCCESS) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2926
        ret = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2927
    } else if (request.errno) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2928
        ret = -request.errno;
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2929
    } else {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2930
        ret = -EIO;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2931
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2932
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2933
    ec_sdo_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2934
    return ret;
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2935
}
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2936
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2937
/*****************************************************************************/
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  2938
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2939
int ecrt_master_sdo_download_complete(ec_master_t *master,
2622
1aee02c1e294 Mark download data as const.
Gavin Lambert <uecasm@users.sourceforge.net>
parents: 2620
diff changeset
  2940
        uint16_t slave_position, uint16_t index, const uint8_t *data,
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2941
        size_t data_size, uint32_t *abort_code)
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2942
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2943
    ec_sdo_request_t request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2944
    ec_slave_t *slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2945
    int ret;
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2946
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2947
    EC_MASTER_DBG(master, 1, "%s(master = 0x%p,"
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2948
            " slave_position = %u, index = 0x%04X,"
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2949
            " data = 0x%p, data_size = %zu, abort_code = 0x%p)\n",
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2950
            __func__, master, slave_position, index, data, data_size,
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2951
            abort_code);
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2952
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2953
    if (!data_size) {
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2954
        EC_MASTER_ERR(master, "Zero data size!\n");
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2955
        return -EINVAL;
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2956
    }
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2957
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2958
    ec_sdo_request_init(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2959
    ecrt_sdo_request_index(&request, index, 0);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2960
    ret = ec_sdo_request_alloc(&request, data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2961
    if (ret) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2962
        ec_sdo_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2963
        return ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2964
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2965
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2966
    request.complete_access = 1;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2967
    memcpy(request.data, data, data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2968
    request.data_size = data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2969
    ecrt_sdo_request_write(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2970
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2971
    if (down_interruptible(&master->master_sem)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2972
        ec_sdo_request_clear(&request);
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2973
        return -EINTR;
2164
cf4db3c282d2 Fixed compiler error in master.c; thanks to Jun Yuan.
Florian Pose <fp@igh-essen.com>
parents: 2150
diff changeset
  2974
    }
cf4db3c282d2 Fixed compiler error in master.c; thanks to Jun Yuan.
Florian Pose <fp@igh-essen.com>
parents: 2150
diff changeset
  2975
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2976
    if (!(slave = ec_master_find_slave(master, 0, slave_position))) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2977
        up(&master->master_sem);
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2978
        EC_MASTER_ERR(master, "Slave %u does not exist!\n", slave_position);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2979
        ec_sdo_request_clear(&request);
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2980
        return -EINVAL;
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2981
    }
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2982
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2983
    EC_SLAVE_DBG(slave, 1, "Scheduling SDO download request"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2984
            " (complete access).\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2985
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2986
    // schedule request.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2987
    list_add_tail(&request.list, &slave->sdo_requests);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2988
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2989
    up(&master->master_sem);
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2990
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2991
    // wait for processing through FSM
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2992
    if (wait_event_interruptible(master->request_queue,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2993
                request.state != EC_INT_REQUEST_QUEUED)) {
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  2994
        // interrupted by signal
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2995
        down(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2996
        if (request.state == EC_INT_REQUEST_QUEUED) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2997
            list_del(&request.list);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2998
            up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  2999
            ec_sdo_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3000
            return -EINTR;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3001
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3002
        // request already processing: interrupt not possible.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3003
        up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3004
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3005
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3006
    // wait until master FSM has finished processing
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3007
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3008
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3009
    *abort_code = request.abort_code;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3010
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3011
    if (request.state == EC_INT_REQUEST_SUCCESS) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3012
        ret = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3013
    } else if (request.errno) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3014
        ret = -request.errno;
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  3015
    } else {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3016
        ret = -EIO;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3017
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3018
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3019
    ec_sdo_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3020
    return ret;
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  3021
}
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  3022
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  3023
/*****************************************************************************/
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  3024
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3025
int ecrt_master_sdo_upload(ec_master_t *master, uint16_t slave_position,
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3026
        uint16_t index, uint8_t subindex, uint8_t *target,
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3027
        size_t target_size, size_t *result_size, uint32_t *abort_code)
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3028
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3029
    ec_sdo_request_t request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3030
    ec_slave_t *slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3031
    int ret = 0;
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3032
2110
455126b35650 Fixed compiler error; added SDO debugging.
Florian Pose <fp@igh-essen.com>
parents: 2107
diff changeset
  3033
    EC_MASTER_DBG(master, 1, "%s(master = 0x%p,"
455126b35650 Fixed compiler error; added SDO debugging.
Florian Pose <fp@igh-essen.com>
parents: 2107
diff changeset
  3034
            " slave_position = %u, index = 0x%04X, subindex = 0x%02X,"
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3035
            " target = 0x%p, target_size = %zu, result_size = 0x%p,"
2110
455126b35650 Fixed compiler error; added SDO debugging.
Florian Pose <fp@igh-essen.com>
parents: 2107
diff changeset
  3036
            " abort_code = 0x%p)\n",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3037
            __func__, master, slave_position, index, subindex,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3038
            target, target_size, result_size, abort_code);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3039
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3040
    ec_sdo_request_init(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3041
    ecrt_sdo_request_index(&request, index, subindex);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3042
    ecrt_sdo_request_read(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3043
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3044
    if (down_interruptible(&master->master_sem)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3045
        ec_sdo_request_clear(&request);
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3046
        return -EINTR;
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3047
    }
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3048
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3049
    if (!(slave = ec_master_find_slave(master, 0, slave_position))) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3050
        up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3051
        ec_sdo_request_clear(&request);
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3052
        EC_MASTER_ERR(master, "Slave %u does not exist!\n", slave_position);
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3053
        return -EINVAL;
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3054
    }
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3055
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3056
    EC_SLAVE_DBG(slave, 1, "Scheduling SDO upload request.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3057
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3058
    // schedule request.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3059
    list_add_tail(&request.list, &slave->sdo_requests);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3060
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3061
    up(&master->master_sem);
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3062
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3063
    // wait for processing through FSM
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3064
    if (wait_event_interruptible(master->request_queue,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3065
                request.state != EC_INT_REQUEST_QUEUED)) {
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3066
        // interrupted by signal
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3067
        down(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3068
        if (request.state == EC_INT_REQUEST_QUEUED) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3069
            list_del(&request.list);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3070
            up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3071
            ec_sdo_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3072
            return -EINTR;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3073
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3074
        // request already processing: interrupt not possible.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3075
        up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3076
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3077
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3078
    // wait until master FSM has finished processing
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3079
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3080
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3081
    *abort_code = request.abort_code;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3082
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3083
    if (request.state != EC_INT_REQUEST_SUCCESS) {
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3084
        *result_size = 0;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3085
        if (request.errno) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3086
            ret = -request.errno;
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3087
        } else {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3088
            ret = -EIO;
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3089
        }
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3090
    } else {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3091
        if (request.data_size > target_size) {
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3092
            EC_MASTER_ERR(master, "Buffer too small.\n");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3093
            ret = -EOVERFLOW;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3094
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3095
        else {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3096
            memcpy(target, request.data, request.data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3097
            *result_size = request.data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3098
            ret = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3099
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3100
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3101
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3102
    ec_sdo_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3103
    return ret;
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3104
}
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3105
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3106
/*****************************************************************************/
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3107
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
  3108
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
  3109
        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
  3110
        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
  3111
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3112
    ec_soe_request_t request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3113
    ec_slave_t *slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3114
    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
  3115
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3116
    if (drive_no > 7) {
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3117
        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
  3118
        return -EINVAL;
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3119
    }
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3120
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3121
    ec_soe_request_init(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3122
    ec_soe_request_set_drive_no(&request, drive_no);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3123
    ec_soe_request_set_idn(&request, idn);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3124
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3125
    ret = ec_soe_request_alloc(&request, data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3126
    if (ret) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3127
        ec_soe_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3128
        return ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3129
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3130
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3131
    memcpy(request.data, data, data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3132
    request.data_size = data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3133
    ec_soe_request_write(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3134
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3135
    if (down_interruptible(&master->master_sem)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3136
        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
  3137
        return -EINTR;
2032
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  3138
    }
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  3139
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3140
    if (!(slave = ec_master_find_slave(master, 0, slave_position))) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3141
        up(&master->master_sem);
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
  3142
        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
  3143
                slave_position);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3144
        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
  3145
        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
  3146
    }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3147
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3148
    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
  3149
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3150
    // schedule SoE write request.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3151
    list_add_tail(&request.list, &slave->soe_requests);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3152
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3153
    up(&master->master_sem);
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
  3154
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
    // wait for processing through FSM
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3156
    if (wait_event_interruptible(master->request_queue,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3157
                request.state != EC_INT_REQUEST_QUEUED)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3158
        // interrupted by signal
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3159
        down(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3160
        if (request.state == EC_INT_REQUEST_QUEUED) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3161
            // abort request
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3162
            list_del(&request.list);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3163
            up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3164
            ec_soe_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3165
            return -EINTR;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3166
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3167
        up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3168
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3169
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3170
    // wait until master FSM has finished processing
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3171
    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
  3172
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
    if (error_code) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3174
        *error_code = request.error_code;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3175
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3176
    ret = request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3177
    ec_soe_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3178
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3179
    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
  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
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3182
/*****************************************************************************/
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
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
  3185
        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
  3186
        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
  3187
{
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3188
    ec_soe_request_t request;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3189
    ec_slave_t *slave;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3190
    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
  3191
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3192
    if (drive_no > 7) {
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3193
        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
  3194
        return -EINVAL;
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3195
    }
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1947
diff changeset
  3196
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3197
    ec_soe_request_init(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3198
    ec_soe_request_set_drive_no(&request, drive_no);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3199
    ec_soe_request_set_idn(&request, idn);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3200
    ec_soe_request_read(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3201
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3202
    if (down_interruptible(&master->master_sem)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3203
        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
  3204
        return -EINTR;
2032
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  3205
    }
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  3206
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3207
    if (!(slave = ec_master_find_slave(master, 0, slave_position))) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3208
        up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3209
        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
  3210
        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
  3211
        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
  3212
    }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3213
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3214
    EC_SLAVE_DBG(slave, 1, "Scheduling SoE read request.\n");
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3215
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
  3216
    // schedule request.
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3217
    list_add_tail(&request.list, &slave->soe_requests);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3218
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3219
    up(&master->master_sem);
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
  3220
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3221
    // wait for processing through FSM
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3222
    if (wait_event_interruptible(master->request_queue,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3223
                request.state != EC_INT_REQUEST_QUEUED)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3224
        // interrupted by signal
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3225
        down(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3226
        if (request.state == EC_INT_REQUEST_QUEUED) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3227
            list_del(&request.list);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3228
            up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3229
            ec_soe_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3230
            return -EINTR;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3231
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3232
        // request already processing: interrupt not possible.
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3233
        up(&master->master_sem);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3234
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3235
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3236
    // wait until master FSM has finished processing
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3237
    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
  3238
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3239
    if (error_code) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3240
        *error_code = request.error_code;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3241
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3242
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3243
    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
  3244
        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
  3245
            *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
  3246
        }
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3247
        ret = -EIO;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3248
    } else { // success
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3249
        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
  3250
            EC_MASTER_ERR(master, "Buffer too small.\n");
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3251
            ret = -EOVERFLOW;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3252
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3253
        else { // data fits in buffer
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3254
            if (result_size) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3255
                *result_size = request.data_size;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3256
            }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3257
            memcpy(target, request.data, request.data_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3258
            ret = 0;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3259
        }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3260
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3261
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3262
    ec_soe_request_clear(&request);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3263
    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
  3264
}
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3265
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3266
/*****************************************************************************/
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1939
diff changeset
  3267
2009
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3268
void ecrt_master_reset(ec_master_t *master)
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3269
{
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3270
    ec_slave_config_t *sc;
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3271
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3272
    list_for_each_entry(sc, &master->configs, list) {
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3273
        if (sc->slave) {
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3274
            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
  3275
        }
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3276
    }
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3277
}
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3278
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3279
/*****************************************************************************/
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3280
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  3281
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  3282
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  3283
EXPORT_SYMBOL(ecrt_master_create_domain);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
  3284
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
  3285
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
  3286
EXPORT_SYMBOL(ecrt_master_send);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3287
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
  3288
EXPORT_SYMBOL(ecrt_master_receive);
206
60a10d85c20b Prepared EoE processing with workqueue.
Florian Pose <fp@igh-essen.com>
parents: 204
diff changeset
  3289
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
  3290
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
  3291
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
  3292
EXPORT_SYMBOL(ecrt_master_slave_config);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3293
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
  3294
EXPORT_SYMBOL(ecrt_master_state);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3295
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
  3296
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
  3297
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
  3298
EXPORT_SYMBOL(ecrt_master_sync_slave_clocks);
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 2270
diff changeset
  3299
EXPORT_SYMBOL(ecrt_master_reference_clock_time);
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  3300
EXPORT_SYMBOL(ecrt_master_sync_monitor_queue);
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  3301
EXPORT_SYMBOL(ecrt_master_sync_monitor_process);
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3302
EXPORT_SYMBOL(ecrt_master_sdo_download);
2150
5144a4bc6184 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
  3303
EXPORT_SYMBOL(ecrt_master_sdo_download_complete);
2107
ebda087981e1 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() for kernel
Florian Pose <fp@igh-essen.com>
parents: 2103
diff changeset
  3304
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
  3305
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
  3306
EXPORT_SYMBOL(ecrt_master_read_idn);
2009
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1952
diff changeset
  3307
EXPORT_SYMBOL(ecrt_master_reset);
2164
cf4db3c282d2 Fixed compiler error in master.c; thanks to Jun Yuan.
Florian Pose <fp@igh-essen.com>
parents: 2150
diff changeset
  3308
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  3309
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  3310
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
  3311
/*****************************************************************************/