author | Florian Pose <fp@igh-essen.com> |
Wed, 04 Jun 2008 08:30:18 +0000 | |
changeset 943 | 1d9e2663e087 |
parent 939 | 6a3b0be56498 |
child 961 | 8aa60dd6cbc7 |
permissions | -rw-r--r-- |
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; |
926
6bb33c6ec770
Output subindices with %02X.
Florian Pose <fp@igh-essen.com>
parents:
861
diff
changeset
|
104 |
if (kobject_set_name(&entry->kobj, "%02X", 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 |
|
939
6a3b0be56498
Check for matching data size when reading Sdo entries via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
188 |
if (request->data_size != entry->bit_length) { |
6a3b0be56498
Check for matching data size when reading Sdo entries via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
189 |
EC_ERR("Dictionary size of Sdo entry 0x%04X:%02X (%u bit) does not " |
6a3b0be56498
Check for matching data size when reading Sdo entries via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
190 |
"match size of uploaded data (%u byte)!\n", entry->sdo->index, |
6a3b0be56498
Check for matching data size when reading Sdo entries via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
191 |
entry->subindex, entry->bit_length, request->data_size); |
6a3b0be56498
Check for matching data size when reading Sdo entries via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
192 |
EC_DBG("Uploaded data:\n"); |
6a3b0be56498
Check for matching data size when reading Sdo entries via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
193 |
ec_print_data(request->data, request->data_size); |
6a3b0be56498
Check for matching data size when reading Sdo entries via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
194 |
return -EIO; |
6a3b0be56498
Check for matching data size when reading Sdo entries via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
195 |
} |
6a3b0be56498
Check for matching data size when reading Sdo entries via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
196 |
|
657
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->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
|
198 |
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
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
} |
7756b9f2eac2
Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
204 |
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
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
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
|
210 |
} |
7756b9f2eac2
Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
211 |
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
|
212 |
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
|
213 |
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
|
214 |
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
|
215 |
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
|
216 |
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
|
217 |
} |
7756b9f2eac2
Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
218 |
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
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
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
|
223 |
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
|
224 |
} |
7756b9f2eac2
Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
} |
7756b9f2eac2
Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
232 |
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
|
233 |
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
|
234 |
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
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
239 |
else if (entry->data_type == 0x0009) { // string |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
240 |
off += sprintf(buffer + off, "%s\n", request->data); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
241 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
242 |
else { |
657
7756b9f2eac2
Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
243 |
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
|
244 |
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
|
245 |
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
|
246 |
} |
7756b9f2eac2
Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
247 |
return off; |
7756b9f2eac2
Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
248 |
|
7756b9f2eac2
Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
249 |
not_fit: |
7756b9f2eac2
Respected endianess in sysfs SDO output; Separate message, if data type
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
250 |
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
|
251 |
"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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
request->data[i], request->data[i]); |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
257 |
return off; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
258 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
259 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
260 |
/*****************************************************************************/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
261 |
|
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
|
262 |
/** 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
|
263 |
* |
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
740
diff
changeset
|
264 |
* 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
|
265 |
* 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
|
266 |
* |
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
740
diff
changeset
|
267 |
* \return number of bytes written to buffer, or error code. |
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
740
diff
changeset
|
268 |
*/ |
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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
) |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
273 |
{ |
739
4a02162a6301
Removed 'sdo' field from ec_sdo_request_t; Exported
Florian Pose <fp@igh-essen.com>
parents:
657
diff
changeset
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
|
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
847
diff
changeset
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
ecrt_sdo_request_read(&request.req); |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
282 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
283 |
// schedule request. |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
284 |
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
|
285 |
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
|
286 |
up(&master->sdo_sem); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
287 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
288 |
// wait for processing through FSM |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
289 |
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
|
290 |
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
|
291 |
// interrupted by signal |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
292 |
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
|
293 |
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
|
294 |
list_del(&request.req.list); |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
295 |
up(&master->sdo_sem); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
296 |
return -EINTR; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
297 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
298 |
// request already processing: interrupt not possible. |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
299 |
up(&master->sdo_sem); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
300 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
301 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
302 |
// 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
|
303 |
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
|
304 |
|
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
305 |
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
|
306 |
return -EIO; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
307 |
|
849
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
847
diff
changeset
|
308 |
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
|
309 |
|
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
847
diff
changeset
|
310 |
ec_sdo_request_clear(&request.req); |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
311 |
return off; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
312 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
313 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
314 |
/*****************************************************************************/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
315 |
|
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
|
316 |
/** 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
|
317 |
* |
92266462d411
Saparated ec_sdo_t, ec_sdo_entry_t and ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
318 |
* /return Number of bytes written to buffer. |
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
740
diff
changeset
|
319 |
*/ |
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
|
320 |
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
|
321 |
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
|
322 |
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
|
323 |
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
|
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 |
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
|
327 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
328 |
if (attr == &attr_info) { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
329 |
return ec_sdo_entry_info(entry, buffer); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
330 |
} |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
331 |
else if (attr == &attr_value) { |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
332 |
return ec_sdo_entry_read_value(entry, buffer); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
333 |
} |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
334 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
335 |
return 0; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
336 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
337 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
338 |
/*****************************************************************************/ |