master/canopen.c
author Florian Pose <fp@igh-essen.com>
Tue, 25 Jul 2006 10:05:04 +0000
changeset 315 119f967aead8
parent 293 14aeb79aa992
permissions -rw-r--r--
Renamed Sysfs attributes.
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     6
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     8
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    12
 *  License, or (at your option) any later version.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    13
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    17
 *  GNU General Public License for more details.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    18
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    31
 *
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    34
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    35
   \file
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    36
   Canopen-over-EtherCAT functions.
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    37
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    38
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    39
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    40
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <linux/delay.h>
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
    42
#include <linux/slab.h>
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
    43
#include <linux/module.h>
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include "master.h"
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
    46
#include "mailbox.h"
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
/*****************************************************************************/
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
    50
void ec_canopen_abort_msg(uint32_t);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
    51
int ec_slave_fetch_sdo_descriptions(ec_slave_t *, ec_datagram_t *);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
    52
int ec_slave_fetch_sdo_entries(ec_slave_t *, ec_datagram_t *,
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    53
                               ec_sdo_t *, uint8_t);
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
    54
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
    55
/*****************************************************************************/
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
    56
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
    57
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    58
   Reads 32 bit of a CANopen SDO in expedited mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    59
   \return 0 in case of success, else < 0
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    60
*/
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    61
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    62
int ec_slave_sdo_read_exp(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    63
                          uint16_t sdo_index, /**< SDO index */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    64
                          uint8_t sdo_subindex, /**< SDO subindex */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    65
                          uint8_t *target /**< 4-byte memory */
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    66
                          )
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    67
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
    68
    ec_datagram_t datagram;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    69
    size_t rec_size;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
    70
    uint8_t *data;
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
    71
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
    72
    ec_datagram_init(&datagram);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
    73
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
    74
    if (!(data = ec_slave_mbox_prepare_send(slave, &datagram, 0x03, 6)))
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    75
        goto err;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
    76
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    77
    EC_WRITE_U16(data, 0x2 << 12); // SDO request
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    78
    EC_WRITE_U8 (data + 2, (0x1 << 1 // expedited transfer
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    79
                            | 0x2 << 5)); // initiate upload request
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    80
    EC_WRITE_U16(data + 3, sdo_index);
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    81
    EC_WRITE_U8 (data + 5, sdo_subindex);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
    82
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
    83
    if (!(data = ec_slave_mbox_simple_io(slave, &datagram, &rec_size)))
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    84
        goto err;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    85
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    86
    if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    87
        EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
    88
        EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n",
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    89
               sdo_index, sdo_subindex, slave->ring_position);
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    90
        ec_canopen_abort_msg(EC_READ_U32(data + 6));
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    91
        goto err;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    92
    }
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    93
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    94
    if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    95
        EC_READ_U8 (data + 2) >> 5 != 0x2 || // upload response
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    96
        EC_READ_U16(data + 3) != sdo_index || // index
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
    97
        EC_READ_U8 (data + 5) != sdo_subindex) { // subindex
159
acb250c92896 Fixed invalid format string.
Florian Pose <fp@igh-essen.com>
parents: 157
diff changeset
    98
        EC_ERR("SDO upload 0x%04X:%X failed:\n", sdo_index, sdo_subindex);
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
    99
        EC_ERR("Invalid SDO upload response at slave %i!\n",
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   100
               slave->ring_position);
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   101
        ec_print_data(data, rec_size);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   102
        goto err;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   103
    }
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   104
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   105
    memcpy(target, data + 6, 4);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   106
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   107
    ec_datagram_clear(&datagram);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   108
    return 0;
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   109
 err:
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   110
    ec_datagram_clear(&datagram);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   111
    return -1;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   112
}
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   113
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   114
/*****************************************************************************/
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   115
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   116
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   117
   Writes a CANopen SDO using expedited mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   118
   \return 0 in case of success, else < 0
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   119
*/
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   120
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   121
int ec_slave_sdo_write_exp(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   122
                           uint16_t sdo_index, /**< SDO index */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   123
                           uint8_t sdo_subindex, /**< SDO subindex */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   124
                           const uint8_t *sdo_data, /**< new value */
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   125
                           size_t size /**< Data size in bytes (1 - 4) */
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   126
                           )
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
   128
    uint8_t *data;
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   129
    size_t rec_size;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   130
    ec_datagram_t datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   131
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   132
    ec_datagram_init(&datagram);
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
    if (size == 0 || size > 4) {
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   135
        EC_ERR("Invalid data size!\n");
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   136
        goto err;
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   137
    }
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   138
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   139
    if (!(data = ec_slave_mbox_prepare_send(slave, &datagram, 0x03, 0x0A)))
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   140
        goto err;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   141
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   142
    EC_WRITE_U16(data, 0x2 << 12); // SDO request
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   143
    EC_WRITE_U8 (data + 2, (0x1 // size specified
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   144
                            | 0x1 << 1 // expedited transfer
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   145
                            | (4 - size) << 2 // data set size
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   146
                            | 0x1 << 5)); // initiate download request
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   147
    EC_WRITE_U16(data + 3, sdo_index);
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   148
    EC_WRITE_U8 (data + 5, sdo_subindex);
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   149
    memcpy(data + 6, sdo_data, size);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   150
    if (size < 4) memset(data + 6 + size, 0x00, 4 - size);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   151
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   152
    if (!(data = ec_slave_mbox_simple_io(slave, &datagram, &rec_size)))
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   153
        goto err;
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   154
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   155
    if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   156
        EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   157
        EC_ERR("SDO download 0x%04X:%X (%i bytes) aborted on slave %i.\n",
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   158
               sdo_index, sdo_subindex, size, slave->ring_position);
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   159
        ec_canopen_abort_msg(EC_READ_U32(data + 6));
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   160
        return -1;
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   161
    }
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   162
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   163
    if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   164
        EC_READ_U8 (data + 2) >> 5 != 0x3 || // download response
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   165
        EC_READ_U16(data + 3) != sdo_index || // index
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   166
        EC_READ_U8 (data + 5) != sdo_subindex) { // subindex
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   167
        EC_ERR("SDO download 0x%04X:%X (%i bytes) failed:\n",
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   168
               sdo_index, sdo_subindex, size);
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   169
        EC_ERR("Invalid SDO download response at slave %i!\n",
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
   170
               slave->ring_position);
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   171
        ec_print_data(data, rec_size);
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
        return -1;
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    }
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   175
    ec_datagram_clear(&datagram);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   176
    return 0;
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   177
 err:
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   178
    ec_datagram_clear(&datagram);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   179
    return -1;
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
}
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
/*****************************************************************************/
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   184
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   185
   Reads a CANopen SDO in normal mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   186
   \return 0 in case of success, else < 0
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   187
   \ingroup RealtimeInterface
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   188
   \todo Make size non-pointer.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   189
