master/datagram.c
author Florian Pose <fp@igh-essen.com>
Tue, 19 Feb 2008 16:18:01 +0000
changeset 802 b947d0b09f9a
parent 758 8fa6f825eb7d
child 809 ec4ef8911824
permissions -rw-r--r--
Renamed ec_fsm_mapping_t to ec_fsm_pdo_mapping_t.
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     6
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     8
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
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: 237
diff changeset
    12
 *  License, or (at your option) any later version.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    13
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    17
 *  GNU General Public License for more details.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    18
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
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: 237
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: 237
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: 237
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: 237
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: 237
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: 237
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: 237
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    31
 *
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
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
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    36
   Methods of an EtherCAT datagram.
199
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
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <linux/slab.h>
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    43
#include "datagram.h"
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "master.h"
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/*****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    48
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    49
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
#define EC_FUNC_HEADER \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    51
    if (unlikely(ec_datagram_prealloc(datagram, data_size))) \
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    52
        return -1; \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    53
    datagram->index = 0; \
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    54
    datagram->working_counter = 0; \
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    55
    datagram->state = EC_DATAGRAM_INIT;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    57
#define EC_FUNC_FOOTER \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    58
    datagram->data_size = data_size; \
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    59
    memset(datagram->data, 0x00, data_size); \
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    60
    return 0;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    61
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    62
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    63
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    64
/*****************************************************************************/
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    65
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    66
/**
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    67
   Datagram constructor.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    68
*/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    69
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    70
void ec_datagram_init(ec_datagram_t *datagram /**< EtherCAT datagram */)
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    71
{
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
    72
    INIT_LIST_HEAD(&datagram->queue); // mark as unqueued
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    73
    datagram->type = EC_DATAGRAM_NONE;
708
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
    74
    memset(datagram->address, 0x00, EC_ADDR_LEN);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    75
    datagram->data = NULL;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    76
    datagram->mem_size = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    77
    datagram->data_size = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    78
    datagram->index = 0x00;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    79
    datagram->working_counter = 0x00;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    80
    datagram->state = EC_DATAGRAM_INIT;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    81
    datagram->cycles_sent = 0;
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
    82
    datagram->jiffies_sent = 0;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
    83
    datagram->cycles_received = 0;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
    84
    datagram->jiffies_received = 0;
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    85
    datagram->skip_count = 0;
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    86
    datagram->stats_output_jiffies = 0;
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    87
    datagram->name[0] = 0x00;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    88
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    89
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    90
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    91
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    92
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    93
   Datagram destructor.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    94
*/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    95
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    96
void ec_datagram_clear(ec_datagram_t *datagram /**< EtherCAT datagram */)
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    97
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    98
    if (datagram->data) kfree(datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    99
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   100
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   101
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   102
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   103
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   104
   Allocates datagram data memory.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   105
   If the allocated memory is already larger than requested, nothing ist done.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   106
   \return 0 in case of success, else < 0
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   107
*/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   108
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   109
int ec_datagram_prealloc(ec_datagram_t *datagram, /**< EtherCAT datagram */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   110
                         size_t size /**< New size in bytes */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   111
                         )
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   112
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   113
    if (size <= datagram->mem_size) return 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   114
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   115
    if (datagram->data) {
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   116
        kfree(datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   117
        datagram->data = NULL;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   118
        datagram->mem_size = 0;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   119
    }
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   120
514
3e5989834735 Datagram preallocation with ATOMIC flag, because it is calles in timer context.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   121
    if (!(datagram->data = kmalloc(size, GFP_ATOMIC))) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   122
        EC_ERR("Failed to allocate %i bytes of datagram memory!\n", size);
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   123
        return -1;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   124
    }
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   125
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   126
    datagram->mem_size = size;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   127
    return 0;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   128
}
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
/*****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
/**
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   133
   Initializes an EtherCAT NPRD datagram.
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
   Node-adressed physical read.
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   135
   \return 0 in case of success, else < 0
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
*/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   138
int ec_datagram_nprd(ec_datagram_t *datagram,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   139
                     /**< EtherCAT datagram */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   140
                     uint16_t node_address,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   141
                     /**< configured station address */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   142
                     uint16_t offset,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   143
                     /**< physical memory address */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   144
                     size_t data_size
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   145
                     /**< number of bytes to read */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   146
                     )
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   147
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   148
    if (unlikely(node_address == 0x0000))
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   149
        EC_WARN("Using node address 0x0000!\n");
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   150
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   151
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   152
    datagram->type = EC_DATAGRAM_NPRD;
708
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   153
    EC_WRITE_U16(datagram->address, node_address);
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   154
    EC_WRITE_U16(datagram->address + 2, offset);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   155
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   156
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   157
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   158
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   159
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   160
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   161
   Initializes an EtherCAT NPWR datagram.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   162
   Node-adressed physical write.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   163
   \return 0 in case of success, else < 0
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   164
*/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   165
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   166
int ec_datagram_npwr(ec_datagram_t *datagram,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   167
                     /**< EtherCAT datagram */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   168
                     uint16_t node_address,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   169
                     /**< configured station address */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   170
                     uint16_t offset,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   171
                     /**< physical memory address */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   172
                     size_t data_size
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   173
                     /**< number of bytes to write */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   174
                     )
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   175
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   176
    if (unlikely(node_address == 0x0000))
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   177
        EC_WARN("Using node address 0x0000!\n");
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   178
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   179
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   180
    datagram->type = EC_DATAGRAM_NPWR;
708
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   181
    EC_WRITE_U16(datagram->address, node_address);
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   182
    EC_WRITE_U16(datagram->address + 2, offset);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   183
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   184
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   185
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   186
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   187
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   188
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   189
   Initializes an EtherCAT APRD datagram.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   190
   Autoincrement physical read.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   191
   \return 0 in case of success, else < 0
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   192
*/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   193
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   194
int ec_datagram_aprd(ec_datagram_t *datagram,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   195
                     /**< EtherCAT datagram */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   196
                     uint16_t ring_position,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   197
                     /**< auto-increment position */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   198
                     uint16_t offset,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   199
                     /**< physical memory address */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   200
                     size_t data_size
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   201
                     /**< number of bytes to read */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   202
                     )
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   203
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   204
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   205
    datagram->type = EC_DATAGRAM_APRD;
708
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   206
    EC_WRITE_S16(datagram->address, (int16_t) ring_position * (-1));
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   207
    EC_WRITE_U16(datagram->address + 2, offset);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   208
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   209
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   210
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   211
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   212
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   213
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   214
   Initializes an EtherCAT APWR datagram.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   215
   Autoincrement physical write.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   216
   \return 0 in case of success, else < 0
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   217
*/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   218
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   219
int ec_datagram_apwr(ec_datagram_t *datagram,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   220
                     /**< EtherCAT datagram */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   221
                     uint16_t ring_position,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   222
                     /**< auto-increment position */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   223
                     uint16_t offset,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   224
                     /**< physical memory address */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   225
                     size_t data_size
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   226
                     /**< number of bytes to write */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   227
                     )
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   228
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   229
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   230
    datagram->type = EC_DATAGRAM_APWR;
708
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   231
    EC_WRITE_S16(datagram->address, (int16_t) ring_position * (-1));
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   232
    EC_WRITE_U16(datagram->address + 2, offset);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   233
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   234
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   235
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   236
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   237
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   238
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   239
   Initializes an EtherCAT BRD datagram.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   240
   Broadcast read.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   241
   \return 0 in case of success, else < 0
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   242
*/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   243
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   244
int ec_datagram_brd(ec_datagram_t *datagram,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   245
                    /**< EtherCAT datagram */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   246
                    uint16_t offset,
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   247
                    /**< physical memory address */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   248
                    size_t data_size
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   249
                    /**< number of bytes to read */
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   250
                    )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   252
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   253
    datagram->type = EC_DATAGRAM_BRD;
708
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   254
    EC_WRITE_U16(datagram->address, 0x0000);
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   255
    EC_WRITE_U16(datagram->address + 2, offset);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   256
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   257
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   258
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   259
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   260
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   261
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   262
   Initializes an EtherCAT BWR datagram.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   263
   Broadcast write.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   264
   \return 0 in case of success, else < 0
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   265
*/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   266
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   267
int ec_datagram_bwr(ec_datagram_t *datagram,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   268
                    /**< EtherCAT datagram */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   269
                    uint16_t offset,
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   270
                    /**< physical memory address */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   271
                    size_t data_size
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   272
                    /**< number of bytes to write */
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   273
                    )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   275
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   276
    datagram->type = EC_DATAGRAM_BWR;
708
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   277
    EC_WRITE_U16(datagram->address, 0x0000);
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   278
    EC_WRITE_U16(datagram->address + 2, offset);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   279
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   280
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   281
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   282
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   283
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   284
/**
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   285
   Initializes an EtherCAT LRW datagram.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   286
   Logical read write.
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   287
   \return 0 in case of success, else < 0
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   288
*/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   289
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   290
int ec_datagram_lrw(ec_datagram_t *datagram,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   291
                    /**< EtherCAT datagram */
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   292
                    uint32_t offset,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   293
                    /**< logical address */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   294
                    size_t data_size
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   295
                    /**< number of bytes to read/write */
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   296
                    )
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   297
{
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   298
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   299
    datagram->type = EC_DATAGRAM_LRW;
708
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   300
    EC_WRITE_U32(datagram->address, offset);
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   301
    EC_FUNC_FOOTER;
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   302
}
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   303
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   304
/*****************************************************************************/
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   305
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   306
/**
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   307
 * Evaluates the working counter of a single-cast datagram.
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   308
 * Outputs an error message.
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   309
 */
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   310
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   311
void ec_datagram_print_wc_error(
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   312
        const ec_datagram_t *datagram /**< EtherCAT datagram */
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   313
        )
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   314
{
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   315
    if (datagram->working_counter == 0)
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   316
        printk("No response.");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   317
    else if (datagram->working_counter > 1)
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   318
        printk("%u slaves responded!", datagram->working_counter);
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   319
    else
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   320
        printk("Success.");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   321
    printk("\n");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   322
}
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   323
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   324
/*****************************************************************************/
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   325
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   326
/**
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   327
 * Outputs datagram statistics at most every second.
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   328
 */
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   329
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   330
void ec_datagram_output_stats(
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   331
        ec_datagram_t *datagram
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   332
        )
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   333
{
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   334
    if (jiffies - datagram->stats_output_jiffies < HZ) {
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   335
        datagram->stats_output_jiffies = jiffies;
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   336
    
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   337
        if (unlikely(datagram->skip_count)) {
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   338
            EC_WARN("Datagram %x (%s) was SKIPPED %u time%s.\n",
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   339
                    (unsigned int) datagram, datagram->name,
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   340
                    datagram->skip_count,
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   341
                    datagram->skip_count == 1 ? "" : "s");
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   342
            datagram->skip_count = 0;
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   343
        }
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   344
    }
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   345
}
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   346
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   347
/*****************************************************************************/