master/sdo_entry.c
author Florian Pose <fp@igh-essen.com>
Fri, 18 Apr 2008 13:17:25 +0000
changeset 898 9fe5df8b3a98
parent 861 6e3de145421a
child 926 6bb33c6ec770
permissions -rw-r--r--
Added support for e1000 2.6.24, thanks to Matthias Luescher.
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
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/**
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
   \file
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
   CANopen-over-EtherCAT Sdo entry functions.
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
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <linux/module.h>
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.h"
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    44
#include "sdo_request.h"
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    45
#include "master.h"
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
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
    47
#include "sdo_entry.h"
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    48
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    49
/*****************************************************************************/
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    50
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
ssize_t ec_show_sdo_entry_attribute(struct kobject *, struct attribute *,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
                                    char *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
void ec_sdo_entry_clear(struct kobject *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
/** \cond */
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
EC_SYSFS_READ_ATTR(info);
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    60
EC_SYSFS_READ_ATTR(value);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
static struct attribute *sdo_entry_def_attrs[] = {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
    &attr_info,
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    64
    &attr_value,
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    NULL,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
};
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
static struct sysfs_ops sdo_entry_sysfs_ops = {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    .show = &ec_show_sdo_entry_attribute,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    .store = NULL
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
};
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
static struct kobj_type ktype_ec_sdo_entry = {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    .release = ec_sdo_entry_clear,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
    .sysfs_ops = &sdo_entry_sysfs_ops,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    .default_attrs = sdo_entry_def_attrs
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
};
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
/** \endcond */
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
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
    83
/** Sdo entry constructor.
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
 *
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    85
 * \todo Turn parameters.
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    86
 */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    87
int ec_sdo_entry_init(
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    88
        ec_sdo_entry_t *entry, /**< Sdo entry. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    89
        uint8_t subindex, /**< Subindex. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    90
        ec_sdo_t *sdo /**< Parent Sdo. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
    91
        )
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
{
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    93
    entry->sdo = sdo;
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    entry->subindex = subindex;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
    entry->data_type = 0x0000;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    entry->bit_length = 0;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    entry->description = NULL;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
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
    99
    // Init kobject and add it to the hierarchy
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    memset(&entry->kobj, 0x00, sizeof(struct kobject));
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    kobject_init(&entry->kobj);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
    entry->kobj.ktype = &ktype_ec_sdo_entry;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    entry->kobj.parent = &sdo->kobj;
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 409
diff changeset
   104
    if (kobject_set_name(&entry->kobj, "%i", entry->subindex)) {
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
        EC_ERR("Failed to set kobj name.\n");
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   106
        kobject_put(&entry->kobj);
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   107
        return -1;
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   108
    }
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   109
    if (kobject_add(&entry->kobj)) {
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   110
        EC_ERR("Failed to add entry kobject.\n");
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   111
        kobject_put(&entry->kobj);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
        return -1;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    return 0;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
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
   120
/** Sdo entry 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
   121
 *
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   122
 * Clears and frees an Sdo entry object.
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   123
 */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   124
void ec_sdo_entry_destroy(
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   125
        ec_sdo_entry_t *entry /**< Sdo entry. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   126
        )
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   127
{
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   128
    // destroy self
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   129
    kobject_del(&entry->kobj);
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   130
    kobject_put(&entry->kobj);
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   131
}
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   132
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   133
/*****************************************************************************/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   134
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
   135
/** Clear and free the Sdo entry.
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   136
 *
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   137
 * This method is called by the kobject,
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   138
 * once there are no more references to it.
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   139
 */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   140
void ec_sdo_entry_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
   141
        struct kobject *kobj /**< Sdo entry's kobject. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   142
        )
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    ec_sdo_entry_t *entry = container_of(kobj, ec_sdo_entry_t, kobj);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    if (entry->description) kfree(entry->description);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
    kfree(entry);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
/*****************************************************************************/
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
   152
 
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
   153
/** Print Sdo entry information to a buffer.
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   154
 * 
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   155
 * \return Number of bytes written.
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   156
 */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   157
ssize_t ec_sdo_entry_info(
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   158
        ec_sdo_entry_t *entry, /**< Sdo entry. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   159
        char *buffer /**< Target buffer. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   160
        )
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    off_t off = 0;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    off += sprintf(buffer + off, "Subindex: 0x%02X\n", entry->subindex);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    off += sprintf(buffer + off, "Description: %s\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
                   entry->description ? entry->description : "");
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    off += sprintf(buffer + off, "Data type: 0x%04X\n", entry->data_type);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    off += sprintf(buffer + off, "Bit length: %i\n", entry->bit_length);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    return off;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
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
   175
/** Format entry data based on the CANopen data type and print it to a buffer.
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   176
 *
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
   177
 * \return number of bytes written.
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
   178
 */
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
   179
ssize_t ec_sdo_entry_format_data(
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   180
        ec_sdo_entry_t *entry, /**< Sdo entry. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   181
        ec_sdo_request_t *request, /**< 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
   182
        char *buffer /**< Target buffer. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   183
        )
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   184
{
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   185
    off_t off = 0;
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   186
    unsigned int i;
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   187
657
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   188
    if (entry->data_type == 0x0002) { // int8
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   189
        int8_t value;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   190
        if (entry->bit_length != 8)
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   191
            goto not_fit;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   192
        value = EC_READ_S8(request->data);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   193
        off += sprintf(buffer + off, "%i (0x%02X)\n", value, value);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   194
    }
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   195
    else if (entry->data_type == 0x0003) { // int16
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   196
        int16_t value;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   197
        if (entry->bit_length != 16)
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   198
            goto not_fit;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   199
        value = EC_READ_S16(request->data);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   200
        off += sprintf(buffer + off, "%i (0x%04X)\n", value, value);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   201
    }
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   202
    else if (entry->data_type == 0x0004) { // int32
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   203
        int32_t value;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   204
        if (entry->bit_length != 32)
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   205
            goto not_fit;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   206
        value = EC_READ_S16(request->data);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   207
        off += sprintf(buffer + off, "%i (0x%08X)\n", value, value);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   208
    }
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   209
    else if (entry->data_type == 0x0005) { // uint8
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   210
        uint8_t value;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   211
        if (entry->bit_length != 8)
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   212
            goto not_fit;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   213
        value = EC_READ_U8(request->data);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   214
        off += sprintf(buffer + off, "%u (0x%02X)\n", value, value);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   215
    }
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   216
    else if (entry->data_type == 0x0006) { // uint16
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   217
        uint16_t value;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   218
        if (entry->bit_length != 16)
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   219
            goto not_fit;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   220
        value = EC_READ_U16(request->data); 
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   221
        off += sprintf(buffer + off, "%u (0x%04X)\n", value, value);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   222
    }
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   223
    else if (entry->data_type == 0x0007) { // uint32
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   224
        uint32_t value;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   225
        if (entry->bit_length != 32)
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   226
            goto not_fit;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   227
        value = EC_READ_U32(request->data);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   228
        off += sprintf(buffer + off, "%i (0x%08X)\n", value, value);
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   229
    }
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   230
    else if (entry->data_type == 0x0009) { // string
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   231
        off += sprintf(buffer + off, "%s\n", request->data);
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   232
    }
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   233
    else {
657
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   234
        off += sprintf(buffer + off, "Unknown data type %04X. Data:\n",
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   235
                entry->data_type);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   236
        goto raw_data;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   237
    }
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   238
    return off;
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   239
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   240
not_fit:
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   241
    off += sprintf(buffer + off,
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   242
            "Invalid bit length %u for data type 0x%04X. Data:\n",
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   243
            entry->bit_length, entry->data_type);
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   244
raw_data:
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
   245
    for (i = 0; i < request->data_size; i++)
657
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   246
        off += sprintf(buffer + off, "%02X (%c)\n",
7756b9f2eac2 Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   247
                request->data[i], request->data[i]);
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   248
    return off;
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   249
}
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   250
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   251
/*****************************************************************************/
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   252
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
   253
/** Start blocking Sdo entry reading.
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   254
 *
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
   255
 * This function blocks, until reading is finished, and is interruptible as
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
   256
 * long as the master state machine has not begun with reading.
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
   257
 *
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
   258
 * \return number of bytes written to buffer, or error code.
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
   259
 */
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
   260
ssize_t ec_sdo_entry_read_value(
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   261
        ec_sdo_entry_t *entry, /**< Sdo entry. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   262
        char *buffer /**< Target buffer. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   263
        )
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   264
{
739
4a02162a6301 Removed 'sdo' field from ec_sdo_request_t; Exported
Florian Pose <fp@igh-essen.com>
parents: 657
diff changeset
   265
    ec_master_t *master = entry->sdo->slave->master;
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   266
    off_t off = 0;
849
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
   267
    ec_master_sdo_request_t request;
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
   268
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
   269
    request.slave = entry->sdo->slave;
852
ab439cbc7a81 Separated ec_sdo_request_init() and ec_sdo_request_read().
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   270
    ec_sdo_request_init(&request.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
   271
    ec_sdo_request_address(&request.req, entry->sdo->index, entry->subindex);
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   272
    ecrt_sdo_request_read(&request.req);
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   273
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   274
    // schedule request.
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   275
    down(&master->sdo_sem);
849
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
   276
    list_add_tail(&request.list, &master->slave_sdo_requests);
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   277
    up(&master->sdo_sem);
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   278
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   279
    // wait for processing through FSM
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   280
    if (wait_event_interruptible(master->sdo_queue,
849
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
   281
                request.req.state != EC_REQUEST_QUEUED)) {
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   282
        // interrupted by signal
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   283
        down(&master->sdo_sem);
849
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
   284
        if (request.req.state == EC_REQUEST_QUEUED) {
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
   285
            list_del(&request.req.list);
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   286
            up(&master->sdo_sem);
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   287
            return -EINTR;
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   288
        }
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   289
        // request already processing: interrupt not possible.
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   290
        up(&master->sdo_sem);
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   291
    }
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   292
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   293
    // wait until master FSM has finished processing
861
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   294
    wait_event(master->sdo_queue, request.req.state != EC_REQUEST_BUSY);
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   295
6e3de145421a Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   296
    if (request.req.state != EC_REQUEST_SUCCESS)
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   297
        return -EIO;
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   298
849
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
   299
    off += ec_sdo_entry_format_data(entry, &request.req, buffer);
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
   300
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
   301
    ec_sdo_request_clear(&request.req);
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   302
    return off;
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   303
}
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   304
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   305
/*****************************************************************************/
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   306
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
   307
/** Show the Sysfs attribute of an Sdo entry.
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   308
 *
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   309
 * /return Number of bytes written to buffer.
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
   310
 */ 
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
   311
ssize_t ec_show_sdo_entry_attribute(
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   312
        struct kobject *kobj, /**< kobject. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   313
        struct attribute *attr, /**< Sysfs attribute. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   314
        char *buffer /**< Target buffer. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   315
        )
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
    ec_sdo_entry_t *entry = container_of(kobj, ec_sdo_entry_t, kobj);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
    if (attr == &attr_info) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
        return ec_sdo_entry_info(entry, buffer);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
    }
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   322
    else if (attr == &attr_value) {
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   323
        return ec_sdo_entry_read_value(entry, buffer);
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
   324
    }
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
    return 0;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   329
/*****************************************************************************/