*/
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   190
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   191
int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   192
                        uint16_t sdo_index, /**< SDO index */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   193
                        uint8_t sdo_subindex, /**< SDO subindex */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   194
                        uint8_t *target, /**< memory for value */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   195
                        size_t *size /**< target memory size */
137
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   196
                        )
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   197
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
   198
    uint8_t *data;
137
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   199
    size_t rec_size, data_size;
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   200
    uint32_t complete_size;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   201
    ec_datagram_t datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   202
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   203
    ec_datagram_init(&datagram);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   204
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   205
    if (!(data = ec_slave_mbox_prepare_send(slave, &datagram, 0x03, 6)))
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   206
        goto err;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   207
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   208
    EC_WRITE_U16(data, 0x2 << 12); // SDO request
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   209
    EC_WRITE_U8 (data + 2, 0x2 << 5); // initiate upload request
137
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   210
    EC_WRITE_U16(data + 3, sdo_index);
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   211
    EC_WRITE_U8 (data + 5, sdo_subindex);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   212
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   213
    if (!(data = ec_slave_mbox_simple_io(slave, &datagram, &rec_size)))
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   214
        goto err;
137
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   215
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   216
    if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   217
        EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   218
        EC_ERR("SDO upload 0x%04X:%X aborted on slave %i.\n",
137
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   219
               sdo_index, sdo_subindex, slave->ring_position);
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   220
        ec_canopen_abort_msg(EC_READ_U32(data + 6));
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   221
        goto err;
