master/sdo_request.c
author Florian Pose <fp@igh-essen.com>
Wed, 13 Jan 2010 00:04:47 +0100
branchstable-1.4
changeset 1769 5c317e78a5ef
parent 1692 24442312c8c6
permissions -rw-r--r--
merge
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    11
 *  published by the Free Software Foundation.
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    12
 *
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    16
 *  Public License for more details.
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    17
 *
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
1685
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    22
 *  Using the EtherCAT technology and brand is permitted in compliance with
399ef727bf62 Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1676
diff changeset
    23
 *  the industrial property and similar rights of Beckhoff Automation GmbH.
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
862
6151a4db6648 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
    27
/** \file
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    28
 * Canopen over EtherCAT SDO request functions.
862
6151a4db6648 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
    29
 */
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <linux/module.h>
881
c5ac0ab2d6cf Added missing jiffies header.
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
    34
#include <linux/jiffies.h>
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
847
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    36
#include "sdo_request.h"
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    40
/** Default timeout in ms to wait for SDO transfer responses.
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
    41
 */
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
    42
#define EC_SDO_REQUEST_RESPONSE_TIMEOUT 3000
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
    43
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
    44
/*****************************************************************************/
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
    45
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    46
void ec_sdo_request_clear_data(ec_sdo_request_t *);
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    47
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    48
/*****************************************************************************/
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    49
861
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    50
/** State type translation table.
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    51
 */
862
6151a4db6648 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
    52
static const ec_sdo_request_state_t state_translation_table[] = {
861
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    53
    EC_SDO_REQUEST_UNUSED,  // EC_REQUEST_INIT,
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    54
    EC_SDO_REQUEST_BUSY,    // EC_REQUEST_QUEUED,
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    55
    EC_SDO_REQUEST_BUSY,    // EC_REQUEST_BUSY,
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    56
    EC_SDO_REQUEST_SUCCESS, // EC_REQUEST_SUCCESS,
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    57
    EC_SDO_REQUEST_ERROR    // EC_REQUEST_FAILURE
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    58
};
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    59
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    60
/*****************************************************************************/
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    61
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    62
/** SDO request constructor.
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
    63
 */
847
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    64
void ec_sdo_request_init(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    65
        ec_sdo_request_t *req /**< SDO request. */
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    66
        )
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    67
{
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    68
    req->data = NULL;
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
    69
    req->mem_size = 0;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
    70
    req->data_size = 0;
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
    71
    req->dir = EC_DIR_INVALID;
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 881
diff changeset
    72
    req->issue_timeout = 0; // no timeout
1053
0cb9604cbaa7 Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents: 1037
diff changeset
    73
    req->response_timeout = EC_SDO_REQUEST_RESPONSE_TIMEOUT;
861
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    74
    req->state = EC_REQUEST_INIT;
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
    75
    req->abort_code = 0x00000000;
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    76
}
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    77
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    78
/*****************************************************************************/
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    79
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    80
/** SDO request destructor.
847
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    81
 */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    82
void ec_sdo_request_clear(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    83
        ec_sdo_request_t *req /**< SDO request. */
847
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    84
        )
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    85
{
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    86
    ec_sdo_request_clear_data(req);
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    87
}
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    88
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    89
/*****************************************************************************/
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    90
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
    91
/** Copy another SDO request.
1676
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    92
 *
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    93
 * \attention Only the index subindex and data are copied.
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    94
 */
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    95
int ec_sdo_request_copy(
1692
24442312c8c6 Added missing doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 1686
diff changeset
    96
        ec_sdo_request_t *req, /**< SDO request. */
24442312c8c6 Added missing doxygen docs.
Florian Pose <fp@igh-essen.com>
parents: 1686
diff changeset
    97
        const ec_sdo_request_t *other /**< Other SDO request to copy from. */
1676
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    98
        )
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    99
{
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   100
    req->index = other->index;
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   101
    req->subindex = other->subindex;
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   102
    return ec_sdo_request_copy_data(req, other->data, other->data_size);
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   103
}
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   104
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   105
/*****************************************************************************/
6ad30897a9dc Added ec_sdo_request_copy().
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   106
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   107
/** SDO request destructor.
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   108
 */
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   109
void ec_sdo_request_clear_data(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   110
        ec_sdo_request_t *req /**< SDO request. */
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   111
        )
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   112
{
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   113
    if (req->data) {
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   114
        kfree(req->data);
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   115
        req->data = NULL;
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   116
    }
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   117
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   118
    req->mem_size = 0;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   119
    req->data_size = 0;
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   120
}
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   121
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   122
/*****************************************************************************/
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   123
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   124
/** Set the SDO address.
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   125
 */
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   126
void ec_sdo_request_address(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   127
        ec_sdo_request_t *req, /**< SDO request. */
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   128
        uint16_t index, /**< SDO index. */
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   129
        uint8_t subindex /**< SDO subindex. */
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   130
        )
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   131
{
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   132
    req->index = index;
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   133
    req->subindex = subindex;
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   134
}
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   135
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   136
/*****************************************************************************/
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   137
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   138
/** Pre-allocates the data memory.
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   139
 *
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   140
 * If the \a mem_size is already bigger than \a size, nothing is done.
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   141
 */
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   142
int ec_sdo_request_alloc(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   143
        ec_sdo_request_t *req, /**< SDO request. */
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   144
        size_t size /**< Data size to allocate. */
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   145
        )
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   146
{
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   147
    if (size <= req->mem_size)
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   148
        return 0;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   149
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   150
    ec_sdo_request_clear_data(req);
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   151
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   152
    if (!(req->data = (uint8_t *) kmalloc(size, GFP_KERNEL))) {
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   153
        EC_ERR("Failed to allocate %u bytes of SDO memory.\n", size);
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   154
        return -1;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   155
    }
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   156
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   157
    req->mem_size = size;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   158
    req->data_size = 0;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   159
    return 0;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   160
}
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   161
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   162
/*****************************************************************************/
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   163
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   164
/** Copies SDO data from an external source.
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   165
 *
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   166
 * If the \a mem_size is to small, new memory is allocated.
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   167
 */
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   168
int ec_sdo_request_copy_data(
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   169
        ec_sdo_request_t *req, /**< SDO request. */
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   170
        const uint8_t *source, /**< Source data. */
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   171
        size_t size /**< Number of bytes in \a source. */
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   172
        )
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   173
{
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   174
    if (ec_sdo_request_alloc(req, size))
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   175
        return -1;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   176
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   177
    memcpy(req->data, source, size);
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   178
    req->data_size = size;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   179
    return 0;
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   180
}
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   181
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   182
/*****************************************************************************/
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   183
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   184
/** Checks, if the timeout was exceeded.
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   185
 *
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   186
 * \return non-zero if the timeout was exceeded, else zero.
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   187
 */
