master/datagram.c
author Florian Pose <fp@igh-essen.com>
Mon, 23 Jul 2012 15:35:32 +0200
changeset 2400 7c9c12c61104
parent 2095 53b5128e1313
child 2589 2b9c78543663
permissions -rw-r--r--
Added r8169 driver for 2.6.36, thanks to J. Kunz.
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     6
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     8
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    11
 *  published by the Free Software Foundation.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    12
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    16
 *  Public License for more details.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    17
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1333
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1333
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1333
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1333
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1333
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 237
diff changeset
    27
 *
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    30
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    31
   \file
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    32
   Methods of an EtherCAT datagram.
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    33
*/
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
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    36
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <linux/slab.h>
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    39
#include "datagram.h"
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "master.h"
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
/*****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    44
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    45
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
#define EC_FUNC_HEADER \
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
    47
    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
    48
    if (unlikely(ret)) \
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
    49
        return ret; \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    50
    datagram->index = 0; \
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    51
    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
    52
    datagram->state = EC_DATAGRAM_INIT;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    54
#define EC_FUNC_FOOTER \
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    55
    datagram->data_size = data_size; \
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    56
    return 0;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    57
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    58
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    59
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    60
/*****************************************************************************/
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    61
816
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    62
/** 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
    63
 *
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    64
 * \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
    65
 */
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    66
static const char *type_strings[] = {
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
    "APRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    69
    "APWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    70
    "APRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    71
    "FPRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    72
    "FPWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    73
    "FPRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    74
    "BRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    75
    "BWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    76
    "BRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    77
    "LRD",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    78
    "LWR",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    79
    "LRW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    80
    "ARMW",
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    81
    "FRMW"
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    82
};
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    83
    
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    84
/*****************************************************************************/
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
    85
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    86
/** Constructor.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    87
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
    88
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
    89
{
2038
770e86a39c98 Datagram queue race fixed: insert datagrams into master-fsm_queue with fsm_queue list_head
Martin Troxler <ch1010277@ch10pc446>
parents: 1981
diff changeset
    90
    INIT_LIST_HEAD(&datagram->list); // mark as unqueued
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
    91
    INIT_LIST_HEAD(&datagram->queue); // mark as unqueued
2038
770e86a39c98 Datagram queue race fixed: insert datagrams into master-fsm_queue with fsm_queue list_head
Martin Troxler <ch1010277@ch10pc446>
parents: 1981
diff changeset
    92
    INIT_LIST_HEAD(&datagram->fsm_queue); // mark as unqueued
770e86a39c98 Datagram queue race fixed: insert datagrams into master-fsm_queue with fsm_queue list_head
Martin Troxler <ch1010277@ch10pc446>
parents: 1981
diff changeset
    93
    INIT_LIST_HEAD(&datagram->sent); // mark as unqueued
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    94
    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
    95
    memset(datagram->address, 0x00, EC_ADDR_LEN);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    96
    datagram->data = NULL;
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
    97
    datagram->data_origin = EC_ORIG_INTERNAL;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    98
    datagram->mem_size = 0;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    99
    datagram->data_size = 0;
1981
c14b6bb14fdf Inplace I/O: let input Pdos use the same bus space as Output Pdos
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1822
diff changeset
   100
    datagram->domain = NULL;
293
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
{
1553
4e8d56d6f12a Bugfix: Unqueue datagram before destroying.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   123
    ec_datagram_unqueue(datagram);
4e8d56d6f12a Bugfix: Unqueue datagram before destroying.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   124
1333
7b9898062c8f merge -c1614 branches/stable-1.4: Fixed datagram cleaning.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   125
    if (datagram->data_origin == EC_ORIG_INTERNAL && datagram->data) {
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   126
        kfree(datagram->data);
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   127
        datagram->data = NULL;
1333
7b9898062c8f merge -c1614 branches/stable-1.4: Fixed datagram cleaning.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   128
    }
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   129
}
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
/*****************************************************************************/
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   132
1553
4e8d56d6f12a Bugfix: Unqueue datagram before destroying.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   133
/** Unqueue datagram.
4e8d56d6f12a Bugfix: Unqueue datagram before destroying.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   134
 */