137
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   222
    }
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   223
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   224
    if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   225
        EC_READ_U8 (data + 2) >> 5 != 0x2 || // initiate upload response
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   226
        EC_READ_U16(data + 3) != sdo_index || // index
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   227
        EC_READ_U8 (data + 5) != sdo_subindex) { // subindex
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   228
        EC_ERR("SDO upload 0x%04X:%X failed:\n", sdo_index, sdo_subindex);
137
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   229
        EC_ERR("Invalid SDO upload response at slave %i!\n",
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   230
               slave->ring_position);
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   231
        ec_print_data(data, rec_size);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   232
        goto err;
137
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   233
    }
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   234
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   235
    if (rec_size < 10) {
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   236
        EC_ERR("Received currupted SDO upload response!\n");
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   237
        ec_print_data(data, rec_size);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   238
        goto err;
137
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   239
    }
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   240
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   241
    if ((complete_size = EC_READ_U32(data + 6)) > *size) {
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   242
        EC_ERR("SDO data does not fit into buffer (%i / %i)!\n",
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   243
               complete_size, *size);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   244
        goto err;
137
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   245
    }
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   246
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   247
    data_size = rec_size - 10;
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   248
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   249
    if (data_size != complete_size) {
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   250
        EC_ERR("SDO data incomplete - Fragmenting not implemented.\n");
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   251
        goto err;
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   252
    }
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   253
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   254
    memcpy(target, data + 10, data_size);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   255
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   256
    ec_datagram_clear(&datagram);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   257
    return 0;
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   258
 err:
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   259
    ec_datagram_clear(&datagram);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   260
    return -1;
137
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   261
}
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   262
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   263
/*****************************************************************************/
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   264
3fb18812871a SDO-Zugriff aufgeteilt in Expedited und Normal. Noch nicht fertig...
Florian Pose <fp@igh-essen.com>
parents: 135
diff changeset
   265
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   266
   Fetches the SDO dictionary of a slave.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   267
   \return 0 in case of success, else < 0
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   268
*/
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   269
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   270
int ec_slave_fetch_sdo_list(ec_slave_t *slave /**< EtherCAT slave */)
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   271
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
   272
    uint8_t *data;
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   273
    size_t rec_size;
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   274
    unsigned int i, sdo_count;
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   275
    ec_sdo_t *sdo;
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   276
    uint16_t sdo_index;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   277
    ec_datagram_t datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   278
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   279
    ec_datagram_init(&datagram);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   280
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   281
    if (!(data = ec_slave_mbox_prepare_send(slave, &datagram, 0x03, 8)))
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   282
        goto err;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   283
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   284
    EC_WRITE_U16(data, 0x8 << 12); // SDO information
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   285
    EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   286
    EC_WRITE_U8 (data + 3, 0x00);
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   287
    EC_WRITE_U16(data + 4, 0x0000);
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   288
    EC_WRITE_U16(data + 6, 0x0001); // deliver all SDOs!
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   289
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   290
    if (unlikely(ec_master_simple_io(slave->master, &datagram))) {
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   291
        EC_ERR("Mailbox checking failed on slave %i!\n", slave->ring_position);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   292
        goto err;
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
   293
    }
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   294
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   295
    do {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   296
        if (!(data = ec_slave_mbox_simple_receive(slave, &datagram,
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   297
                                                  0x03, &rec_size)))
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   298
            goto err;
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   299
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   300
        if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   301
            (EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   302
            EC_ERR("SDO information error response at slave %i!\n",
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   303
                   slave->ring_position);
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   304
            ec_canopen_abort_msg(EC_READ_U32(data + 6));
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   305
            goto err;
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   306
        }
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   307
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   308
        if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   309
            (EC_READ_U8 (data + 2) & 0x7F) != 0x02) { // Get OD List response
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   310
            EC_ERR("Invalid SDO list response at slave %i!\n",
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   311
                   slave->ring_position);
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   312
            ec_print_data(data, rec_size);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   313
            goto err;
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   314
        }
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   315
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   316
        if (rec_size < 8) {
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   317
            EC_ERR("Invalid data size!\n");
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   318
            ec_print_data(data, rec_size);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   319
            goto err;
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   320
        }
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   321
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   322
        sdo_count = (rec_size - 8) / 2;
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   323
        for (i = 0; i < sdo_count; i++) {
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   324
            sdo_index = EC_READ_U16(data + 8 + i * 2);
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   325
            if (!sdo_index) continue; // sometimes index is 0... ???
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   326
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   327
            if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_KERNEL))) {
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   328
                EC_ERR("Failed to allocate memory for SDO!\n");
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   329
                goto err;
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   330
            }
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   331
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   332
            // Initialize SDO object
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   333
            sdo->index = sdo_index;
