master/module.c
author Florian Pose <fp@igh-essen.com>
Wed, 18 Oct 2006 12:04:24 +0000
changeset 413 a7144fdf14f5
parent 403 7bb931deccd9
child 430 74754f45d5fa
permissions -rw-r--r--
Improved SM and FMMU debugging output.
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
     6
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
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: 196
diff changeset
     8
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 201
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 201
diff changeset
    12
 *  License, or (at your option) any later version.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
    13
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
    17
 *  GNU General Public License for more details.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
    18
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 196
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 201
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 201
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 201
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 201
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 201
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 201
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 201
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 201
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 201
diff changeset
    31
 *
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 34
diff changeset
    32
 *****************************************************************************/
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    34
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    35
   \file
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    36
   EtherCAT master driver module.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    37
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    38
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    39
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    40
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <linux/module.h>
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include <linux/kernel.h>
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include <linux/init.h>
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
184
2fc86cec12df Macro for SysFS attribute definition
Florian Pose <fp@igh-essen.com>
parents: 178
diff changeset
    45
#include "globals.h"
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    46
#include "master.h"
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    47
#include "device.h"
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    48
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    49
/*****************************************************************************/
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    50
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    51
int __init ec_init_module(void);
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    52
void __exit ec_cleanup_module(void);
52
c0405659a74a Neues Interface.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    53
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 34
diff changeset
    54
/*****************************************************************************/
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 34
diff changeset
    55
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
    56
static int ec_master_count = 1; /**< parameter value, number of masters */
321
64e20e6e9d0b Renamed master parameter ec_eoe_devices to ec_eoeif_count.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    57
static int ec_eoeif_count = 0; /**< parameter value, number of EoE interf. */
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
    58
static struct list_head ec_masters; /**< list of masters */
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
    59
static dev_t device_number;
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 34
diff changeset
    61
/*****************************************************************************/
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 34
diff changeset
    62
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    63
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    64
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
    65
module_param(ec_master_count, int, S_IRUGO);
321
64e20e6e9d0b Renamed master parameter ec_eoe_devices to ec_eoeif_count.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    66
module_param(ec_eoeif_count, int, S_IRUGO);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
    67
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
    68
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
    69
MODULE_DESCRIPTION("EtherCAT master driver module");
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
MODULE_LICENSE("GPL");
382
72500991bcc3 Altered master version string.
Florian Pose <fp@igh-essen.com>
parents: 381
diff changeset
    71
MODULE_VERSION(EC_MASTER_VERSION);
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    72
MODULE_PARM_DESC(ec_master_count, "number of EtherCAT masters to initialize");
321
64e20e6e9d0b Renamed master parameter ec_eoe_devices to ec_eoeif_count.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    73
MODULE_PARM_DESC(ec_eoeif_count, "number of EoE interfaces per master");
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    74
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    75
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    76
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    77
/*****************************************************************************/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    78
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    79
/**
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    80
   Module initialization.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    81
   Initializes \a ec_master_count masters.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
    82
   \return 0 on success, else < 0
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    83
*/
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    84
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
    85
