master/datagram.c
author Florian Pose <fp@igh-essen.com>
Mon, 26 Jan 2009 11:51:53 +0000
changeset 1331 7cd33a77f926
parent 1326 ef907b0b5125
child 1333 7b9898062c8f
permissions -rw-r--r--
merge -c1609 branches/stable-1.4: INSTALL, README.
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
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     6
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     8
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    11
 *  published by the Free Software Foundation.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    12
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    16
 *  Public License for more details.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    17
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    22
 *  Using the EtherCAT technology and brand is permitted in compliance with
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    23
 *  the industrial property and similar rights of Beckhoff Automation GmbH.
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    24
 *
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    27
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    28
   \file
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    29
   Methods of an EtherCAT datagram.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    30
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    31
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    32
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    33
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <linux/slab.h>
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    36
#include "datagram.h"
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "master.h"
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    41
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    42
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#define EC_FUNC_HEADER \
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
    44
    ret = ec_datagram_prealloc(datagram, data_size); \
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
    45
    if (unlikely(ret)) \
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
    46
        return ret; \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    47
    datagram->index = 0; \
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    48
    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
    49
    datagram->state = EC_DATAGRAM_INIT;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    51
#define EC_FUNC_FOOTER \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    52
    datagram->data_size = data_size; \
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    53
    return 0;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    54
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    55
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    56
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    57
/*****************************************************************************/
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    58
816
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    59
/** Array of datagram type strings used in ec_datagram_type_string().
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    60
 *
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    61
 * \attention This is indexed by ec_datagram_type_t.
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    62
 */
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    63
static const char *type_strings[] = {
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    64
    "?",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    65
    "APRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    66
    "APWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    67
    "APRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    68
    "FPRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    69
    "FPWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    70
    "FPRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    71
    "BRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    72
    "BWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    73
    "BRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    74
    "LRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    75
    "LWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    76
    "LRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    77
    "ARMW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    78
    "FRMW"
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    79
};
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    80
    
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    81
/*****************************************************************************/
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    82
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    83
/** Constructor.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    84
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
    85
void ec_datagram_init(ec_datagram_t *datagram /**< EtherCAT datagram. */)
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    86
{
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
    87
    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
    88
    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
    89
    memset(datagram->address, 0x00, EC_ADDR_LEN);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    90
    datagram->data = NULL;
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    91
    datagram->data_origin = EC_ORIG_INTERNAL;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    92
    datagram->mem_size = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    93
    datagram->data_size = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    94
    datagram->index = 0x00;
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    95
    datagram->working_counter = 0x0000;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    96
    datagram->state = EC_DATAGRAM_INIT;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
    97
#ifdef EC_HAVE_CYCLES
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    98
    datagram->cycles_sent = 0;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
    99
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   100
    datagram->jiffies_sent = 0;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   101
#ifdef EC_HAVE_CYCLES
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   102
    datagram->cycles_received = 0;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   103
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   104
    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
   105
    datagram->skip_count = 0;
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   106
    datagram->stats_output_jiffies = 0;
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   107
    memset(datagram->name, 0x00, EC_DATAGRAM_NAME_SIZE);
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   108
}
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   109
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   110
/*****************************************************************************/
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   111
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   112
/** Destructor.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   113
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   114
void ec_datagram_clear(ec_datagram_t *datagram /**< EtherCAT datagram. */)
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   115
{
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   116
    if (datagram->data_origin == EC_ORIG_INTERNAL && datagram->data)
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   117
        kfree(datagram->data);
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   118
}
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   119
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   120
/*****************************************************************************/
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   121
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   122
/** Allocates internal payload memory.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   123
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   124
 * If the allocated memory is already larger than requested, nothing ist done.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   125
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   126
 * \attention If external payload memory has been provided, no range checking
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   127
 *            is done!
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   128
 *
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   129
 * \return 0 in case of success, otherwise \a -ENOMEM.
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   130
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   131
int ec_datagram_prealloc(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   132
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   133
        size_t size /**< New payload size in bytes. */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   134
        )
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   135
{
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   136
    if (datagram->data_origin == EC_ORIG_EXTERNAL
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   137
            || size <= datagram->mem_size)
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   138
        return 0;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   139
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   140
    if (datagram->data) {
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   141
        kfree(datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   142
        datagram->data = NULL;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   143
        datagram->mem_size = 0;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   144
    }
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   145
998
05a24788f3b2 Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   146
    if (!(datagram->data = kmalloc(size, GFP_KERNEL))) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 816
diff changeset
   147
        EC_ERR("Failed to allocate %u bytes of datagram memory!\n", size);
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   148
        return -ENOMEM;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   149
    }
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   150
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   151
    datagram->mem_size = size;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   152
    return 0;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   153
}
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
/*****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   157
/** Fills the datagram payload memory with zeros.
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   158
 */
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   159
void ec_datagram_zero(ec_datagram_t *datagram /**< EtherCAT datagram. */)
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   160
{
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   161
    memset(datagram->data, 0x00, datagram->data_size);
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   162
}
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   163
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   164
/*****************************************************************************/
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   165
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   166
/** Initializes an EtherCAT APRD datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   167
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   168
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   169
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   170
int ec_datagram_aprd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   171
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   172
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   173
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   174
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   175
        )
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   176
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   177
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   178
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   179
    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
   180
    EC_WRITE_S16(datagram->address, (int16_t) ring_position * (-1));
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   181
    EC_WRITE_U16(datagram->address + 2, mem_address);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   182
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   183
}
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
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   187
/** Initializes an EtherCAT APWR datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   188
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   189
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   190
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   191
int ec_datagram_apwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   192
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   193
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   194
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   195
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   196
        )
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   197
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   198
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   199
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   200
    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
   201
    EC_WRITE_S16(datagram->address, (int16_t) ring_position * (-1));
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   202
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   203
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   204
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   205
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   206
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   207
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   208
/** Initializes an EtherCAT APRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   209
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   210
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   211
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   212
int ec_datagram_aprw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   213
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   214
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   215
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   216
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   217
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   218
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   219
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   220
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   221
    datagram->type = EC_DATAGRAM_APRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   222
    EC_WRITE_S16(datagram->address, (int16_t) ring_position * (-1));
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   223
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   224
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   225
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   226
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   227
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   228
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   229
/** Initializes an EtherCAT ARMW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   230
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   231
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   232
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   233
int ec_datagram_armw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   234
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   235
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   236
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   237
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   238
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   239
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   240
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   241
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   242
    datagram->type = EC_DATAGRAM_ARMW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   243
    EC_WRITE_S16(datagram->address, (int16_t) ring_position * (-1));
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   244
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   245
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   246
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   247
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   248
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   249
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   250
/** Initializes an EtherCAT FPRD datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   251
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   252
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   253
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   254
int ec_datagram_fprd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   255
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   256
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   257
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   258
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   259
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   260
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   261
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   262
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   263
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   264
        EC_WARN("Using configured station address 0x0000!\n");
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   265
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   266
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   267
    datagram->type = EC_DATAGRAM_FPRD;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   268
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   269
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   270
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   271
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   272
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   273
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   274
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   275
/** Initializes an EtherCAT FPWR datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   276
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   277
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   278
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   279
int ec_datagram_fpwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   280
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   281
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   282
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   283
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   284
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   285
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   286
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   287
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   288
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   289
        EC_WARN("Using configured station address 0x0000!\n");
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   290
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   291
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   292
    datagram->type = EC_DATAGRAM_FPWR;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   293
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   294
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   295
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   296
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   297
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   298
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   299
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   300
/** Initializes an EtherCAT FPRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   301
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   302
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   303
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   304
int ec_datagram_fprw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   305
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   306
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   307
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   308
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   309
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   310
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   311
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   312
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   313
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   314
        EC_WARN("Using configured station address 0x0000!\n");
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   315
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   316
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   317
    datagram->type = EC_DATAGRAM_FPRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   318
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   319
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   320
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   321
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   322
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   323
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   324
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   325
/** Initializes an EtherCAT FRMW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   326
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   327
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   328
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   329
int ec_datagram_frmw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   330
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   331
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   332
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   333
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   334
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   335
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   336
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   337
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   338
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   339
        EC_WARN("Using configured station address 0x0000!\n");
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   340
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   341
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   342
    datagram->type = EC_DATAGRAM_FRMW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   343
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   344
    EC_WRITE_U16(datagram->address + 2, mem_address);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   345
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   346
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   347
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   348
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   349
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   350
/** Initializes an EtherCAT BRD datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   351
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   352
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   353
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   354
int ec_datagram_brd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   355
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   356
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   357
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   358
        )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   360
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   361
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   362
    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
   363
    EC_WRITE_U16(datagram->address, 0x0000);
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   364
    EC_WRITE_U16(datagram->address + 2, mem_address);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   365
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   366
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   367
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   368
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   369
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   370
/** Initializes an EtherCAT BWR datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   371
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   372
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   373
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   374
int ec_datagram_bwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   375
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   376
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   377
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   378
        )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   380
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   381
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   382
    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
   383
    EC_WRITE_U16(datagram->address, 0x0000);
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   384
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   385
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   386
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   387
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   388
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   389
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   390
/** Initializes an EtherCAT BRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   391
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   392
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   393
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   394
int ec_datagram_brw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   395
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   396
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   397
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   398
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   399
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   400
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   401
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   402
    datagram->type = EC_DATAGRAM_BRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   403
    EC_WRITE_U16(datagram->address, 0x0000);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   404
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   405
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   406
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   407
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   408
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   409
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   410
/** Initializes an EtherCAT LRD datagram.
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   411
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   412
 * \attention It is assumed, that the external memory is at least \a data_size
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   413
 *            bytes large.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   414
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   415
 * \return Return value of ec_datagram_prealloc().
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   416
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   417
int ec_datagram_lrd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   418
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   419
        uint32_t offset, /**< Logical address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   420
        size_t data_size, /**< Number of bytes to read/write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   421
        uint8_t *external_memory /**< Pointer to the memory to use. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   422
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   423
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   424
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   425
    datagram->data = external_memory;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   426
    datagram->data_origin = EC_ORIG_EXTERNAL;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   427
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   428
    datagram->type = EC_DATAGRAM_LRD;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   429
    EC_WRITE_U32(datagram->address, offset);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   430
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   431
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   432
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   433
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   434
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   435
/** Initializes an EtherCAT LWR datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   436
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   437
 * \attention It is assumed, that the external memory is at least \a data_size
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   438
 *            bytes large.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   439
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   440
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   441
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   442
int ec_datagram_lwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   443
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   444
        uint32_t offset, /**< Logical address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   445
        size_t data_size, /**< Number of bytes to read/write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   446
        uint8_t *external_memory /**< Pointer to the memory to use. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   447
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   448
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   449
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   450
    datagram->data = external_memory;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   451
    datagram->data_origin = EC_ORIG_EXTERNAL;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   452
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   453
    datagram->type = EC_DATAGRAM_LWR;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   454
    EC_WRITE_U32(datagram->address, offset);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   455
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   456
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   457
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   458
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   459
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   460
/** Initializes an EtherCAT LRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   461
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   462
 * \attention It is assumed, that the external memory is at least \a data_size
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   463
 *            bytes large.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   464
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   465
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   466
 */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   467