175
2e4b18203ade Altered CoE "Get object description response" fields
Florian Pose <fp@igh-essen.com>
parents: 164
diff changeset
   334
            //sdo->unkown = 0x0000;
2e4b18203ade Altered CoE "Get object description response" fields
Florian Pose <fp@igh-essen.com>
parents: 164
diff changeset
   335
            sdo->object_code = 0x00;
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   336
            sdo->name = NULL;
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   337
            INIT_LIST_HEAD(&sdo->entries);
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   338
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   339
            list_add_tail(&sdo->list, &slave->sdo_dictionary);
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   340
        }
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   341
    }
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   342
    while (EC_READ_U8(data + 2) & 0x80);
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   343
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   344
    // Fetch all SDO descriptions
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   345
    if (ec_slave_fetch_sdo_descriptions(slave, &datagram)) goto err;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   346
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   347
    ec_datagram_clear(&datagram);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   348
    return 0;
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   349
 err:
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   350
    ec_datagram_clear(&datagram);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   351
    return -1;
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   352
}
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   353
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   354
/*****************************************************************************/
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   355
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   356
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   357
   Fetches the SDO descriptions for the known SDOs.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   358
   \return 0 in case of success, else < 0
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   359
*/
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   360
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   361
int ec_slave_fetch_sdo_descriptions(ec_slave_t *slave, /**< EtherCAT slave */
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   362
                                    ec_datagram_t *datagram /**< datagram */
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   363
                                    )
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   364
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
   365
    uint8_t *data;
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   366
    size_t rec_size, name_size;
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   367
    ec_sdo_t *sdo;
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   368
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   369
    list_for_each_entry(sdo, &slave->sdo_dictionary, list) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   370
        if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8)))
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   371
            return -1;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   372
        EC_WRITE_U16(data, 0x8 << 12); // SDO information
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   373
        EC_WRITE_U8 (data + 2, 0x03); // Get object description request
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   374
        EC_WRITE_U8 (data + 3, 0x00);
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   375
        EC_WRITE_U16(data + 4, 0x0000);
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   376
        EC_WRITE_U16(data + 6, sdo->index); // SDO index
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   377
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   378
        if (!(data = ec_slave_mbox_simple_io(slave, datagram, &rec_size)))
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   379
            return -1;
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   380
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   381
        if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   382
            (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   383
            EC_ERR("SDO information error response at slave %i while"
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   384
                   " fetching SDO 0x%04X!\n", slave->ring_position,
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   385
                   sdo->index);
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   386
            ec_canopen_abort_msg(EC_READ_U32(data + 6));
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   387
            return -1;
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   388
        }
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   389
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   390
        if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   391
            (EC_READ_U8 (data + 2) & 0x7F) != 0x04 || // Object desc. response
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   392
            EC_READ_U16(data + 6) != sdo->index) { // SDO index
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   393
            EC_ERR("Invalid object description response at slave %i while"
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   394
                   " fetching SDO 0x%04X!\n", slave->ring_position,
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   395
                   sdo->index);
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   396
            ec_print_data(data, rec_size);
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   397
            return -1;
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   398
        }
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   399
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   400
        if (rec_size < 12) {
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   401
            EC_ERR("Invalid data size!\n");
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   402
            ec_print_data(data, rec_size);
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   403
            return -1;
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   404
        }
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   405
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   406
#if 0
175
2e4b18203ade Altered CoE "Get object description response" fields
Florian Pose <fp@igh-essen.com>
parents: 164
diff changeset
   407
        EC_DBG("object desc response:\n");
