master/sdo.c
author Florian Pose <fp@igh-essen.com>
Fri, 06 Jun 2008 09:22:57 +0000
changeset 964 957f21465052
parent 963 01702c78fe0a
child 991 2548ca639b1f
permissions -rw-r--r--
Added ec_slave_get_sdo_by_pos_const() and ec_slave_sdo_count().
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 Sdo 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
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    43
#include "master.h"
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
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
    45
#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
    46
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
ssize_t ec_show_sdo_attribute(struct kobject *, struct attribute *, char *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
void ec_sdo_clear(struct kobject *);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
/** \cond */
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
EC_SYSFS_READ_ATTR(info);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
static struct attribute *sdo_def_attrs[] = {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
    &attr_info,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    NULL,
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
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
static struct sysfs_ops sdo_sysfs_ops = {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
    .show = &ec_show_sdo_attribute,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
    .store = 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 kobj_type ktype_ec_sdo = {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    .release = ec_sdo_clear,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    .sysfs_ops = &sdo_sysfs_ops,
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    .default_attrs = sdo_def_attrs
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
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
/** \endcond */
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
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
    78
/** Sdo 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
    79
 *
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
 * \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
    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
int ec_sdo_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
    83
        ec_sdo_t *sdo, /**< 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
    84
        uint16_t index, /**< Sdo index. */
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
        ec_slave_t *slave /**< Parent slave. */
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
        )
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
{
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
    88
    sdo->slave = slave;
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
    sdo->index = index;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    sdo->object_code = 0x00;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    sdo->name = NULL;
962
ea83a7aab57a Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
    92
    sdo->max_subindex = 0;
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    INIT_LIST_HEAD(&sdo->entries);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
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
    95
    // Init kobject and add it to the hierarchy
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    memset(&sdo->kobj, 0x00, sizeof(struct kobject));
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    kobject_init(&sdo->kobj);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    sdo->kobj.ktype = &ktype_ec_sdo;
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 409
diff changeset
    99
    sdo->kobj.parent = &slave->sdo_kobj;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 409
diff changeset
   100
    if (kobject_set_name(&sdo->kobj, "%4X", sdo->index)) {
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
        EC_ERR("Failed to set kobj name.\n");
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   102
        kobject_put(&sdo->kobj);
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   103
        return -1;
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   104
    }
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   105
    if (kobject_add(&sdo->kobj)) {
814
a51f857b1b2d Renamed [PS]DO to [PS]do.
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   106
        EC_ERR("Failed to add Sdo kobject.\n");
484
9fde4a17b820 kobject_add() in constructors.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   107
        kobject_put(&sdo->kobj);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
        return -1;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    return 0;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
}
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
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
   116
/** Sdo 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
   117
 *
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   118
 * Clears and frees an Sdo 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
   119
 */
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
void ec_sdo_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
   121
        ec_sdo_t *sdo /**< 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
   122
        )
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
   123
{
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    ec_sdo_entry_t *entry, *next;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    // free all entries
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    list_for_each_entry_safe(entry, next, &sdo->entries, list) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
        list_del(&entry->list);
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
   129
        ec_sdo_entry_destroy(entry);
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
    }
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
    // 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
   133
    kobject_del(&sdo->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
   134
    kobject_put(&sdo->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
   135
}
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   136
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   137
/*****************************************************************************/
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   138
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
   139
/** Clear and free 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
   140
 *
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
 * 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
   142
 * 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
   143
 */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   144
void ec_sdo_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
   145
        struct kobject *kobj /**< Sdo'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
   146
        )
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
   147
{
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   148
    ec_sdo_t *sdo = container_of(kobj, ec_sdo_t, kobj);
409
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
    if (sdo->name) kfree(sdo->name);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    kfree(sdo);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
963
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   157
/** Get an Sdo entry from an Sdo via its subindex.
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
   158
 * 
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
 * \retval >0 Pointer to the requested 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
   160
 * \retval NULL Sdo entry not found.
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   161
 */
740
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   162
ec_sdo_entry_t *ec_sdo_get_entry(
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
   163
        ec_sdo_t *sdo, /**< 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
   164
        uint8_t subindex /**< Entry subindex. */
740
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   165
        )
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   166
{
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   167
    ec_sdo_entry_t *entry;
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   168
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   169
    list_for_each_entry(entry, &sdo->entries, list) {
963
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   170
        if (entry->subindex != subindex)
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   171
            continue;
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   172
        return entry;
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   173
    }
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   174
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   175
    return NULL;
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   176
}
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   177
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   178
/*****************************************************************************/
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   179
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   180
/** Get an Sdo entry from an Sdo via its subindex.
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   181
 *
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   182
 * const version.
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   183
 * 
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   184
 * \retval >0 Pointer to the requested Sdo entry.
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   185
 * \retval NULL Sdo entry not found.
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   186
 */
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   187
const ec_sdo_entry_t *ec_sdo_get_entry_const(
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   188
        const ec_sdo_t *sdo, /**< Sdo. */
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   189
        uint8_t subindex /**< Entry subindex. */
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   190
        )
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   191
{
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   192
    const ec_sdo_entry_t *entry;
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   193
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   194
    list_for_each_entry(entry, &sdo->entries, list) {
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   195
        if (entry->subindex != subindex)
01702c78fe0a Added ec_sdo_get_entry_const().
Florian Pose <fp@igh-essen.com>
parents: 962
diff changeset
   196
            continue;
740
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   197
        return entry;
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   198
    }
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   199
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   200
    return NULL;
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   201
}
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   202
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   203
/*****************************************************************************/
68d83b45dfa2 Added ec_slave_get_sdo() and ec_sdo_get_entry().
Florian Pose <fp@igh-essen.com>
parents: 739
diff changeset
   204
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
   205
/** Print Sdo 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
   206
 * 
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
   207
 * /return size of bytes written to buffer.
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
   208
 */ 
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
   209
ssize_t ec_sdo_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
   210
        ec_sdo_t *sdo, /**< 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
   211
        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
   212
        )
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
    off_t off = 0;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
    off += sprintf(buffer + off, "Index: 0x%04X\n", sdo->index);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
    off += sprintf(buffer + off, "Name: %s\n", sdo->name ? sdo->name : "");
962
ea83a7aab57a Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents: 847
diff changeset
   218
    off += sprintf(buffer + off, "Max subindex: %u\n", sdo->max_subindex);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
    return off;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
/*****************************************************************************/
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
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
   225
/** Show a Sysfs attribute of an 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
   226
 * 
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   227
 * /return Number of bytes written to buffer.
758
8fa6f825eb7d Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 740
diff changeset
   228
 */ 
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
   229
ssize_t ec_show_sdo_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
   230
        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
   231
        struct attribute *attr, /**< Requested 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
   232
        char *buffer /**< Buffer to write the data in. */
92266462d411 Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   233
        )
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
{
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
    ec_sdo_t *sdo = container_of(kobj, ec_sdo_t, kobj);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
    if (attr == &attr_info) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
        return ec_sdo_info(sdo, buffer);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
    return 0;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
}
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
/*****************************************************************************/