master/datagram.c
author Florian Pose <fp@igh-essen.com>
Mon, 26 Jan 2009 10:30:17 +0000
changeset 1323 10fbef0a3ac5
parent 1313 ed15eef57d5c
child 1326 ef907b0b5125
permissions -rw-r--r--
merge -r1599:1600 branches/stable-1.4: Removed bashisms from init script.
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 \
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
    51
    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
    52
    if (unlikely(ret)) \
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
    53
        return ret; \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    54
    datagram->index = 0; \
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    55
    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
    56
    datagram->state = EC_DATAGRAM_INIT;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    58
#define EC_FUNC_FOOTER \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    59
    datagram->data_size = 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
816
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    66
/** 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
    67
 *
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    68
 * \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
    69
 */
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    70
static const char *type_strings[] = {
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    71
    "?",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    72
    "APRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    73
    "APWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    74
    "APRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    75
    "FPRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    76
    "FPWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    77
    "FPRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    78
    "BRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    79
    "BWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    80
    "BRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    81
    "LRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    82
    "LWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    83
    "LRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    84
    "ARMW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    85
    "FRMW"
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    86
};
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    87
    
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    88
/*****************************************************************************/
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    89
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    90
/** Constructor.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    91
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
    92
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
    93
{
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
    94
    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
    95
    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
    96
    memset(datagram->address, 0x00, EC_ADDR_LEN);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    97
    datagram->data = NULL;
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    98
    datagram->data_origin = EC_ORIG_INTERNAL;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    99
    datagram->mem_size = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   100
    datagram->data_size = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   101
    datagram->index = 0x00;
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   102
    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
   103
    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
   104
#ifdef EC_HAVE_CYCLES
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   105
    datagram->cycles_sent = 0;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   106
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   107
    datagram->jiffies_sent = 0;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   108
#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
   109
    datagram->cycles_received = 0;
1040
d2527675cdd5 Disable use of CPU timestamp counter by default.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   110
#endif
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   111
    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
   112
    datagram->skip_count = 0;
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   113
    datagram->stats_output_jiffies = 0;
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   114
    memset(datagram->name, 0x00, EC_DATAGRAM_NAME_SIZE);
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   115
}
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   116
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   117
/*****************************************************************************/
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
/** Destructor.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   120
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   121
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
   122
{
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   123
    if (datagram->data_origin == EC_ORIG_INTERNAL && datagram->data)
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   124
        kfree(datagram->data);
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
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   127
/*****************************************************************************/
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   128
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   129
/** Allocates internal payload memory.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   130
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   131
 * 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
   132
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   133
 * \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
   134
 *            is done!
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   135
 *
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   136
 * \return 0 in case of success, otherwise \a -ENOMEM.
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   137
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   138
int ec_datagram_prealloc(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   139
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   140
        size_t size /**< New payload size in bytes. */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   141
        )
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   142
{
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   143
    if (datagram->data_origin == EC_ORIG_EXTERNAL
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   144
            || size <= datagram->mem_size)
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   145
        return 0;
293
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
    if (datagram->data) {
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   148
        kfree(datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   149
        datagram->data = NULL;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   150
        datagram->mem_size = 0;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   151
    }
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   152
998
05a24788f3b2 Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   153
    if (!(datagram->data = kmalloc(size, GFP_KERNEL))) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 816
diff changeset
   154
        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
   155
        return -ENOMEM;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   156
    }
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   157
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   158
    datagram->mem_size = size;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   159
    return 0;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   160
}
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
/*****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   164
/** Fills the datagram payload memory with zeros.
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   165
 */
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   166
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
   167
{
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   168
    memset(datagram->data, 0x00, datagram->data_size);
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   169
}
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   170
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   171
/*****************************************************************************/
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   172
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   173
/** Initializes an EtherCAT APRD datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   174
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   175
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   176
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   177
int ec_datagram_aprd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   178
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   179
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   180
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   181
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   182
        )
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   183
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   184
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   185
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   186
    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
   187
    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
   188
    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
   189
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   190
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   191
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
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   194
/** Initializes an EtherCAT APWR datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   195
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   196
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   197
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   198
int ec_datagram_apwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   199
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   200
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   201
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   202
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   203
        )
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   204
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   205
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   206
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   207
    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
   208
    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
   209
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   210
    EC_FUNC_FOOTER;
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   213
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   214
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   215
/** Initializes an EtherCAT APRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   216
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   217
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   218
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   219
int ec_datagram_aprw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   220
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   221
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   222
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   223
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   224
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   225
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   226
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   227
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   228
    datagram->type = EC_DATAGRAM_APRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   229
    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
   230
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   231
    EC_FUNC_FOOTER;
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   234
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   235
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   236
/** Initializes an EtherCAT ARMW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   237
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   238
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   239
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   240
int ec_datagram_armw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   241
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   242
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   243
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   244
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   245
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   246
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   247
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   248
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   249
    datagram->type = EC_DATAGRAM_ARMW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   250
    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
   251
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   252
    EC_FUNC_FOOTER;
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   255
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   256
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   257
/** Initializes an EtherCAT FPRD datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   258
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   259
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   260
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   261
int ec_datagram_fprd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   262
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   263
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   264
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   265
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   266
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   267
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   268
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   269
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   270
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   271
        EC_WARN("Using configured station address 0x0000!\n");
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
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   274
    datagram->type = EC_DATAGRAM_FPRD;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   275
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   276
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   277
    EC_FUNC_FOOTER;
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   280
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   281
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   282
/** Initializes an EtherCAT FPWR datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   283
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   284
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   285
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   286
int ec_datagram_fpwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   287
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   288
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   289
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   290
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   291
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   292
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   293
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   294
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   295
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   296
        EC_WARN("Using configured station address 0x0000!\n");
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
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   299
    datagram->type = EC_DATAGRAM_FPWR;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   300
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   301
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   302
    EC_FUNC_FOOTER;
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   305
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   306
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   307
/** Initializes an EtherCAT FPRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   308
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   309
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   310
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   311
int ec_datagram_fprw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   312
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   313
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   314
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   315
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   316
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   317
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   318
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   319
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   320
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   321
        EC_WARN("Using configured station address 0x0000!\n");
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
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   324
    datagram->type = EC_DATAGRAM_FPRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   325
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   326
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   327
    EC_FUNC_FOOTER;
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   330
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   331
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   332
/** Initializes an EtherCAT FRMW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   333
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   334
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   335
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   336
int ec_datagram_frmw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   337
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   338
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   339
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   340
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   341
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   342
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   343
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   344
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   345
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   346
        EC_WARN("Using configured station address 0x0000!\n");
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   347
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   348
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   349
    datagram->type = EC_DATAGRAM_FRMW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   350
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   351
    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
   352
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   353
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   354
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   355
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   356
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   357
/** Initializes an EtherCAT BRD datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   358
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   359
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   360
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   361
int ec_datagram_brd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   362
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   363
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   364
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   365
        )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   367
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   368
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   369
    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
   370
    EC_WRITE_U16(datagram->address, 0x0000);
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   371
    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
   372
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   373
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   374
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   375
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   376
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   377
/** Initializes an EtherCAT BWR datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   378
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   379
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   380
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   381
int ec_datagram_bwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   382
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   383
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   384
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   385
        )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   386
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   387
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   388
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   389
    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
   390
    EC_WRITE_U16(datagram->address, 0x0000);
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   391
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   392
    EC_FUNC_FOOTER;
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   395
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   396
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   397
/** Initializes an EtherCAT BRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   398
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   399
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   400
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   401
int ec_datagram_brw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   402
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   403
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   404
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   405
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   406
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   407
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   408
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   409
    datagram->type = EC_DATAGRAM_BRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   410
    EC_WRITE_U16(datagram->address, 0x0000);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   411
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   412
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   413
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   414
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   415
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   416
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   417
/** Initializes an EtherCAT LRD datagram.
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   418
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   419
 * \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
   420
 *            bytes large.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   421
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   422
 * \return Return value of ec_datagram_prealloc().
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   423
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   424
int ec_datagram_lrd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   425
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   426
        uint32_t offset, /**< Logical address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   427
        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
   428
        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
   429
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   430
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   431
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   432
    datagram->data = external_memory;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   433
    datagram->data_origin = EC_ORIG_EXTERNAL;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   434
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   435
    datagram->type = EC_DATAGRAM_LRD;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   436
    EC_WRITE_U32(datagram->address, offset);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   437
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   438
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   439
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   440
/*****************************************************************************/
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
/** Initializes an EtherCAT LWR datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   443
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   444
 * \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
   445
 *            bytes large.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   446
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   447
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   448
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   449
int ec_datagram_lwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   450
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   451
        uint32_t offset, /**< Logical address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   452
        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
   453
        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
   454
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   455
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   456
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   457
    datagram->data = external_memory;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   458
    datagram->data_origin = EC_ORIG_EXTERNAL;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   459
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   460
    datagram->type = EC_DATAGRAM_LWR;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   461
    EC_WRITE_U32(datagram->address, offset);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   462
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   463
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   464
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   465
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   466
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   467
/** Initializes an EtherCAT LRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   468
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   469
 * \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
   470
 *            bytes large.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   471
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   472
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   473
 */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   474