int __init ec_init_module(void)
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
{
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
    87
    unsigned int i;
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
    88
    ec_master_t *master, *next;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
    89
382
72500991bcc3 Altered master version string.
Florian Pose <fp@igh-essen.com>
parents: 381
diff changeset
    90
    EC_INFO("Master driver %s\n", EC_MASTER_VERSION);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
    91
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
    92
    if (ec_master_count < 1) {
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
    93
        EC_ERR("Invalid ec_master_count: %i\n", ec_master_count);
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
    94
        goto out_return;
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
    95
    }
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
    96
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
    97
    if (alloc_chrdev_region(&device_number, 0, ec_master_count, "EtherCAT")) {
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
    98
        EC_ERR("Failed to allocate device number!\n");
127
e67c80a76de4 Code aufger?umt und kleines Speicherleck entdeckt.
Florian Pose <fp@igh-essen.com>
parents: 111
diff changeset
    99
        goto out_return;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   100
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   101
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 79
diff changeset
   102
    EC_INFO("Initializing %i EtherCAT master(s)...\n", ec_master_count);
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 79
diff changeset
   103
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   104
    INIT_LIST_HEAD(&ec_masters);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   105
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   106
    for (i = 0; i < ec_master_count; i++) {
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   107
        if (!(master =
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   108
              (ec_master_t *) kmalloc(sizeof(ec_master_t), GFP_KERNEL))) {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   109
            EC_ERR("Failed to allocate memory for EtherCAT master %i.\n", i);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   110
            goto out_free;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   111
        }
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   112
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   113
        if (ec_master_init(master, i, ec_eoeif_count, device_number))
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   114
            goto out_free;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   115
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   116
        if (kobject_add(&master->kobj)) {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   117
            EC_ERR("Failed to add kobj.\n");
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   118
            kobject_put(&master->kobj); // free master
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   119
            goto out_free;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   120
        }
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   121
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   122
        list_add_tail(&master->list, &ec_masters);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   123
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   124
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 79
diff changeset
   125
    EC_INFO("Master driver initialized.\n");
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   126
    return 0;
127
e67c80a76de4 Code aufger?umt und kleines Speicherleck entdeckt.
Florian Pose <fp@igh-essen.com>
parents: 111
diff changeset
   127
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   128
 out_free:
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   129
    list_for_each_entry_safe(master, next, &ec_masters, list) {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   130
        list_del(&master->list);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   131
        kobject_del(&master->kobj);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   132
        kobject_put(&master->kobj);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   133
    }
127
e67c80a76de4 Code aufger?umt und kleines Speicherleck entdeckt.
Florian Pose <fp@igh-essen.com>
parents: 111
diff changeset
   134
 out_return:
e67c80a76de4 Code aufger?umt und kleines Speicherleck entdeckt.
Florian Pose <fp@igh-essen.com>
parents: 111
diff changeset
   135
    return -1;
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
}
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 34
diff changeset
   138
/*****************************************************************************/
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   141
   Module cleanup.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   142
   Clears all master instances.
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
*/
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   145
void __exit ec_cleanup_module(void)
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
{
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   147
    ec_master_t *master, *next;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   148
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 79
diff changeset
   149
    EC_INFO("Cleaning up master driver...\n");
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   150
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   151
    list_for_each_entry_safe(master, next, &ec_masters, list) {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   152
        list_del(&master->list);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   153
        kobject_del(&master->kobj);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   154
        kobject_put(&master->kobj); // free master
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   155
    }
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   156
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   157
    unregister_chrdev_region(device_number, ec_master_count);
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 356
diff changeset
   158
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 79
diff changeset
   159
    EC_INFO("Master driver cleaned up.\n");
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
}
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   162
/*****************************************************************************/
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   163
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   164
/**
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   165
   Gets a handle to a certain master.
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   166
   \returns pointer to master
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   167
*/
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   168
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   169
ec_master_t *ec_find_master(unsigned int master_index /**< master index */)
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   170
{
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   171
    ec_master_t *master;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   172
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   173
    list_for_each_entry(master, &ec_masters, list) {
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   174
        if (master->index == master_index) return master;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   175
    }
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   176
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   177
    EC_ERR("Master %i does not exist!\n", master_index);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   178
    return NULL;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   179
}
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   180
196
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   181
/*****************************************************************************/
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   182
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   183
/**
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   184
   Outputs frame contents for debugging purposes.
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   185
*/
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   186
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   187
void ec_print_data(const uint8_t *data, /**< pointer to data */
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   188
                   size_t size /**< number of bytes to output */
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   189
                   )
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   190
{
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   191
    unsigned int i;
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   192
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   193
    EC_DBG("");
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   194
    for (i = 0; i < size; i++) {
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   195
        printk("%02X ", data[i]);
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   196
        if ((i + 1) % 16 == 0) {
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   197
            printk("\n");
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   198
            EC_DBG("");
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   199
        }
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   200
    }
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   201
    printk("\n");
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   202
}
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   203
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   204
/*****************************************************************************/
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   205
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   206
/**
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   207
   Outputs frame contents and differences for debugging purposes.
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   208
*/
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   209
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   210
void ec_print_data_diff(const uint8_t *d1, /**< first data */
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   211
                        const uint8_t *d2, /**< second data */
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   212
                        size_t size /** number of bytes to output */
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   213
                        )
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   214
{
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   215
    unsigned int i;
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   216
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   217
    EC_DBG("");
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   218
    for (i = 0; i < size; i++) {
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   219
        if (d1[i] == d2[i]) printk(".. ");
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   220
        else printk("%02X ", d2[i]);
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   221
        if ((i + 1) % 16 == 0) {
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   222
            printk("\n");
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   223
            EC_DBG("");
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   224
        }
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   225
    }
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   226
    printk("\n");
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   227
}
f8a1e9f364a3 Introduced version number define.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   228
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   229
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   230
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   231
/**
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   232
   Prints slave states in clear text.
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   233
*/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   234
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   235
size_t ec_state_string(uint8_t states, /**< slave states */
403
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 383
diff changeset
   236
                       char *buffer /**< target buffer
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 383
diff changeset
   237
                                       (min. EC_STATE_STRING_SIZE bytes) */
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   238
                       )
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   239
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   240
    off_t off = 0;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   241
    unsigned int first = 1;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   242
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   243
    if (!states) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   244
        off += sprintf(buffer + off, "(unknown)");
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   245
        return off;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   246
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   247
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   248
    if (states & EC_SLAVE_STATE_INIT) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   249
        off += sprintf(buffer + off, "INIT");
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   250
        first = 0;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   251
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   252
    if (states & EC_SLAVE_STATE_PREOP) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   253
        if (!first) off += sprintf(buffer + off, ", ");
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   254
        off += sprintf(buffer + off, "PREOP");
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   255
        first = 0;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   256
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   257
    if (states & EC_SLAVE_STATE_SAVEOP) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   258
        if (!first) off += sprintf(buffer + off, ", ");
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   259
        off += sprintf(buffer + off, "SAVEOP");
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   260
        first = 0;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   261
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   262
    if (states & EC_SLAVE_STATE_OP) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   263
        if (!first) off += sprintf(buffer + off, ", ");
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   264
        off += sprintf(buffer + off, "OP");
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   265
    }
403
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 383
diff changeset
   266
    if (states & EC_SLAVE_STATE_ACK_ERR) {
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 383
diff changeset
   267
        if (!first) off += sprintf(buffer + off, ", ");
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 383
diff changeset
   268
        off += sprintf(buffer + off, "ERR");
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 383
diff changeset
   269
    }
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   270
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   271
    return off;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   272
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 249
diff changeset
   273
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   274
/******************************************************************************
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   275
 *  Device interface
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   276
 *****************************************************************************/
33
f4171b8aadf8 Master-Reservierung und Use-Count f?r NIC-Treiber.
Florian Pose <fp@igh-essen.com>
parents: 27
diff changeset
   277
f4171b8aadf8 Master-Reservierung und Use-Count f?r NIC-Treiber.
Florian Pose <fp@igh-essen.com>
parents: 27
diff changeset
   278
/**
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   279
   Connects an EtherCAT device to a certain master.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   280
   The master will use the device for sending and receiving frames. It is
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   281
   required that no other instance (for example the kernel IP stack) uses
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   282
   the device.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   283
   \return 0 on success, else < 0
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   284
   \ingroup DeviceInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   285
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   286
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   287
ec_device_t *ecdev_register(unsigned int master_index, /**< master index */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   288
                            struct net_device *net_dev, /**< net_device of
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   289
                                                           the device */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   290
                            ec_isr_t isr, /**< interrupt service routine */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   291
                            struct module *module /**< pointer to the module */
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   292
                            )
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 88
diff changeset
   293
{
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   294
    ec_master_t *master;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   295
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   296
    if (!(master = ec_find_master(master_index))) return NULL;
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   297
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   298
    if (down_interruptible(&master->device_sem)) {
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   299
        EC_ERR("Interrupted while waiting for device!\n");
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   300
        goto out_return;
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   301
    }
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   302
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   303
    if (master->device) {
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 79
diff changeset
   304
        EC_ERR("Master %i already has a device!\n", master_index);
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   305
        goto out_up;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   306
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   307
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   308
    if (!(master->device =
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   309
          (ec_device_t *) kmalloc(sizeof(ec_device_t), GFP_KERNEL))) {
161
ddb7266d1c56 Bugfix: Discovered memory leak.
Florian Pose <fp@igh-essen.com>
parents: 152
diff changeset
   310
        EC_ERR("Failed to allocate device!\n");
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   311
        goto out_up;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   312
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   313
127
e67c80a76de4 Code aufger?umt und kleines Speicherleck entdeckt.
Florian Pose <fp@igh-essen.com>
parents: 111
diff changeset
   314
    if (ec_device_init(master->device, master, net_dev, isr, module)) {
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   315
        EC_ERR("Failed to init device!\n");
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   316
        goto out_free;
127
e67c80a76de4 Code aufger?umt und kleines Speicherleck entdeckt.
Florian Pose <fp@igh-essen.com>
parents: 111
diff changeset
   317
    }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   318
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   319
    up(&master->device_sem);
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   320
    return master->device;
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   321
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   322
 out_free:
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   323
    kfree(master->device);
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   324
    master->device = NULL;
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   325
 out_up:
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   326
    up(&master->device_sem);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   327
 out_return:
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   328
    return NULL;
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 88
diff changeset
   329
}
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 88
diff changeset
   330
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 88
diff changeset
   331
/*****************************************************************************/
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 88
diff changeset
   332
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 88
diff changeset
   333
/**
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   334
   Disconnect an EtherCAT device from the master.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   335
   The device is disconnected from the master and all device ressources
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   336
   are freed.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   337
   \attention Before calling this function, the ecdev_stop() function has
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   338
   to be called, to be sure that the master does not use the device any more.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   339
   \ingroup DeviceInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   340
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   341
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   342
void ecdev_unregister(unsigned int master_index, /**< master index */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   343
                      ec_device_t *device /**< EtherCAT device */
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   344
                      )
55
059a9e712aa7 Mit neuer Schnittstelle wieder lauff?hig.
Florian Pose <fp@igh-essen.com>
parents: 54
diff changeset
   345
{
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   346
    ec_master_t *master;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   347
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   348
    if (!(master = ec_find_master(master_index))) return;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   349
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   350
    down(&master->device_sem);
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   351
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   352
    if (!master->device || master->device != device) {
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   353
        up(&master->device_sem);
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 79
diff changeset
   354
        EC_WARN("Unable to unregister device!\n");
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   355
        return;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   356
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   357
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   358
    ec_device_clear(master->device);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   359
    kfree(master->device);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   360
    master->device = NULL;
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   361
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   362
    up(&master->device_sem);
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   363
}
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   364
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   365
/*****************************************************************************/
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   366
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   367
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   368
   Starts the master associated with the device.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   369
   This function has to be called by the network device driver to tell the
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   370
   master that the device is ready to send and receive data. The master
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   371
   will enter the idle mode then.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   372
   \ingroup DeviceInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   373
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   374
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   375
int ecdev_start(unsigned int master_index /**< master index */)
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   376
{
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   377
    ec_master_t *master;
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   378
    if (!(master = ec_find_master(master_index))) return -1;
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   379
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   380
    if (ec_device_open(master->device)) {
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   381
        EC_ERR("Failed to open device!\n");
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   382
        return -1;
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   383
    }
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   384
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   385
    ec_master_idle_start(master);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   386
    return 0;
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   387
}
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   388
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   389
/*****************************************************************************/
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   390
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   391
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   392
   Stops the master associated with the device.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   393
   Tells the master to stop using the device for frame IO. Has to be called
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   394
   before unregistering the device.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   395
   \ingroup DeviceInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   396
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   397
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   398
void ecdev_stop(unsigned int master_index /**< master index */)
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   399
{
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   400
    ec_master_t *master;
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   401
    if (!(master = ec_find_master(master_index))) return;
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   402
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   403
    ec_master_idle_stop(master);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   404
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   405
    if (ec_device_close(master->device))
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   406
        EC_WARN("Failed to close device!\n");
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   407
}
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   408
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   409
/******************************************************************************
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   410
 *  Realtime interface
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   411
 *****************************************************************************/
33
f4171b8aadf8 Master-Reservierung und Use-Count f?r NIC-Treiber.
Florian Pose <fp@igh-essen.com>
parents: 27
diff changeset
   412
f4171b8aadf8 Master-Reservierung und Use-Count f?r NIC-Treiber.
Florian Pose <fp@igh-essen.com>
parents: 27
diff changeset
   413
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   414
   Reserves an EtherCAT master for realtime operation.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   415
   \return pointer to reserved master, or NULL on error
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   416
   \ingroup RealtimeInterface
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 88
diff changeset
   417
*/
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 88
diff changeset
   418
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   419
ec_master_t *ecrt_request_master(unsigned int master_index
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   420
                                 /**< master index */
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   421
                                 )
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   422
{
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   423
    ec_master_t *master;
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   424
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   425
    EC_INFO("Requesting master %i...\n", master_index);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   426
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   427
    if (!(master = ec_find_master(master_index))) goto out_return;
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   428
378
8fe6cd43787a Replaced master's reserved flag by atomic_t available.
Florian Pose <fp@igh-essen.com>
parents: 377
diff changeset
   429
    if (!atomic_dec_and_test(&master->available)) {
8fe6cd43787a Replaced master's reserved flag by atomic_t available.
Florian Pose <fp@igh-essen.com>
parents: 377
diff changeset
   430
        atomic_inc(&master->available);
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   431
        EC_ERR("Master %i is already in use!\n", master_index);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   432
        goto out_return;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   433
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   434
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   435
    if (down_interruptible(&master->device_sem)) {
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   436
        EC_ERR("Interrupted while waiting for device!\n");
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   437
        goto out_release;
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   438
    }
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   439
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   440
    if (!master->device) {
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   441
        up(&master->device_sem);
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   442
        EC_ERR("Master %i has no assigned device!\n", master_index);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   443
        goto out_release;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   444
    }
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   445
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   446
    if (!try_module_get(master->device->module)) {
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   447
        up(&master->device_sem);
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   448
        EC_ERR("Device module is unloading!\n");
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   449
        goto out_release;
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   450
    }
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   451
381
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   452
    up(&master->device_sem);
006d3653701d Fixed race on duplicate device registering or device unregistering while requesting master.
Florian Pose <fp@igh-essen.com>
parents: 378
diff changeset
   453
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   454
    if (!master->device->link_state) {
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   455
        EC_ERR("Link is DOWN.\n");
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   456
        goto out_module_put;
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   457
    }
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   458
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   459
    ec_master_reset(master); // also stops idle mode
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 321
diff changeset
   460
    master->mode = EC_MASTER_MODE_OPERATION;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   461
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   462
    if (ec_master_measure_bus_time(master)) {
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   463
        EC_ERR("Bus time measuring failed!\n");
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   464
        goto out_reset;
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   465
    }
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   466
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   467
    if (ec_master_bus_scan(master)) {
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 79
diff changeset
   468
        EC_ERR("Bus scan failed!\n");
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   469
        goto out_reset;
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   470
    }
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   471
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   472
    EC_INFO("Successfully requested master %i.\n", master_index);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   473
    return master;
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   474
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   475
 out_reset:
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   476
    ec_master_reset(master);
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   477
    ec_master_idle_start(master);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   478
 out_module_put:
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   479
    module_put(master->device->module);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   480
 out_release:
378
8fe6cd43787a Replaced master's reserved flag by atomic_t available.
Florian Pose <fp@igh-essen.com>
parents: 377
diff changeset
   481
    atomic_inc(&master->available);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   482
 out_return:
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   483
    EC_ERR("Failed to request master %i.\n", master_index);
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 64
diff changeset
   484
    return NULL;
27
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   485
}
d75ef6b46e33 EtherCAT-Master in eigenes Modul ausgelagert.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   486
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 34
diff changeset
   487
/*****************************************************************************/
33
f4171b8aadf8 Master-Reservierung und Use-Count f?r NIC-Treiber.
Florian Pose <fp@igh-essen.com>
parents: 27
diff changeset
   488
f4171b8aadf8 Master-Reservierung und Use-Count f?r NIC-Treiber.
Florian Pose <fp@igh-essen.com>
parents: 27
diff changeset
   489
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   490
   Releases a reserved EtherCAT master.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   491
   \ingroup RealtimeInterface
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   492
*/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   493
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 191
diff changeset
   494
void ecrt_release_master(ec_master_t *master /**< EtherCAT master */)
33
f4171b8aadf8 Master-Reservierung und Use-Count f?r NIC-Treiber.
Florian Pose <fp@igh-essen.com>
parents: 27
diff changeset
   495
{
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   496
    EC_INFO("Releasing master %i...\n", master->index);
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   497
378
8fe6cd43787a Replaced master's reserved flag by atomic_t available.
Florian Pose <fp@igh-essen.com>
parents: 377
diff changeset
   498
    if (atomic_read(&master->available)) {
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   499
        EC_ERR("Master %i was never requested!\n", master->index);
88
98335157e54e Bessere Ausgaben beim Starten und beenden.
Florian Pose <fp@igh-essen.com>
parents: 85
diff changeset
   500
        return;
98335157e54e Bessere Ausgaben beim Starten und beenden.
Florian Pose <fp@igh-essen.com>
parents: 85
diff changeset
   501
    }
98335157e54e Bessere Ausgaben beim Starten und beenden.
Florian Pose <fp@igh-essen.com>
parents: 85
diff changeset
   502
98335157e54e Bessere Ausgaben beim Starten und beenden.
Florian Pose <fp@igh-essen.com>
parents: 85
diff changeset
   503
    ec_master_reset(master);
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 305
diff changeset
   504
    ec_master_idle_start(master);
151
1961b674466c Plugfest: master_open()/close() ausgelagert.
Florian Pose <fp@igh-essen.com>
parents: 127
diff changeset
   505
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   506
    module_put(master->device->module);
378
8fe6cd43787a Replaced master's reserved flag by atomic_t available.
Florian Pose <fp@igh-essen.com>
parents: 377
diff changeset
   507
    atomic_inc(&master->available);
178
b84f69db8566 MERGE branches/sysfs -> trunk (whole SysFS implementation)
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   508
377
ecac8252f114 Changes in ecrt_request_master(); minor output changes.
Florian Pose <fp@igh-essen.com>
parents: 361
diff changeset
   509
    EC_INFO("Successfully released master %i.\n", master->index);
88
98335157e54e Bessere Ausgaben beim Starten und beenden.
Florian Pose <fp@igh-essen.com>
parents: 85
diff changeset
   510
    return;
33
f4171b8aadf8 Master-Reservierung und Use-Count f?r NIC-Treiber.
Florian Pose <fp@igh-essen.com>
parents: 27
diff changeset
   511
}
f4171b8aadf8 Master-Reservierung und Use-Count f?r NIC-Treiber.
Florian Pose <fp@igh-essen.com>
parents: 27
diff changeset
   512
39
6965c23a6826 likely/unlikely, Fehlermeldungen in zyklischem Code begrenzt und Kommentare ge??ndert.
Florian Pose <fp@igh-essen.com>
parents: 34
diff changeset
   513
/*****************************************************************************/
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   514
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   515
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   516
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   517
module_init(ec_init_module);
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   518
module_exit(ec_cleanup_module);
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   519
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   520
EXPORT_SYMBOL(ecdev_register);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   521
EXPORT_SYMBOL(ecdev_unregister);
191
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   522
EXPORT_SYMBOL(ecdev_start);
ca805255a935 Prepared Free-Run mode
Florian Pose <fp@igh-essen.com>
parents: 184
diff changeset
   523
EXPORT_SYMBOL(ecdev_stop);
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   524
EXPORT_SYMBOL(ecrt_request_master);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   525
EXPORT_SYMBOL(ecrt_release_master);
54
7506e67dd122 Vereinheitlichte Schnittstellen, Include-Verzeichnis und Module getrennt.
Florian Pose <fp@igh-essen.com>
parents: 52
diff changeset
   526
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   527
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   528
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   529
/*****************************************************************************/