master/sdo_request.c
author Florian Pose <fp@igh-essen.com>
Tue, 17 Jun 2008 13:27:28 +0000
changeset 1016 f831ef59426d
parent 881 c5ac0ab2d6cf
child 1035 7fafc1a7451e
permissions -rw-r--r--
Remove manual creation of device nodes, this is done by udev.
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
 *
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
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
 *
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  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
    22
 *
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
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
862
6151a4db6648 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
    34
/** \file
6151a4db6648 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
    35
 * Canopen-over-EtherCAT Sdo request functions.
6151a4db6648 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
    36
 */
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
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include <linux/module.h>
881
c5ac0ab2d6cf Added missing jiffies header.
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
    41
#include <linux/jiffies.h>
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
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
    43
#include "sdo_request.h"
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    47
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
    48
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    49
/*****************************************************************************/
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    50
861
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    51
/** 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
    52
 */
862
6151a4db6648 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
    53
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
    54
    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
    55
    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
    56
    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
    57
    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
    58
    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
    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
/*****************************************************************************/
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
    62
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
    63
/** Sdo request constructor.
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
    64
 */
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
    65
void ec_sdo_request_init(
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    66
        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
    67
        )
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
    68
{
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    69
    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
    70
    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
    71
    req->data_size = 0;
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
    72
    req->dir = EC_DIR_OUTPUT;
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
    73
    req->timeout = 0; // no 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;
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    75
}
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
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
    79
/** Sdo request destructor.
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    80
 */
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
void ec_sdo_request_clear(
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
        ec_sdo_request_t *req /**< Sdo request. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    83
        )
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    84
{
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    85
    ec_sdo_request_clear_data(req);
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    86
}
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
/*****************************************************************************/
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    89
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    90
/** Sdo request destructor.
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    91
 */
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    92
void ec_sdo_request_clear_data(
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    93
        ec_sdo_request_t *req /**< Sdo request. */
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    94
        )
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    95
{
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    96
    if (req->data) {
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    97
        kfree(req->data);
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    98
        req->data = NULL;
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
    99
    }
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   100
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
   101
    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
   102
    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
   103
}
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   104
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   105
/*****************************************************************************/
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   106
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
   107
/** 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
   108
 */
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
   109
void ec_sdo_request_address(
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   110
        ec_sdo_request_t *req, /**< Sdo request. */
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   111
        uint16_t index, /**< Sdo index. */
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   112
        uint8_t subindex /**< Sdo subindex. */
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   113
        )
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   114
{
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   115
    req->index = index;
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   116
    req->subindex = subindex;
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   117
}
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   118
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   119
/*****************************************************************************/
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
   120
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   121
/** 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
   122
 *
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   123
 * 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
   124
 */
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   125
int ec_sdo_request_alloc(
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
        ec_sdo_request_t *req, /**< Sdo request. */
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   127
        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
   128
        )
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   129
{
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   130
    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
   131
        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
   132
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   133
    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
   134
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   135
    if (!(req->data = (uint8_t *) kmalloc(size, GFP_KERNEL))) {
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   136
        EC_ERR("Failed to allocate %u bytes of Sdo memory.\n", 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
   137
        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
   138
    }
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
    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
   141
    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
   142
    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
   143
}
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
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
/** Copies Sdo data from an external 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
   148
 *
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
 * 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
   150
 */
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
int ec_sdo_request_copy_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
   152
        ec_sdo_request_t *req, /**< Sdo request. */
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   153
        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
   154
        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
   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
    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
   158
        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
   159
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
    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
   161
    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
   162
    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
   163
}
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   164
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   165
/*****************************************************************************/
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   166
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   167
/** Checks, if the timeout was exceeded.
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   168
 *
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   169
 * \return non-zero if the timeout was exceeded, else zero.
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   170
 */
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   171
int ec_sdo_request_timed_out(const ec_sdo_request_t *req /**< Sdo request. */)
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   172
{
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   173
    return req->timeout
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   174
        && jiffies - req->start_jiffies > HZ * req->timeout / 1000;
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   175
}
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   176
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   177
/*****************************************************************************
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   178
 * Realtime interface.
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   179
 ****************************************************************************/
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   180
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   181
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
   182
{
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   183
    req->timeout = timeout;
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   184
}
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   185
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   186
/*****************************************************************************/
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   187
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   188
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
   189
{
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   190
    return req->data;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   191
}
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   192
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   193
/*****************************************************************************/
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   194
869
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   195
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
   196
{
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   197
    return req->data_size;
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   198
}
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   199
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   200
/*****************************************************************************/
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   201
861
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 859
diff changeset
   202
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
   203
{
862
6151a4db6648 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   204
   return state_translation_table[req->state];
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   205
}
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
/*****************************************************************************/
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
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
   210
{
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   211
    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
   212
    req->state = EC_REQUEST_QUEUED;
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   213
    req->start_jiffies = 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
   214
}
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   215
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   216
/*****************************************************************************/
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   217
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   218
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
   219
{
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   220
    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
   221
    req->state = EC_REQUEST_QUEUED;
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 869
diff changeset
   222
    req->start_jiffies = 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
   223
}
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   224
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 852
diff changeset
   225
/*****************************************************************************/
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   226
863
1f85dbb2f76e Added doxygen markers.
Florian Pose <fp@igh-essen.com>
parents: 862
diff changeset
   227
/** \cond */
1f85dbb2f76e Added doxygen markers.
Florian Pose <fp@igh-essen.com>
parents: 862
diff changeset
   228
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   229
EXPORT_SYMBOL(ecrt_sdo_request_timeout);
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   230
EXPORT_SYMBOL(ecrt_sdo_request_data);
869
6c2f4130ed46 Added ecrt_sdo_request_data_size().
Florian Pose <fp@igh-essen.com>
parents: 863
diff changeset
   231
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
   232
EXPORT_SYMBOL(ecrt_sdo_request_state);
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   233
EXPORT_SYMBOL(ecrt_sdo_request_read);
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   234
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
   235
863
1f85dbb2f76e Added doxygen markers.
Florian Pose <fp@igh-essen.com>
parents: 862
diff changeset
   236
/** \endcond */
1f85dbb2f76e Added doxygen markers.
Florian Pose <fp@igh-essen.com>
parents: 862
diff changeset
   237
1f85dbb2f76e Added doxygen markers.
Florian Pose <fp@igh-essen.com>
parents: 862
diff changeset
   238
/*****************************************************************************/