master/canopen.c
author Florian Pose <fp@igh-essen.com>
Mon, 20 Mar 2006 12:54:17 +0000
changeset 112 eec7639c7be9
parent 111 9963537ec776
child 113 a3dbd6bc8fce
permissions -rw-r--r--
Feldregistrierung: NULL als data_ptr m?glich, field_count 0 = 1.
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
 *  c a n o p e n . c
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  CANopen over EtherCAT
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  $Id$
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *****************************************************************************/
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
#include <linux/delay.h>
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
    12
#include <linux/slab.h>
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
    13
#include <linux/module.h>
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
#include "master.h"
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
/*****************************************************************************/
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
    19
/**
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    20
   SDO Abort Code Messages
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    21
*/
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    22
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    23
typedef struct
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    24
{
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    25
    uint32_t code;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    26
    const char *message;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    27
}
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    28
ec_sdo_abort_message_t;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    29
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    30
const ec_sdo_abort_message_t sdo_abort_messages[];
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    31
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    32
/*****************************************************************************/
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    33
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    34
/**
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
    35
   Schreibt ein CANopen-SDO (service data object).
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
    36
 */
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
    37
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
    38
int ecrt_slave_sdo_write(ec_slave_t *slave, /**< EtherCAT-Slave */
101
b0c19892145a MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents: 98
diff changeset
    39
                         uint16_t sdo_index, /**< SDO-Index */
b0c19892145a MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents: 98
diff changeset
    40
                         uint8_t sdo_subindex, /**< SDO-Subindex */
b0c19892145a MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents: 98
diff changeset
    41
                         uint32_t value, /**< Neuer Wert */
b0c19892145a MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents: 98
diff changeset
    42
                         size_t size /**< Größe des Datenfeldes */
b0c19892145a MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents: 98
diff changeset
    43
                         )
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
{
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    45
    uint8_t data[0xF6];
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    46
    ec_command_t command;
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    47
    unsigned int i;
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
    48
    ec_master_t *master;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    49
    cycles_t start, end, timeout;
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    50
    uint32_t abort_code;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    51
    const ec_sdo_abort_message_t *abort_msg;
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
73
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
    53
    memset(data, 0x00, 0xF6);
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
    54
9f4ea66d89a3 Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents: 66
diff changeset
    55
    master = slave->master;
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
    if (size == 0 || size > 4) {
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    58
        EC_ERR("Invalid SDO data size: %i!\n", size);
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
        return -1;
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    }
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
77
677967864795 EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
    62
    EC_WRITE_U16(data,      0x000A); // Length of the Mailbox service data
677967864795 EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
    63
    EC_WRITE_U16(data + 2,  slave->station_address); // Station address
677967864795 EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
    64
    EC_WRITE_U8 (data + 4,  0x00); // Channel & priority
677967864795 EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
    65
    EC_WRITE_U8 (data + 5,  0x03); // CANopen over EtherCAT
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    66
    EC_WRITE_U16(data + 6,  0x02 << 12); // Number (0), Service (SDO request)
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    67
    EC_WRITE_U8 (data + 8,  0x23 | ((4 - size) << 2)); // Spec., exp., init.
77
677967864795 EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
    68
    EC_WRITE_U16(data + 9,  sdo_index);
677967864795 EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
    69
    EC_WRITE_U8 (data + 11, sdo_subindex);
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    for (i = 0; i < size; i++) {
77
677967864795 EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents: 73
diff changeset
    72
        EC_WRITE_U8(data + 12 + i, value & 0xFF);
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
        value >>= 8;
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    }
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    76
    ec_command_init_npwr(&command, slave->station_address, 0x1800, 0xF6, data);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    77
    if (unlikely(ec_master_simple_io(master, &command))) {
89
e91ef35c36db Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
    78
        EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position);
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        return -1;
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    }
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    // Read "written bit" of Sync-Manager
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    83
    start = get_cycles();
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    84
    timeout = (cycles_t) 10 * cpu_khz; // 10ms
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    85
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    86
    while (1)
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    87
    {
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    88
        udelay(100);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
    89
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    90
        ec_command_init_nprd(&command, slave->station_address, 0x808, 8);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    91
        if (unlikely(ec_master_simple_io(master, &command))) {
89
e91ef35c36db Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
    92
            EC_ERR("Mailbox checking failed on slave %i!\n",
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 80
diff changeset
    93
                   slave->ring_position);
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
            return -1;
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
        }
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    97
        end = get_cycles();
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
    99
        if (EC_READ_U8(command.data + 5) & 8) break; // Written bit is high
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   100
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   101
        if ((end - start) >= timeout) {
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   102
            EC_ERR("Mailbox check - Slave %i timed out.\n",
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   103
                   slave->ring_position);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   104
            return -1;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   105
        }
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   106
    }
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   107
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   108
    if (unlikely(slave->master->debug_level) > 1)
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   109
        EC_DBG("SDO download took %ius.\n", ((u32) (end - start) * 1000
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   110
                                             / cpu_khz));
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   112
    ec_command_init_nprd(&command, slave->station_address, 0x18F6, 0xF6);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   113
    if (unlikely(ec_master_simple_io(master, &command))) {
89
e91ef35c36db Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   114
        EC_ERR("Mailbox receiving failed on slave %i!\n",
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 80
diff changeset
   115
               slave->ring_position);
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
        return -1;
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
    }
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   119
    if (EC_READ_U8 (command.data + 5) != 0x03) { // nicht CoE
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   120
        EC_ERR("Invalid mailbox response (non-CoE) at slave %i!\n",
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   121
               slave->ring_position);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   122
        return -1;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   123
    }
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   124
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   125
    if (EC_READ_U16(command.data + 6) >> 12 == 0x02 && // SDO request
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   126
        EC_READ_U8 (command.data + 8) >> 5 == 0x04) { // Abort SDO transf. req.
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   127
        EC_ERR("SDO download of 0x%04X:%X (value %X, size %X) aborted on slave"
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   128
               " %i.\n", sdo_index, sdo_subindex, value, size,
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   129
               slave->ring_position);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   130
        abort_code = EC_READ_U32(command.data + 12);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   131
        for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) {
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   132
            if (abort_msg->code == abort_code) {
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   133
                EC_ERR("SDO abort message 0x%08X: \"%s\".\n",
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   134
                       abort_msg->code, abort_msg->message);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   135
                return -1;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   136
            }
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   137
        }
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   138
        EC_ERR("Unknown SDO abort code 0x%08X.\n", abort_code);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   139
        return -1;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   140
    }
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   141
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   142
    if (EC_READ_U16(command.data + 6) >> 12 != 0x03 || // SDO response
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   143
        EC_READ_U8 (command.data + 8) >> 5 != 0x03 || // Download response
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   144
        EC_READ_U16(command.data + 9) != sdo_index || // Index
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   145
        EC_READ_U8 (command.data + 11) != sdo_subindex) // Subindex
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    {
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   147
        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
   148
               slave->ring_position);
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
        return -1;
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    }
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    return 0;
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
}
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
/*****************************************************************************/
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   157
/**
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   158
   Liest ein CANopen-SDO (service data object).
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   159
 */
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   160
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   161
int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT-Slave */
101
b0c19892145a MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents: 98
diff changeset
   162
                        uint16_t sdo_index, /**< SDO-Index */
