author | Florian Pose <fp@igh-essen.com> |
Tue, 24 Oct 2006 10:37:05 +0000 | |
changeset 439 | 0f5a3d983908 |
parent 430 | 74754f45d5fa |
child 441 | ffa13db95e10 |
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 |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
Canopen-over-EtherCAT functions. |
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 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
#include "canopen.h" |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
44 |
#include "master.h" |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
/*****************************************************************************/ |
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 |
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
|
49 |
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
|
50 |
char *); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
void ec_sdo_clear(struct kobject *); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
void ec_sdo_entry_clear(struct kobject *); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
|
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
54 |
void ec_sdo_request_init_read(ec_sdo_request_t *, ec_sdo_t *, |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
55 |
ec_sdo_entry_t *); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
56 |
void ec_sdo_request_clear(ec_sdo_request_t *); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
57 |
|
409
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 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
/** \cond */ |
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 |
EC_SYSFS_READ_ATTR(info); |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
63 |
EC_SYSFS_READ_ATTR(value); |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
static struct attribute *sdo_def_attrs[] = { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
&attr_info, |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
NULL, |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
}; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
static struct sysfs_ops sdo_sysfs_ops = { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
.show = &ec_show_sdo_attribute, |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
.store = NULL |
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 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
static struct kobj_type ktype_ec_sdo = { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
.release = ec_sdo_clear, |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
.sysfs_ops = &sdo_sysfs_ops, |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
.default_attrs = sdo_def_attrs |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
}; |
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 |
static struct attribute *sdo_entry_def_attrs[] = { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
&attr_info, |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
83 |
&attr_value, |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
NULL, |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
}; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
static struct sysfs_ops sdo_entry_sysfs_ops = { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
.show = &ec_show_sdo_entry_attribute, |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
.store = NULL |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
}; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
static struct kobj_type ktype_ec_sdo_entry = { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
.release = ec_sdo_entry_clear, |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
.sysfs_ops = &sdo_entry_sysfs_ops, |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
.default_attrs = sdo_entry_def_attrs |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
}; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
/** \endcond */ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
/*****************************************************************************/ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
/** |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
SDO constructor. |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
*/ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
int ec_sdo_init(ec_sdo_t *sdo, /**< SDO */ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
uint16_t index, /**< SDO index */ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
ec_slave_t *slave /**< parent slave */ |
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 |
{ |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
111 |
sdo->slave = slave; |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
sdo->index = index; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
sdo->object_code = 0x00; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
sdo->name = NULL; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
sdo->subindices = 0; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
INIT_LIST_HEAD(&sdo->entries); |
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 |
// init kobject and add it to the hierarchy |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
memset(&sdo->kobj, 0x00, sizeof(struct kobject)); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
kobject_init(&sdo->kobj); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
EC_ERR("Failed to set kobj name.\n"); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
125 |
return -1; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
126 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
127 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
128 |
return 0; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
129 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
131 |
/*****************************************************************************/ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
132 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
/** |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
SDO destructor. |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
*/ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
void ec_sdo_clear(struct kobject *kobj /**< SDO's kobject */) |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
{ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
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
|
140 |
ec_sdo_entry_t *entry, *next; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
142 |
// free all entries |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
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
|
144 |
list_del(&entry->list); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
145 |
kobject_del(&entry->kobj); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
kobject_put(&entry->kobj); |
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 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
if (sdo->name) kfree(sdo->name); |
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 |
kfree(sdo); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
152 |
} |
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 |
ssize_t ec_sdo_info(ec_sdo_t *sdo, /**< SDO */ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
157 |
char *buffer /**< target buffer */ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
) |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
{ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
160 |
off_t off = 0; |
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 += sprintf(buffer + off, "Index: 0x%04X\n", sdo->index); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
163 |
off += sprintf(buffer + off, "Name: %s\n", sdo->name ? sdo->name : ""); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
off += sprintf(buffer + off, "Subindices: %i\n", sdo->subindices); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
return off; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
168 |
|
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 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
171 |
ssize_t ec_show_sdo_attribute(struct kobject *kobj, /**< kobject */ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
struct attribute *attr, |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
char *buffer |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
) |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
{ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
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
|
177 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
178 |
if (attr == &attr_info) { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
179 |
return ec_sdo_info(sdo, buffer); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
180 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
181 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
182 |
return 0; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
183 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
184 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
185 |
/*****************************************************************************/ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
186 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
187 |
/** |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
188 |
SDO entry constructor. |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
189 |
*/ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
191 |
int ec_sdo_entry_init(ec_sdo_entry_t *entry, /**< SDO entry */ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
192 |
uint8_t subindex, /**< SDO entry subindex */ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
193 |
ec_sdo_t *sdo /**< parent SDO */ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
194 |
) |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
195 |
{ |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
196 |
entry->sdo = sdo; |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
197 |
entry->subindex = subindex; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
198 |
entry->data_type = 0x0000; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
199 |
entry->bit_length = 0; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
200 |
entry->description = NULL; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
201 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
202 |
// init kobject and add it to the hierarchy |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
203 |
memset(&entry->kobj, 0x00, sizeof(struct kobject)); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
204 |
kobject_init(&entry->kobj); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
205 |
entry->kobj.ktype = &ktype_ec_sdo_entry; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
206 |
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
|
207 |
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
|
208 |
EC_ERR("Failed to set kobj name.\n"); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
209 |
return -1; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
210 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
211 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
212 |
return 0; |
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 |
|
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 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
217 |
/** |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
218 |
SDO destructor. |
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 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
221 |
void ec_sdo_entry_clear(struct kobject *kobj /**< SDO entry's kobject */) |
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 |
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
|
224 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
225 |
if (entry->description) kfree(entry->description); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
226 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
227 |
kfree(entry); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
228 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
229 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
230 |
/*****************************************************************************/ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
231 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
232 |
ssize_t ec_sdo_entry_info(ec_sdo_entry_t *entry, /**< SDO entry */ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
233 |
char *buffer /**< target buffer */ |
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 |
{ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
236 |
off_t off = 0; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
237 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
238 |
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
|
239 |
off += sprintf(buffer + off, "Description: %s\n", |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
240 |
entry->description ? entry->description : ""); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
241 |
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
|
242 |
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
|
243 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
244 |
return off; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
245 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
246 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
247 |
/*****************************************************************************/ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
248 |
|
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
249 |
ssize_t ec_sdo_entry_format_data(ec_sdo_entry_t *entry, /**< SDO entry */ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
250 |
ec_sdo_request_t *request, /**< SDO request */ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
251 |
char *buffer /**< target buffer */ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
252 |
) |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
253 |
{ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
254 |
off_t off = 0; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
255 |
unsigned int i; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
256 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
257 |
if (entry->data_type == 0x0002 && entry->bit_length == 8) { // int8 |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
258 |
off += sprintf(buffer + off, "%i\n", *((int8_t *) request->data)); |
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 |
else if (entry->data_type == 0x0003 && entry->bit_length == 16) { // int16 |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
261 |
off += sprintf(buffer + off, "%i\n", *((int16_t *) request->data)); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
262 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
263 |
else if (entry->data_type == 0x0004 && entry->bit_length == 32) { // int32 |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
264 |
off += sprintf(buffer + off, "%i\n", *((int32_t *) request->data)); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
265 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
266 |
else if (entry->data_type == 0x0005 && entry->bit_length == 8) { // uint8 |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
267 |
off += sprintf(buffer + off, "%i\n", *((uint8_t *) request->data)); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
268 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
269 |
else if (entry->data_type == 0x0006 && entry->bit_length == 16) { // uint16 |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
270 |
off += sprintf(buffer + off, "%i\n", *((uint16_t *) request->data)); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
271 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
272 |
else if (entry->data_type == 0x0007 && entry->bit_length == 32) { // uint32 |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
273 |
off += sprintf(buffer + off, "%i\n", *((uint32_t *) request->data)); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
274 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
275 |
else if (entry->data_type == 0x0009) { // string |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
276 |
off += sprintf(buffer + off, "%s\n", request->data); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
277 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
278 |
else { |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
279 |
for (i = 0; i < request->size; i++) |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
280 |
off += sprintf(buffer + off, "%02X (%c)\n", |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
281 |
request->data[i], request->data[i]); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
282 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
283 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
284 |
return off; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
285 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
286 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
287 |
/*****************************************************************************/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
288 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
289 |
ssize_t ec_sdo_entry_read_value(ec_sdo_entry_t *entry, /**< SDO entry */ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
290 |
char *buffer /**< target buffer */ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
291 |
) |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
292 |
{ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
293 |
ec_sdo_t *sdo = entry->sdo; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
294 |
ec_master_t *master = sdo->slave->master; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
295 |
off_t off = 0; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
296 |
ec_sdo_request_t request; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
297 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
298 |
ec_sdo_request_init_read(&request, sdo, entry); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
299 |
list_add_tail(&request.queue, &master->sdo_requests); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
300 |
if (wait_event_interruptible(master->sdo_wait_queue, |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
301 |
request.return_code)) { |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
302 |
// interrupted by signal |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
303 |
list_del_init(&request.queue); |
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 |
if (request.return_code == 1 && request.data) { |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
307 |
off += ec_sdo_entry_format_data(entry, &request, buffer); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
308 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
309 |
else if (request.return_code < 0) { |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
310 |
off = -EINVAL; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
311 |
} |
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 |
ec_sdo_request_clear(&request); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
314 |
return off; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
315 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
316 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
317 |
/*****************************************************************************/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
318 |
|
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
319 |
ssize_t ec_show_sdo_entry_attribute(struct kobject *kobj, /**< kobject */ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
320 |
struct attribute *attr, |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
321 |
char *buffer |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
322 |
) |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
323 |
{ |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
324 |
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
|
325 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
326 |
if (attr == &attr_info) { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
327 |
return ec_sdo_entry_info(entry, buffer); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
328 |
} |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
329 |
else if (attr == &attr_value) { |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
330 |
return ec_sdo_entry_read_value(entry, buffer); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
331 |
} |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
332 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
333 |
return 0; |
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 |
|
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 |
|
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
338 |
/** |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
339 |
SDO request constructor. |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
340 |
*/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
341 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
342 |
void ec_sdo_request_init_read(ec_sdo_request_t *req, /**< SDO request */ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
343 |
ec_sdo_t *sdo, /**< SDO */ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
344 |
ec_sdo_entry_t *entry /**< SDO entry */ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
345 |
) |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
346 |
{ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
347 |
req->sdo = sdo; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
348 |
req->entry = entry; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
349 |
req->data = NULL; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
350 |
req->size = 0; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
351 |
req->return_code = 0; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
352 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
353 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
354 |
/*****************************************************************************/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
355 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
356 |
/** |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
357 |
SDO request destructor. |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
358 |
*/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
359 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
360 |
void ec_sdo_request_clear(ec_sdo_request_t *req /**< SDO request */) |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
361 |
{ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
362 |
if (req->data) kfree(req->data); |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
363 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
364 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
365 |
/*****************************************************************************/ |