2e4b18203ade Altered CoE "Get object description response" fields
Florian Pose <fp@igh-essen.com>
parents: 164
diff changeset
   408
        ec_print_data(data, rec_size);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   409
#endif
175
2e4b18203ade Altered CoE "Get object description response" fields
Florian Pose <fp@igh-essen.com>
parents: 164
diff changeset
   410
2e4b18203ade Altered CoE "Get object description response" fields
Florian Pose <fp@igh-essen.com>
parents: 164
diff changeset
   411
        //sdo->unknown = EC_READ_U16(data + 8);
2e4b18203ade Altered CoE "Get object description response" fields
Florian Pose <fp@igh-essen.com>
parents: 164
diff changeset
   412
        sdo->object_code = EC_READ_U8(data + 11);
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   413
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   414
        name_size = rec_size - 12;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   415
        if (name_size) {
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   416
            if (!(sdo->name = kmalloc(name_size + 1, GFP_KERNEL))) {
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   417
                EC_ERR("Failed to allocate SDO name!\n");
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   418
                return -1;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   419
            }
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   420
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   421
            memcpy(sdo->name, data + 12, name_size);
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   422
            sdo->name[name_size] = 0;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   423
        }
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   424
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   425
        if (EC_READ_U8(data + 2) & 0x80) {
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   426
            EC_ERR("Fragment follows (not implemented)!\n");
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   427
            return -1;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   428
        }
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   429
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   430
        // Fetch all entries (subindices)
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   431
        if (ec_slave_fetch_sdo_entries(slave, datagram, sdo,
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   432
                                       EC_READ_U8(data + 10)))
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   433
            return -1;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   434
    }
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   435
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   436
    return 0;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   437
}
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   438
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   439
/*****************************************************************************/
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   440
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   441
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   442
   Fetches all entries (subindices) to an SDO.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   443
   \return 0 in case of success, else < 0
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   444
*/
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   445
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   446
int ec_slave_fetch_sdo_entries(ec_slave_t *slave, /**< EtherCAT slave */
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   447
                               ec_datagram_t *datagram, /**< datagram */
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   448
                               ec_sdo_t *sdo, /**< SDO */
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   449
                               uint8_t subindices /**< number of subindices */
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   450
                               )
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   451
{
144
fdc24bf62f80 Dynamischer Kommandospeicher, Domain-Kommandos als Liste.
Florian Pose <fp@igh-essen.com>
parents: 139
diff changeset
   452
    uint8_t *data;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   453
    size_t rec_size, data_size;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   454
    uint8_t i;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   455
    ec_sdo_entry_t *entry;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   456
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   457
    for (i = 1; i <= subindices; i++) {
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   458
        if (!(data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10)))
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   459
            return -1;
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   460
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   461
        EC_WRITE_U16(data, 0x8 << 12); // SDO information
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   462
        EC_WRITE_U8 (data + 2, 0x05); // Get entry description request
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   463
        EC_WRITE_U8 (data + 3, 0x00);
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   464
        EC_WRITE_U16(data + 4, 0x0000);
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   465
        EC_WRITE_U16(data + 6, sdo->index); // SDO index
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   466
        EC_WRITE_U8 (data + 8, i); // SDO subindex
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   467
        EC_WRITE_U8 (data + 9, 0x00); // value info (no values)
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents: 144
diff changeset
   468
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 286
diff changeset
   469
        if (!(data = ec_slave_mbox_simple_io(slave, datagram, &rec_size)))
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   470
            return -1;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   471
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   472
        if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   473
            (EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   474
            EC_ERR("SDO information error response at slave %i while"
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   475
                   " fetching SDO entry 0x%04X:%i!\n", slave->ring_position,
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   476
                   sdo->index, i);
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   477
            ec_canopen_abort_msg(EC_READ_U32(data + 6));
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   478
            return -1;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   479
        }
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   480
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   481
        if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   482
            (EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   483
            EC_READ_U16(data + 6) != sdo->index || // SDO index
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   484
            EC_READ_U8(data + 8) != i) { // SDO subindex
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   485
            EC_ERR("Invalid entry description response at slave %i while"
161
ddb7266d1c56 Bugfix: Discovered memory leak.
Florian Pose <fp@igh-essen.com>
parents: 159
diff changeset
   486
                   " fetching SDO entry 0x%04X:%i!\n", slave->ring_position,
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   487
                   sdo->index, i);
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   488
            ec_print_data(data, rec_size);
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   489
            return -1;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   490
        }
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   491
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   492
        if (rec_size < 16) {
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   493
            EC_ERR("Invalid data size!\n");
157
37c6dd0ff0b1 Bugfix: Crash after failing to fetch SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 145
diff changeset
   494
            ec_print_data(data, rec_size);
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   495
            return -1;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   496
        }
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   497
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   498
        if (!EC_READ_U16(data + 12)) // bit length = 0
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   499
            continue;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   500
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   501
        data_size = rec_size - 16;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   502
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   503
        if (!(entry = (ec_sdo_entry_t *)
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   504
              kmalloc(sizeof(ec_sdo_entry_t) + data_size + 1, GFP_KERNEL))) {
161
ddb7266d1c56 Bugfix: Discovered memory leak.
Florian Pose <fp@igh-essen.com>
parents: 159
diff changeset
   505
            EC_ERR("Failed to allocate entry!\n");
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   506
            return -1;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   507
        }
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   508
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   509
        entry->subindex = i;
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   510
        entry->data_type = EC_READ_U16(data + 10);
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   511
        entry->bit_length = EC_READ_U16(data + 12);
161
ddb7266d1c56 Bugfix: Discovered memory leak.
Florian Pose <fp@igh-essen.com>
parents: 159
diff changeset
   512
ddb7266d1c56 Bugfix: Discovered memory leak.
Florian Pose <fp@igh-essen.com>
parents: 159
diff changeset
   513
        // memory for name string appended to entry
ddb7266d1c56 Bugfix: Discovered memory leak.
Florian Pose <fp@igh-essen.com>
parents: 159
diff changeset
   514
        entry->name = (uint8_t *) entry + sizeof(ec_sdo_entry_t);
ddb7266d1c56 Bugfix: Discovered memory leak.
Florian Pose <fp@igh-essen.com>
parents: 159
diff changeset
   515
ddb7266d1c56 Bugfix: Discovered memory leak.
Florian Pose <fp@igh-essen.com>
parents: 159
diff changeset
   516
        memcpy(entry->name, data + 16, data_size);
ddb7266d1c56 Bugfix: Discovered memory leak.
Florian Pose <fp@igh-essen.com>
parents: 159
diff changeset
   517
        entry->name[data_size] = 0;
139
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   518
998215ab9b92 Laden der SDO-Subindizes.
Florian Pose <fp@igh-essen.com>
parents: 138
diff changeset
   519
        list_add_tail(&entry->list, &sdo->entries);
135
80d493917205 Laden der SDO Dictionaries funktioniert.
Florian Pose <fp@igh-essen.com>
parents: 134
diff changeset
   520
    }
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   521
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   522
    return 0;
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   523
}
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   524
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   525
/*****************************************************************************/
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   526
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   527
/**
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   528
   SDO abort messages.
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   529
   The "abort SDO transfer request" supplies an abort code,
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   530
   which can be translated to clear text. This table does
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   531
   the mapping of the codes and messages.
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   532
*/
133
b36d187ecc0b Unterst?tzte Prot. auslesen, Mailbox in Slave ausgelagert, Bugfix in Anzeige des Watch-Frames und erste SDO-List-Abfrage.
Florian Pose <fp@igh-essen.com>
parents: 113
diff changeset
   533