b0c19892145a MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents: 98
diff changeset
   163
                        uint8_t sdo_subindex, /**< SDO-Subindex */
b0c19892145a MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents: 98
diff changeset
   164
                        uint32_t *value /**< Speicher für gel. Wert */
b0c19892145a MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents: 98
diff changeset
   165
                        )
b0c19892145a MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents: 98
diff changeset
   166
{
b0c19892145a MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents: 98
diff changeset
   167
    uint8_t data[0xF6];
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   168
    ec_command_t command;
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   169
    ec_master_t *master;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   170
    cycles_t start, end, timeout;
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   171
    uint32_t abort_code;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   172
    const ec_sdo_abort_message_t *abort_msg;
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   173
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   174
    memset(data, 0x00, 0xF6);
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   175
    master = slave->master;
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   176
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   177
    EC_WRITE_U16(data,      0x0006); // Length of the Mailbox service data
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   178
    EC_WRITE_U16(data + 2,  slave->station_address); // Station address
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   179
    EC_WRITE_U8 (data + 4,  0x00); // Channel & priority
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   180
    EC_WRITE_U8 (data + 5,  0x03); // CANopen over EtherCAT
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   181
    EC_WRITE_U16(data + 6,  0x2000); // Number (0), Service (SDO request)
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   182
    EC_WRITE_U8 (data + 8,  0x1 << 1 | 0x2 << 5); // Exp., Upload request
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   183
    EC_WRITE_U16(data + 9,  sdo_index);
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   184
    EC_WRITE_U8 (data + 11, sdo_subindex);
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   185
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   186
    ec_command_init_npwr(&command, slave->station_address, 0x1800, 0xF6, data);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   187
    if (unlikely(ec_master_simple_io(master, &command))) {
89
e91ef35c36db Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   188
        EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position);
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   189
        return -1;
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   190
    }
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   191
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   192
    // Read "written bit" of Sync-Manager
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   193
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   194
    start = get_cycles();
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   195
    timeout = cpu_khz; // 1ms
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   196
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   197
    do
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   198
    {
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   199
        ec_command_init_nprd(&command, slave->station_address, 0x808, 8);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   200
        if (unlikely(ec_master_simple_io(master, &command))) {
89
e91ef35c36db Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   201
            EC_ERR("Mailbox checking failed on slave %i!\n",
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 80
diff changeset
   202
                   slave->ring_position);
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   203
            return -1;
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   204
        }
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   205
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   206
        end = get_cycles();
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   207
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   208
        if (EC_READ_U8(command.data + 5) & 8) { // Written bit is high
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   209
            break;
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   210
        }
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   211
    }
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   212
    while (likely((end - start) < timeout));
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   213
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   214
    if (unlikely((end - start) >= timeout)) {
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   215
        EC_ERR("Mailbox check on slave %i timed out.\n", slave->ring_position);
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   216
        return -1;
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   217
    }
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   218
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   219
    ec_command_init_nprd(&command, slave->station_address, 0x18F6, 0xF6);
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   220
    if (unlikely(ec_master_simple_io(master, &command))) {
89
e91ef35c36db Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents: 84
diff changeset
   221
        EC_ERR("Mailbox receiving failed on slave %i!\n",
84
b4ae98855cea printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents: 80
diff changeset
   222
               slave->ring_position);
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   223
        return -1;
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   224
    }
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   225
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   226
    if (EC_READ_U8 (command.data + 5) != 0x03) { // nicht CoE
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   227
        EC_ERR("Invalid mailbox response (non-CoE) at slave %i!\n",
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   228
               slave->ring_position);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   229
        return -1;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   230
    }
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   231
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   232
    if (EC_READ_U16(command.data + 6) >> 12 == 0x02 && // SDO request
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   233
        EC_READ_U8 (command.data + 8) >> 5 == 0x04) { // Abort SDO transf. req.
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   234
        EC_ERR("SDO upload of 0x%04X:%X aborted on slave %i.\n",
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   235
               sdo_index, sdo_subindex, slave->ring_position);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   236
        abort_code = EC_READ_U32(command.data + 12);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   237
        for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) {
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   238
            if (abort_msg->code == abort_code) {
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   239
                EC_ERR("SDO abort message 0x%08X: \"%s\".\n",
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   240
                       abort_msg->code, abort_msg->message);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   241
                return -1;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   242
            }
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   243
        }
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   244
        EC_ERR("Unknown SDO abort code 0x%08X.\n", abort_code);
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   245
        return -1;
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   246
    }
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   247
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   248
    if (EC_READ_U16(command.data + 6) >> 12 != 0x03 || // SDO response
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   249
        EC_READ_U8 (command.data + 8) >> 5 != 0x02 || // Upload response
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   250
        EC_READ_U16(command.data + 9) != sdo_index || // Index
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   251
        EC_READ_U8 (command.data + 11) != sdo_subindex) // Subindex
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   252
    {
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   253
        EC_ERR("Invalid SDO upload response at slave %i!\n",
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   254
               slave->ring_position);
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   255
        return -1;
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   256
    }
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   257
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   258
    *value = EC_READ_U32(command.data + 12);
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   259
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   260
    return 0;
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   261
}
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   262
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   263
/*****************************************************************************/
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   264
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   265
/**
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   266
   Schweibt ein CANopen-SDO (Variante mit Angabe des Masters und der Adresse).
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   267
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   268
   Siehe ecrt_slave_sdo_write()
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   269
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   270
   \return 0 wenn alles ok, < 0 bei Fehler
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   271
 */
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   272
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   273
int ecrt_master_sdo_write(ec_master_t *master,
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   274
                          /**< EtherCAT-Master */
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   275
                          const char *addr,
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   276
                          /**< Addresse, siehe ec_master_slave_address() */
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   277
                          uint16_t index,
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   278
                          /**< SDO-Index */
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   279
                          uint8_t subindex,
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   280
                          /**< SDO-Subindex */
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   281
                          uint32_t value,
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   282
                          /**< Neuer Wert */
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   283
                          size_t size
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   284
                          /**< Größe des Datenfeldes */
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   285
                          )
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   286
{
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   287
    ec_slave_t *slave;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   288
    if (!(slave = ec_master_slave_address(master, addr))) return -1;
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   289
    return ecrt_slave_sdo_write(slave, index, subindex, value, size);
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   290
}
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   291
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   292
/*****************************************************************************/
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   293
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   294
/**
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   295
   Liest ein CANopen-SDO (Variante mit Angabe des Masters und der Adresse).
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   296
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   297
   Siehe ecrt_slave_sdo_read()
91
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   298
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   299
   \return 0 wenn alles ok, < 0 bei Fehler
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   300
 */