4e8d56d6f12a Bugfix: Unqueue datagram before destroying.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   135
void ec_datagram_unqueue(ec_datagram_t *datagram /**< EtherCAT datagram. */)
4e8d56d6f12a Bugfix: Unqueue datagram before destroying.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   136
{
2038
770e86a39c98 Datagram queue race fixed: insert datagrams into master-fsm_queue with fsm_queue list_head
Martin Troxler <ch1010277@ch10pc446>
parents: 1981
diff changeset
   137
    if (!list_empty(&datagram->fsm_queue)) {
770e86a39c98 Datagram queue race fixed: insert datagrams into master-fsm_queue with fsm_queue list_head
Martin Troxler <ch1010277@ch10pc446>
parents: 1981
diff changeset
   138
        list_del_init(&datagram->fsm_queue);
1553
4e8d56d6f12a Bugfix: Unqueue datagram before destroying.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   139
    }
2040
45706e3273fd lock io_mutex when unqueueing datagrams; unqueue datagrams from send-receive queue.
Martin Troxler <ch1010277@ch10pc446>
parents: 2038
diff changeset
   140
    if (!list_empty(&datagram->queue)) {
45706e3273fd lock io_mutex when unqueueing datagrams; unqueue datagrams from send-receive queue.
Martin Troxler <ch1010277@ch10pc446>
parents: 2038
diff changeset
   141
        list_del_init(&datagram->queue);
45706e3273fd lock io_mutex when unqueueing datagrams; unqueue datagrams from send-receive queue.
Martin Troxler <ch1010277@ch10pc446>
parents: 2038
diff changeset
   142
    }
1553
4e8d56d6f12a Bugfix: Unqueue datagram before destroying.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   143
}
4e8d56d6f12a Bugfix: Unqueue datagram before destroying.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   144
4e8d56d6f12a Bugfix: Unqueue datagram before destroying.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   145
/*****************************************************************************/
4e8d56d6f12a Bugfix: Unqueue datagram before destroying.
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   146
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   147
/** Allocates internal payload memory.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   148
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   149
 * 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
   150
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   151
 * \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
   152
 *            is done!
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   153
 *
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   154
 * \return 0 in case of success, otherwise \a -ENOMEM.
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   155
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   156
int ec_datagram_prealloc(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   157
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   158
        size_t size /**< New payload size in bytes. */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   159
        )
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   160
{
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   161
    if (datagram->data_origin == EC_ORIG_EXTERNAL
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   162
            || size <= datagram->mem_size)
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   163
        return 0;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   164
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   165
    if (datagram->data) {
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   166
        kfree(datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   167
        datagram->data = NULL;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   168
        datagram->mem_size = 0;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   169
    }
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   170
998
05a24788f3b2 Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   171
    if (!(datagram->data = kmalloc(size, GFP_KERNEL))) {
1543
373cd456dc26 Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   172
        EC_ERR("Failed to allocate %zu 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
   173
        return -ENOMEM;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   174
    }
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   175
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   176
    datagram->mem_size = size;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   177
    return 0;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   178
}
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
/*****************************************************************************/
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   182
/** Fills the datagram payload memory with zeros.
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   183
 */
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   184
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
   185
{
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   186
    memset(datagram->data, 0x00, datagram->data_size);
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   187
}
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   188
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   189
/*****************************************************************************/
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1040
diff changeset
   190
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   191
/** Initializes an EtherCAT APRD datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   192
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   193
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   194
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   195
int ec_datagram_aprd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   196
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   197
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   198
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   199
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   200
        )
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   201
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   202
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   203
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   204
    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
   205
    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
   206
    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
   207
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   208
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   209
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   210
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   211
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   212
/** Initializes an EtherCAT APWR datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   213
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   214
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   215
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   216
int ec_datagram_apwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   217
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   218
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   219
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   220
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   221
        )
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   222
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   223
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   224
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   225
    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
   226
    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
   227
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   228
    EC_FUNC_FOOTER;
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
/*****************************************************************************/
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
/** Initializes an EtherCAT APRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   234
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   235
 * \return Return value of ec_datagram_prealloc().
815
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
int ec_datagram_aprw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   238
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   239
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   240
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   241
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   242
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   243
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   244
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   245
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   246
    datagram->type = EC_DATAGRAM_APRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   247
    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
   248
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   249
    EC_FUNC_FOOTER;
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
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   252
/*****************************************************************************/
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
/** Initializes an EtherCAT ARMW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   255
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   256
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   257
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   258
int ec_datagram_armw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   259
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   260
        uint16_t ring_position, /**< Auto-increment address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   261
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   262
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   263
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   264
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   265
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   266
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   267
    datagram->type = EC_DATAGRAM_ARMW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   268
    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
   269
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   270
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   271
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   272
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   273
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   274
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   275
/** Initializes an EtherCAT FPRD datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   276
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   277
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   278
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   279
int ec_datagram_fprd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   280
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   281
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   282
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   283
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   284
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   285
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   286
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   287
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   288
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   289
        EC_WARN("Using configured station address 0x0000!\n");
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   290
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   291
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   292
    datagram->type = EC_DATAGRAM_FPRD;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   293
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   294
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   295
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   296
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   297
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   298
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   299
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   300
/** Initializes an EtherCAT FPWR datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   301
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   302
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   303
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   304
int ec_datagram_fpwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   305
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   306
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   307
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   308
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   309
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   310
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   311
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   312
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   313
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   314
        EC_WARN("Using configured station address 0x0000!\n");
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   315
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   316
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   317
    datagram->type = EC_DATAGRAM_FPWR;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   318
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   319
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   320
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   321
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   322
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   323
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   324
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   325
/** Initializes an EtherCAT FPRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   326
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   327
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   328
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   329
int ec_datagram_fprw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   330
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   331
        uint16_t configured_address, /**< Configured station address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   332
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   333
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   334
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   335
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   336
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   337
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   338
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   339
        EC_WARN("Using configured station address 0x0000!\n");
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   340
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   341
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   342
    datagram->type = EC_DATAGRAM_FPRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   343
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   344
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   345
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   346
}
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
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   349
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   350
/** Initializes an EtherCAT FRMW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   351
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   352
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   353
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   354
int ec_datagram_frmw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   355
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   356
        uint16_t configured_address, /**< Configured station address. */
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
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   360
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   361
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   362
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   363
    if (unlikely(configured_address == 0x0000))
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   364
        EC_WARN("Using configured station address 0x0000!\n");
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   365
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   366
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   367
    datagram->type = EC_DATAGRAM_FRMW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   368
    EC_WRITE_U16(datagram->address, configured_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   369
    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
   370
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   371
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   372
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
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   375
/** Initializes an EtherCAT BRD datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   376
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   377
 * \return Return value of ec_datagram_prealloc().
815
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
int ec_datagram_brd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   380
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   381
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   382
        size_t data_size /**< Number of bytes to read. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   383
        )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   384
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   385
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   386
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   387
    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
   388
    EC_WRITE_U16(datagram->address, 0x0000);
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   389
    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
   390
    EC_FUNC_FOOTER;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   391
}
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   392
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   393
/*****************************************************************************/
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   394
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   395
/** Initializes an EtherCAT BWR datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   396
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   397
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   398
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   399
int ec_datagram_bwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   400
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   401
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   402
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   403
        )
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   404
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   405
    int ret;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   406
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   407
    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
   408
    EC_WRITE_U16(datagram->address, 0x0000);
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   409
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   410
    EC_FUNC_FOOTER;
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
/*****************************************************************************/
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
/** Initializes an EtherCAT BRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   416
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   417
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   418
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   419
int ec_datagram_brw(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   420
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   421
        uint16_t mem_address, /**< Physical memory address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   422
        size_t data_size /**< Number of bytes to write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   423
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   424
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   425
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   426
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   427
    datagram->type = EC_DATAGRAM_BRW;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   428
    EC_WRITE_U16(datagram->address, 0x0000);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   429
    EC_WRITE_U16(datagram->address + 2, mem_address);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   430
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   431
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   432
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   433
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   434
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   435
/** Initializes an EtherCAT LRD datagram.
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   436
 *
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   437
 * \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
   438
 *            bytes large.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   439
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   440
 * \return Return value of ec_datagram_prealloc().
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   441
 */
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   442
int ec_datagram_lrd(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   443
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   444
        uint32_t offset, /**< Logical address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   445
        size_t data_size, /**< Number of bytes to read/write. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   446
        uint8_t *external_memory /**< Pointer to the memory to use. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   447
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   448
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   449
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   450
    datagram->data = external_memory;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   451
    datagram->data_origin = EC_ORIG_EXTERNAL;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   452
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   453
    datagram->type = EC_DATAGRAM_LRD;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   454
    EC_WRITE_U32(datagram->address, offset);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   455
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   456
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   457
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   458
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   459
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   460
/** Initializes an EtherCAT LWR datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   461
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   462
 * \attention It is assumed, that the external memory is at least \a data_size
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   463
 *            bytes large.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   464
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   465
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   466
 */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   467
int ec_datagram_lwr(
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   468
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   469
        uint32_t offset, /**< Logical address. */
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   470
        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
   471
        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
   472
        )
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   473
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   474
    int ret;
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   475
    datagram->data = external_memory;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   476
    datagram->data_origin = EC_ORIG_EXTERNAL;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   477
    EC_FUNC_HEADER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   478
    datagram->type = EC_DATAGRAM_LWR;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   479
    EC_WRITE_U32(datagram->address, offset);
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   480
    EC_FUNC_FOOTER;
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   481
}
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   482
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   483
/*****************************************************************************/
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   484
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   485
/** Initializes an EtherCAT LRW datagram.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   486
 *
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   487
 * \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
   488
 *            bytes large.
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   489
 *
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   490
 * \return Return value of ec_datagram_prealloc().
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   491
 */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   492
int ec_datagram_lrw(
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 809
diff changeset
   493
        ec_datagram_t *datagram, /**< EtherCAT datagram. */
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   494
        uint32_t offset, /**< Logical address. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   495
        size_t data_size, /**< Number of bytes to read/write. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   496
        uint8_t *external_memory /**< Pointer to the memory to use. */
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   497
        )
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   498
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   499
    int ret;
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   500
    datagram->data = external_memory;
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   501
    datagram->data_origin = EC_ORIG_EXTERNAL;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   502
    EC_FUNC_HEADER;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
   503
    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
   504
    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
   505
    EC_FUNC_FOOTER;
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   506
}
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   507
90bdb315f560 Fixed EtherCAT addressing problem on big-endian systems. The slaves
Florian Pose <fp@igh-essen.com>
parents: 514
diff changeset
   508
/*****************************************************************************/
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   509
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   510
/** Prints the state of a datagram.
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   511
 *
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   512
 * Outputs a text message.
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   513
 */
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   514
void ec_datagram_print_state(
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   515
        const ec_datagram_t *datagram /**< EtherCAT datagram */
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   516
        )
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   517
{
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   518
    printk("Datagram ");
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   519
    switch (datagram->state) {
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   520
        case EC_DATAGRAM_INIT:
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   521
            printk("initialized");
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   522
            break;
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   523
        case EC_DATAGRAM_QUEUED:
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   524
            printk("queued");
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   525
            break;
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   526
        case EC_DATAGRAM_SENT:
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   527
            printk("sent");
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   528
            break;
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   529
        case EC_DATAGRAM_RECEIVED:
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   530
            printk("received");
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   531
            break;
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   532
        case EC_DATAGRAM_TIMED_OUT:
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   533
            printk("timed out");
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   534
            break;
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   535
        case EC_DATAGRAM_ERROR:
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   536
            printk("error");
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   537
            break;
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   538
        default:
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   539
            printk("???");
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   540
    }
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   541
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   542
    printk(".\n");
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   543
}
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   544
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   545
/*****************************************************************************/
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1553
diff changeset
   546
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   547
/** Evaluates the working counter of a single-cast datagram.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   548
 *
713
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   549
 * Outputs an error message.
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   550
 */
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   551
void ec_datagram_print_wc_error(
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   552
        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
   553
        )
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   554
{
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   555
    if (datagram->working_counter == 0)
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   556
        printk("No response.");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   557
    else if (datagram->working_counter > 1)
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   558
        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
   559
    else
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   560
        printk("Success.");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   561
    printk("\n");
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   562
}
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   563
ae41cadd25b6 Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents: 708
diff changeset
   564
/*****************************************************************************/
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   565
809
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   566
/** Outputs datagram statistics at most every second.
ec4ef8911824 External domain memory.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   567
 */
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   568
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
   569
        ec_datagram_t *datagram
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   570
        )
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   571
{
2077
e8f690838311 Fixed datagram statistics output (skipped datagrams).
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   572
    if (jiffies - datagram->stats_output_jiffies > HZ) {
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   573
        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
   574
    
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   575
        if (unlikely(datagram->skip_count)) {
1543
373cd456dc26 Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   576
            EC_WARN("Datagram %p (%s) was SKIPPED %u time%s.\n",
373cd456dc26 Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   577
                    datagram, datagram->name,
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   578
                    datagram->skip_count,
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   579
                    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
   580
            datagram->skip_count = 0;
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   581
        }
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   582
    }
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   583
}
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   584
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   585
/*****************************************************************************/
816
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   586
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   587
/** Returns a string describing the datagram type.
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   588
 */
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   589
const char *ec_datagram_type_string(
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   590
        const ec_datagram_t *datagram /**< EtherCAT datagram. */
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   591
        )
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   592
{
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   593
    return type_strings[datagram->type];
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   594
}
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   595
d02761e14eb0 Introduced ec_datagram_type_string().
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   596
/*****************************************************************************/
2095
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   597
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   598
/** Output datagram information.
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   599
 */
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   600
void ec_datagram_output_info(
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   601
        const ec_datagram_t *datagram /**< EtherCAT datagram. */
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   602
        )
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   603
{
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   604
    printk("state=%s ", ec_datagram_type_string(datagram));
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   605
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   606
    switch (datagram->type) {
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   607
        case EC_DATAGRAM_APRD:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   608
        case EC_DATAGRAM_APWR:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   609
        case EC_DATAGRAM_APRW:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   610
        case EC_DATAGRAM_ARMW:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   611
            printk("pos=%i mem=0x%04x",
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   612
                    EC_READ_S16(datagram->address) * (-1),
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   613
                    EC_READ_U16(datagram->address + 2)
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   614
                    );
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   615
            break;
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   616
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   617
        case EC_DATAGRAM_FPRD:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   618
        case EC_DATAGRAM_FPWR:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   619
        case EC_DATAGRAM_FPRW:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   620
        case EC_DATAGRAM_FRMW:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   621
            printk("node=%u mem=0x%04x",
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   622
                    EC_READ_U16(datagram->address),
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   623
                    EC_READ_U16(datagram->address + 2));
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   624
            break;
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   625
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   626
        case EC_DATAGRAM_BRD:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   627
        case EC_DATAGRAM_BWR:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   628
        case EC_DATAGRAM_BRW:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   629
            printk("mem=0x%04x", EC_READ_U16(datagram->address + 2));
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   630
            break;
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   631
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   632
        case EC_DATAGRAM_LRD:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   633
        case EC_DATAGRAM_LWR:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   634
        case EC_DATAGRAM_LRW:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   635
            printk("log=0x%08x", EC_READ_U32(datagram->address));
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   636
            break;
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   637
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   638
        default:
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   639
            printk("??");
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   640
            break;
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   641
    }
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   642
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   643
    printk(" size=%zu", datagram->data_size);
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   644
}
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   645
53b5128e1313 Fixed skipped datagrams output again; added datagram information on skip.
Florian Pose <fp@igh-essen.com>
parents: 2080
diff changeset
   646
/*****************************************************************************/