1686
e206f4485f60 Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1685
diff changeset
   188
int ec_sdo_request_timed_out(const ec_sdo_request_t *req /**< SDO request. */)
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   189
{
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 881
diff changeset
   190
    return req->issue_timeout
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 881
diff changeset
   191
        && jiffies - req->jiffies_start > HZ * req->issue_timeout / 1000;
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   192
}
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   193
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   194
/*****************************************************************************
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   195
 * Realtime interface.
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   196
 ****************************************************************************/
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   197
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   198
void ecrt_sdo_request_timeout(ec_sdo_request_t *req, uint32_t timeout)
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   199
{
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 881
diff changeset
   200
    req->issue_timeout = timeout;
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   201
}
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   202
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   203
/*****************************************************************************/
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   204
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   205
uint8_t *ecrt_sdo_request_data(ec_sdo_request_t *req)
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   206
{
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   207
    return req->data;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   208
}
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   209
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   210
/*****************************************************************************/
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   211
869
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   212
size_t ecrt_sdo_request_data_size(const ec_sdo_request_t *req)
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   213
{
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   214
    return req->data_size;
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   215
}
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   216
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   217
/*****************************************************************************/
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   218
861
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
   219
ec_sdo_request_state_t ecrt_sdo_request_state(const ec_sdo_request_t *req)
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
   220
{
862
6151a4db6648 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   221
   return state_translation_table[req->state];
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   222
}
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   223
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   224
/*****************************************************************************/
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   225
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   226
void ecrt_sdo_request_read(ec_sdo_request_t *req)
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   227
{
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   228
    req->dir = EC_DIR_INPUT;
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   229
    req->state = EC_REQUEST_QUEUED;
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   230
    req->abort_code = 0x00000000;
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 881
diff changeset
   231
    req->jiffies_start = jiffies;
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   232
}
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   233
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   234
/*****************************************************************************/
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   235
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   236
void ecrt_sdo_request_write(ec_sdo_request_t *req)
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   237
{
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   238
    req->dir = EC_DIR_OUTPUT;
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   239
    req->state = EC_REQUEST_QUEUED;
1037
59f191c9185b Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents: 1035
diff changeset
   240
    req->abort_code = 0x00000000;
1035
7fafc1a7451e Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents: 881
diff changeset
   241
    req->jiffies_start = jiffies;
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   242
}
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   243
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   244
/*****************************************************************************/
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   245
863
1f85dbb2f76e Added doxygen markers.
Florian Pose <fp@igh-essen.com>
parents: 862
diff changeset
   246
/** \cond */
1f85dbb2f76e Added doxygen markers.
Florian Pose <fp@igh-essen.com>
parents: 862
diff changeset
   247
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   248
EXPORT_SYMBOL(ecrt_sdo_request_timeout);
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   249
EXPORT_SYMBOL(ecrt_sdo_request_data);
869
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   250
EXPORT_SYMBOL(ecrt_sdo_request_data_size);
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   251
EXPORT_SYMBOL(ecrt_sdo_request_state);
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   252
EXPORT_SYMBOL(ecrt_sdo_request_read);
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   253
EXPORT_SYMBOL(ecrt_sdo_request_write);
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   254
863
1f85dbb2f76e Added doxygen markers.
Florian Pose <fp@igh-essen.com>
parents: 862
diff changeset
   255
/** \endcond */
1f85dbb2f76e Added doxygen markers.
Florian Pose <fp@igh-essen.com>
parents: 862
diff changeset
   256
1f85dbb2f76e Added doxygen markers.
Florian Pose <fp@igh-essen.com>
parents: 862
diff changeset
   257
/*****************************************************************************/