0120d6214948 Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents: 90
diff changeset
   301
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   302
int ecrt_master_sdo_read(ec_master_t *master,
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   303
                         /**< EtherCAT-Slave */
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   304
                         const char *addr,
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   305
                         /**< Addresse, siehe ec_master_slave_address() */
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   306
                         uint16_t index,
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   307
                         /**< SDO-Index */
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   308
                         uint8_t subindex,
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   309
                         /**< SDO-Subindex */
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   310
                         uint32_t *value
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   311
                         /**< Speicher für gel. Wert */
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   312
                         )
80
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   313
{
8cd08d73b560 CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents: 77
diff changeset
   314
    ec_slave_t *slave;
98
f564d0929292 MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents: 91
diff changeset
   315
    if (!(slave = ec_master_slave_address(master, addr))) return -1;
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   316
    return ecrt_slave_sdo_read(slave, index, subindex, value);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   317
}
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   318
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   319
/*****************************************************************************/
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   320
111
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   321
const ec_sdo_abort_message_t sdo_abort_messages[] = {
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   322
    {0x05030000, "Toggle bit not changed"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   323
    {0x05040000, "SDO protocol timeout"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   324
    {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
   325
    {0x05040005, "Out of memory"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   326
    {0x06010000, "Unsupported access to an object"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   327
    {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
   328
    {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
   329
    {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
   330
    {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
   331
    {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
   332
     " exceed the PDO length"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   333
    {0x06040043, "General parameter incompatibility reason"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   334
    {0x06040047, "Gerneral internal incompatibility in device"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   335
    {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
   336
    {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
   337
     " not match"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   338
    {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
   339
     " high"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   340
    {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
   341
     " low"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   342
    {0x06090011, "Subindex does not exist"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   343
    {0x06090030, "Value range of parameter exceeded"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   344
    {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
   345
    {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
   346
    {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
   347
    {0x08000000, "General error"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   348
    {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
   349
    {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
   350
     " because of local control"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   351
    {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
   352
     " because of the present device state"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   353
    {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
   354
     " dictionary is present"},
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   355
    {}
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   356
};
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   357
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   358
/*****************************************************************************/
9963537ec776 Bugfix: SDO download. SDO abort codes ausgeben.
Florian Pose <fp@igh-essen.com>
parents: 104
diff changeset
   359
104
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   360
EXPORT_SYMBOL(ecrt_slave_sdo_write);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   361
EXPORT_SYMBOL(ecrt_slave_sdo_read);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   362
EXPORT_SYMBOL(ecrt_master_sdo_write);
052bc82d5442 MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents: 101
diff changeset
   363
EXPORT_SYMBOL(ecrt_master_sdo_read);
64
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   364
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   365
/*****************************************************************************/
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   367
/* Emacs-Konfiguration
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
;;; Local Variables: ***
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   369
;;; c-basic-offset:4 ***
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   370
;;; End: ***
ea6ccf12c612 CANopen over EtherCAT.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   371
*/