master/datagram.c
author Florian Pose <fp@igh-essen.com>
Mon, 03 Mar 2008 16:22:39 +0000
changeset 854 f4f53be425ac
parent 816 d02761e14eb0
child 986 a486591ba86b
permissions -rw-r--r--
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     6
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     8
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    12
 *  License, or (at your option) any later version.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    13
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    17
 *  GNU General Public License for more details.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    18
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    31
 *
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    34
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    35
   \file
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    36
   Methods of an EtherCAT datagram.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    37
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    38
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    39
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    40
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <linux/slab.h>
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    43
#include "datagram.h"
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "master.h"
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/*****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    48
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    49
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
#define EC_FUNC_HEADER \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    51
    if (unlikely(ec_datagram_prealloc(datagram, data_size))) \
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    52
        return -1; \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    53
    datagram->index = 0; \
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    54
    datagram->working_counter = 0; \
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    55
    datagram->state = EC_DATAGRAM_INIT;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    57
#define EC_FUNC_FOOTER \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    58
    datagram->data_size = data_size; \
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    59
    memset(datagram->data, 0x00, data_size); \
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    60
    return 0;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    61
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    62
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    63
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    64
/*****************************************************************************/
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    65
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;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   104
    datagram->cycles_sent = 0;
398
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   105
    datagram->jiffies_sent = 0;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   106
    datagram->cycles_received = 0;