int ec_datagram_lrw(
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   475
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   476
        uint32_t offset, /**< Logical address. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   477
        size_t data_size, /**< Number of bytes to read/write. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   478
        uint8_t *external_memory /**< Pointer to the memory to use. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   479
        )
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   480
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   481
    int ret;
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   482
    datagram->data = external_memory;
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   483
    datagram->data_origin = EC_ORIG_EXTERNAL;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   484
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   485
    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
   486
    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
   487
    EC_FUNC_FOOTER;
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   488
}
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   489
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   490
/*****************************************************************************/
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   491
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   492
/** Evaluates the working counter of a single-cast datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   493
 *
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   494
 * Outputs an error message.
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   495
 */
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   496
void ec_datagram_print_wc_error(
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   497
        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
   498
        )
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   499
{
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   500
    if (datagram->working_counter == 0)
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   501
        printk("No response.");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   502
    else if (datagram->working_counter > 1)
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   503
        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
   504
    else
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   505
        printk("Success.");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   506
    printk("\n");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   507
}
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   508
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   509
/*****************************************************************************/
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   510
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   511
/** Outputs datagram statistics at most every second.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   512
 */
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   513
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
   514
        ec_datagram_t *datagram
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   515
        )
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   516
{
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   517
    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
   518
        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
   519
    
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   520
        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
   521
            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
   522
                    (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
   523
                    datagram->skip_count,
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   524
                    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
   525
            datagram->skip_count = 0;
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   526
        }
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   527
    }
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   528
}
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   529
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   530
/*****************************************************************************/
816
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   531
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   532
/** Returns a string describing the datagram type.
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
const char *ec_datagram_type_string(
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   535
        const ec_datagram_t *datagram /**< EtherCAT datagram. */
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   536
        )
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   537
{
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   538
    return type_strings[datagram->type];
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   539
}
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   540
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   541
/*****************************************************************************/