int ec_datagram_lrw(
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   468
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   469
        uint32_t offset, /**< Logical address. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   470
        size_t data_size, /**< Number of bytes to read/write. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   471
        uint8_t *external_memory /**< Pointer to the memory to use. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   472
        )
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   473
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   474
    int ret;
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   475
    datagram->data = external_memory;
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   476
    datagram->data_origin = EC_ORIG_EXTERNAL;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   477
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   478
    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
   479
    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
   480
    EC_FUNC_FOOTER;
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   481
}
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   482
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   483
/*****************************************************************************/
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   484
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   485
/** Evaluates the working counter of a single-cast datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   486
 *
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   487
 * Outputs an error message.
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   488
 */
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   489
void ec_datagram_print_wc_error(
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   490
        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
   491
        )
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   492
{
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   493
    if (datagram->working_counter == 0)
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   494
        printk("No response.");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   495
    else if (datagram->working_counter > 1)
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   496
        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
   497
    else
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   498
        printk("Success.");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   499
    printk("\n");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   500
}
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   501
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   502
/*****************************************************************************/
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   503
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   504
/** Outputs datagram statistics at most every second.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   505
 */
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   506
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
   507
        ec_datagram_t *datagram
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   508
        )
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   509
{
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   510
    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
   511
        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
   512
    
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   513
        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
   514
            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
   515
                    (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
   516
                    datagram->skip_count,
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   517
                    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
   518
            datagram->skip_count = 0;
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   519
        }
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   520
    }
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   521
}
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   522
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   523
/*****************************************************************************/
816
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   524
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   525
/** Returns a string describing the datagram type.
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   526
 */
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   527
const char *ec_datagram_type_string(
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   528
        const ec_datagram_t *datagram /**< EtherCAT datagram. */
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   529
        )
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   530
{
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   531
    return type_strings[datagram->type];
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   532
}
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   533
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   534
/*****************************************************************************/