ff37601361a8 Fixed serveral races while starting up under high CPU load.
Florian Pose <fp@igh-essen.com>
parents: 397
diff changeset
   107
    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
   108
    datagram->skip_count = 0;
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   109
    datagram->stats_output_jiffies = 0;
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   110
    memset(datagram->name, 0x00, EC_DATAGRAM_NAME_SIZE);
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
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   113
/*****************************************************************************/
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   114
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   115
/** Destructor.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   116
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   117
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
   118
{
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   119
    if (datagram->data_origin == EC_ORIG_INTERNAL && datagram->data)
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   120
        kfree(datagram->data);
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
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
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   125
/** Allocates internal payload memory.
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
 * 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
   128
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   129
 * \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
   130
 *            is done!
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   131
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   132
 * \return 0 in case of success, else < 0
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   133
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   134
int ec_datagram_prealloc(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   135
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   136
        size_t size /**< New payload size in bytes. */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   137
        )
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   138
{
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   139
    if (datagram->data_origin == EC_ORIG_EXTERNAL
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   140
            || size <= datagram->mem_size)
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   141
        return 0;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   142
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   143
    if (datagram->data) {
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   144
        kfree(datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   145
        datagram->data = NULL;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   146
        datagram->mem_size = 0;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   147
    }
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   148
514
3e5989834735 Datagram preallocation with ATOMIC flag, because it is calles in timer context.
Florian Pose <fp@igh-essen.com>
parents: 511
diff changeset
   149
    if (!(datagram->data = kmalloc(size, GFP_ATOMIC))) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   150
        EC_ERR("Failed to allocate %i bytes of datagram memory!\n", size);
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   151
        return -1;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   152
    }
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   153
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   154
    datagram->mem_size = size;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   155
    return 0;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   156
}
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
/*****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   160
/** Initializes an EtherCAT APRD datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   161
 *
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   162
 * \return 0 in case of success, else < 0
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   163
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   164
int ec_datagram_aprd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   165
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   166
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   167
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   168
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   169
        )
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   170
{
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   171
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   172
    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
   173
    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
   174
    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
   175
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   176
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   177
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   178
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   179
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   180
/** Initializes an EtherCAT APWR datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   181
 *
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   182
 * \return 0 in case of success, else < 0
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   183
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   184
int ec_datagram_apwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   185
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   186
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   187
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   188
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   189
        )
293
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
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   192
    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
   193
    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
   194
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   195
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   196
}
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
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   199
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   200
/** Initializes an EtherCAT APRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   201
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   202
 * \return 0 in case of success, else < 0
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   203
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   204
int ec_datagram_aprw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   205
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   206
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   207
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   208
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   209
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   210
{
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   211
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   212
    datagram->type = EC_DATAGRAM_APRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   213
    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
   214
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   215
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   216
}
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
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   219
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   220
/** Initializes an EtherCAT ARMW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   221
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   222
 * \return 0 in case of success, else < 0
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   223
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   224
int ec_datagram_armw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   225
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   226
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   227
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   228
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   229
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   230
{
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   231
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   232
    datagram->type = EC_DATAGRAM_ARMW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   233
    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
   234
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   235
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   236
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   237
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   240
/** Initializes an EtherCAT FPRD datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   241
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   242
 * \return 0 in case of success, else < 0
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   243
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   244
int ec_datagram_fprd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   245
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   246
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   247
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   248
        size_t data_size /**< Number of bytes to read. */
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
{
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   251
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   252
        EC_WARN("Using configured station address 0x0000!\n");
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
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   255
    datagram->type = EC_DATAGRAM_FPRD;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   256
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   257
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   258
    EC_FUNC_FOOTER;
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   261
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   262
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   263
/** Initializes an EtherCAT FPWR datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   264
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   265
 * \return 0 in case of success, else < 0
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
int ec_datagram_fpwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   268
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   269
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   270
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   271
        size_t data_size /**< Number of bytes to write. */
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
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   275
        EC_WARN("Using configured station address 0x0000!\n");
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   276
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   277
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   278
    datagram->type = EC_DATAGRAM_FPWR;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   279
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   280
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   281
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   282
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   283
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   286
/** Initializes an EtherCAT FPRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   287
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   288
 * \return 0 in case of success, else < 0
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   289
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   290
int ec_datagram_fprw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   291
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   292
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   293
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   294
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   295
        )
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
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   298
        EC_WARN("Using configured station address 0x0000!\n");
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
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   301
    datagram->type = EC_DATAGRAM_FPRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   302
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   303
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   304
    EC_FUNC_FOOTER;
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
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   308
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   309
/** Initializes an EtherCAT FRMW datagram.
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
 * \return 0 in case of success, else < 0
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   312
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   313
int ec_datagram_frmw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   314
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   315
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   316
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   317
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   318
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   319
{
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_FRMW;
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);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   327
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   328
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   329
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   330
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   331
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   332
/** Initializes an EtherCAT BRD datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   333
 *
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   334
 * \return 0 in case of success, else < 0
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_brd(
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 mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   339
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   340
        )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   342
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   343
    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
   344
    EC_WRITE_U16(datagram->address, 0x0000);
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   345
    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
   346
    EC_FUNC_FOOTER;
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
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   350
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   351
/** Initializes an EtherCAT BWR datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   352
 *
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   353
 * \return 0 in case of success, else < 0
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   354
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   355
int ec_datagram_bwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   356
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   357
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   358
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   359
        )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   360
{
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_BWR;
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);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   365
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   366
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   367
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   368
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   369
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   370
/** Initializes an EtherCAT BRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   371
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   372
 * \return 0 in case of success, else < 0
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_brw(
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
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   379
{
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   380
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   381
    datagram->type = EC_DATAGRAM_BRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   382
    EC_WRITE_U16(datagram->address, 0x0000);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   383
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   384
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   385
}
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
/** Initializes an EtherCAT LRD datagram.
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   390
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   391
 * \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
   392
 *            bytes large.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   393
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   394
 * \return 0 in case of success, else < 0
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   395
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   396
int ec_datagram_lrd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   397
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   398
        uint32_t offset, /**< Logical address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   399
        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
   400
        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
   401
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   402
{
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   403
    datagram->data = external_memory;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   404
    datagram->data_origin = EC_ORIG_EXTERNAL;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   405
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   406
    datagram->type = EC_DATAGRAM_LRD;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   407
    EC_WRITE_U32(datagram->address, offset);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   408
    EC_FUNC_FOOTER;
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   411
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   412
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   413
/** Initializes an EtherCAT LWR datagram.
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
 * \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
   416
 *            bytes large.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   417
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   418
 * \return 0 in case of success, else < 0
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   419
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   420
int ec_datagram_lwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   421
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   422
        uint32_t offset, /**< Logical address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   423
        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
   424
        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
   425
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   426
{
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   427
    datagram->data = external_memory;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   428
    datagram->data_origin = EC_ORIG_EXTERNAL;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   429
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   430
    datagram->type = EC_DATAGRAM_LWR;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   431
    EC_WRITE_U32(datagram->address, offset);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   432
    EC_FUNC_FOOTER;
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
/*****************************************************************************/
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
/** Initializes an EtherCAT LRW datagram.
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
 * \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
   440
 *            bytes large.
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
 * \return 0 in case of success, else < 0
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   443
 */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   444
int ec_datagram_lrw(
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   445
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   446
        uint32_t offset, /**< Logical address. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   447
        size_t data_size, /**< Number of bytes to read/write. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   448
        uint8_t *external_memory /**< Pointer to the memory to use. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   449
        )
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   450
{
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   451
    datagram->data = external_memory;
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   452
    datagram->data_origin = EC_ORIG_EXTERNAL;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   453
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   454
    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
   455
    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
   456
    EC_FUNC_FOOTER;
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   457
}
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   458
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   459
/*****************************************************************************/
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   460
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   461
/** Evaluates the working counter of a single-cast datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   462
 *
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   463
 * Outputs an error message.
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   464
 */
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   465
void ec_datagram_print_wc_error(
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   466
        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
   467
        )
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   468
{
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   469
    if (datagram->working_counter == 0)
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   470
        printk("No response.");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   471
    else if (datagram->working_counter > 1)
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   472
        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
   473
    else
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   474
        printk("Success.");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   475
    printk("\n");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   476
}
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   477
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   478
/*****************************************************************************/
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   479
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   480
/** Outputs datagram statistics at most every second.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   481
 */
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   482
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
   483
        ec_datagram_t *datagram
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   484
        )
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   485
{
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   486
    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
   487
        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
   488
    
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   489
        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
   490
            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
   491
                    (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
   492
                    datagram->skip_count,
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   493
                    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
   494
            datagram->skip_count = 0;
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   495
        }
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   496
    }
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   497
}
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   498
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   499
/*****************************************************************************/
816
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   500
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   501
/** Returns a string describing the datagram type.
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   502
 */
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   503
const char *ec_datagram_type_string(
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   504
        const ec_datagram_t *datagram /**< EtherCAT datagram. */
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   505
        )
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   506
{
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   507
    return type_strings[datagram->type];
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   508
}
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   509
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   510
/*****************************************************************************/