164
ed85368b2b2e AL status code reading after failed state transition.
Florian Pose <fp@igh-essen.com>
parents: 161
diff changeset
   534
const ec_code_msg_t sdo_abort_messages[] = {
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   535
    {0x05030000, "Toggle bit not changed"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   536
    {0x05040000, "SDO protocol timeout"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   537
    {0x05040001, "Client/Server command specifier not valid or unknown"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   538
    {0x05040005, "Out of memory"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   539
    {0x06010000, "Unsupported access to an object"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   540
    {0x06010001, "Attempt to read a write-only object"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   541
    {0x06010002, "Attempt to write a read-only object"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   542
    {0x06020000, "This object does not exist in the object directory"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   543
    {0x06040041, "The object cannot be mapped into the PDO"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   544
    {0x06040042, "The number and length of the objects to be mapped would"
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   545
     " exceed the PDO length"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   546
    {0x06040043, "General parameter incompatibility reason"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   547
    {0x06040047, "Gerneral internal incompatibility in device"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   548
    {0x06060000, "Access failure due to a hardware error"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   549
    {0x06070010, "Data type does not match, length of service parameter does"
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   550
     " not match"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   551
    {0x06070012, "Data type does not match, length of service parameter too"
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   552
     " high"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   553
    {0x06070013, "Data type does not match, length of service parameter too"
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   554
     " low"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   555
    {0x06090011, "Subindex does not exist"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   556
    {0x06090030, "Value range of parameter exceeded"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   557
    {0x06090031, "Value of parameter written too high"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   558
    {0x06090032, "Value of parameter written too low"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   559
    {0x06090036, "Maximum value is less than minimum value"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   560
    {0x08000000, "General error"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   561
    {0x08000020, "Data cannot be transferred or stored to the application"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   562
    {0x08000021, "Data cannot be transferred or stored to the application"
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   563
     " because of local control"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   564
    {0x08000022, "Data cannot be transferred or stored to the application"
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   565
     " because of the present device state"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   566
    {0x08000023, "Object dictionary dynamic generation fails or no object"
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   567
     " dictionary is present"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   568
    {}
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   569
};
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   570
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   571
/*****************************************************************************/
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   572
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   573
/**
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   574
   Outputs an SDO abort message.
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   575
*/
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   576
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   577
void ec_canopen_abort_msg(uint32_t abort_code)
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   578
{
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   579
    const ec_code_msg_t *abort_msg;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   580
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   581
    for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) {
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   582
        if (abort_msg->code == abort_code) {
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   583
            EC_ERR("SDO abort message 0x%08X: \"%s\".\n",
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   584
                   abort_msg->code, abort_msg->message);
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   585
            return;
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   586
        }
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   587
    }
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   588
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   589
    EC_ERR("Unknown SDO abort code 0x%08X.\n", abort_code);
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   590
}
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
   591
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   592
/******************************************************************************
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   593
 *  Realtime interface
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   594
 *****************************************************************************/
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   595
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   596
/**
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   597
   Reads an 8-bit SDO in expedited mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   598
   See ec_slave_sdo_read_exp()
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   599
   \return 0 in case of success, else < 0
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   600
   \ingroup RealtimeInterface
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   601
*/
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   602
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   603
int ecrt_slave_sdo_read_exp8(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   604
                             uint16_t sdo_index, /**< SDO index */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   605
                             uint8_t sdo_subindex, /**< SDO subindex */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   606
                             uint8_t *target /**< memory for read value */
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   607
                             )
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   608
{
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   609
    uint8_t data[4];
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   610
    if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1;
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   611
    *target = EC_READ_U8(data);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   612
    return 0;
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   613
}
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   614
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   615
/*****************************************************************************/
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   616
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   617
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   618
   Reads a 16-bit SDO in expedited mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   619
   See ec_slave_sdo_read_exp()
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   620
   \return 0 in case of success, else < 0
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   621
   \ingroup RealtimeInterface
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   622
*/
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   623
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   624
int ecrt_slave_sdo_read_exp16(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   625
                              uint16_t sdo_index, /**< SDO index */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   626
                              uint8_t sdo_subindex, /**< SDO subindex */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   627
                              uint16_t *target /**< memory for read value */
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   628
                              )
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   629
{
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   630
    uint8_t data[4];
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   631
    if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1;
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   632
    *target = EC_READ_U16(data);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   633
    return 0;
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   634
}
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   635
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   636
/*****************************************************************************/
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   637
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   638
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   639
   Reads a 32-bit SDO in expedited mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   640
   See ec_slave_sdo_read_exp()
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   641
   \return 0 in case of success, else < 0
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   642
   \ingroup RealtimeInterface
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   643
*/
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   644
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   645
int ecrt_slave_sdo_read_exp32(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   646
                              uint16_t sdo_index, /**< SDO index */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   647
                              uint8_t sdo_subindex, /**< SDO subindex */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   648
                              uint32_t *target /**< memory for read value */
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   649
                              )
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   650
{
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   651
    uint8_t data[4];
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   652
    if (ec_slave_sdo_read_exp(slave, sdo_index, sdo_subindex, data)) return -1;
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   653
    *target = EC_READ_U32(data);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   654
    return 0;
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   655
}
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   656
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   657
/*****************************************************************************/
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   658
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   659
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   660
   Writes an 8-bit SDO in expedited mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   661
   \return 0 in case of success, else < 0
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   662
   \ingroup RealtimeInterface
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   663
*/
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   664
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   665
int ecrt_slave_sdo_write_exp8(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   666
                              uint16_t sdo_index, /**< SDO index */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   667
                              uint8_t sdo_subindex, /**< SDO subindex */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   668
                              uint8_t value /**< new value */
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   669
                              )
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   670
{
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   671
    return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, &value, 1);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   672
}
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   673
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   674
/*****************************************************************************/
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   675
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   676
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   677
   Writes a 16-bit SDO in expedited mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   678
   \return 0 in case of success, else < 0
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   679
   \ingroup RealtimeInterface
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   680
*/
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   681
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   682
int ecrt_slave_sdo_write_exp16(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   683
                               uint16_t sdo_index, /**< SDO index */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   684
                               uint8_t sdo_subindex, /**< SDO subindex */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   685
                               uint16_t value /**< new value */
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   686
                               )
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   687
{
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   688
    uint8_t data[2];
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   689
    EC_WRITE_U16(data, value);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   690
    return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, data, 2);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   691
}
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   692
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   693
/*****************************************************************************/
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   694
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   695
/**
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   696
   Writes a 32-bit SDO in expedited mode.
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   697
   \return 0 in case of success, else < 0
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   698
   \ingroup RealtimeInterface
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   699
*/
195
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   700
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   701
int ecrt_slave_sdo_write_exp32(ec_slave_t *slave, /**< EtherCAT slave */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   702
                               uint16_t sdo_index, /**< SDO index */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   703
                               uint8_t sdo_subindex, /**< SDO subindex */
674071846ee3 Translated all comments and documentation to english language.
Florian Pose <fp@igh-essen.com>
parents: 175
diff changeset
   704
                               uint32_t value /**< new value */
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   705
                               )
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   706
{
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   707
    uint8_t data[4];
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   708
    EC_WRITE_U32(data, value);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   709
    return ec_slave_sdo_write_exp(slave, sdo_index, sdo_subindex, data, 4);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   710
}
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   711
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   712
/*****************************************************************************/
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   713
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   714
/** \cond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   715
138
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   716
EXPORT_SYMBOL(ecrt_slave_sdo_read_exp8);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   717
EXPORT_SYMBOL(ecrt_slave_sdo_read_exp16);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   718
EXPORT_SYMBOL(ecrt_slave_sdo_read_exp32);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   719
EXPORT_SYMBOL(ecrt_slave_sdo_write_exp8);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   720
EXPORT_SYMBOL(ecrt_slave_sdo_write_exp16);
7e743a61a991 SDO-Schnittstelle verbessert.
Florian Pose <fp@igh-essen.com>
parents: 137
diff changeset
   721
EXPORT_SYMBOL(ecrt_slave_sdo_write_exp32);
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   722
EXPORT_SYMBOL(ecrt_slave_sdo_read);
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   723
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   724
/** \endcond */
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   725
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   726
/*****************************************************************************/