author | Florian Pose <fp@igh-essen.com> |
Tue, 12 Jan 2010 23:40:37 +0100 | |
branch | kernel-2.4 |
changeset 1766 | 9e4d4306b641 |
parent 5 | 6f2508af550c |
child 23 | 39364fbcd069 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************** |
2 |
* |
|
3 |
* e c _ s l a v e . c |
|
4 |
* |
|
5 |
* Methoden für einen EtherCAT-Slave. |
|
6 |
* |
|
7 |
* $Date$ |
|
8 |
* $Author$ |
|
9 |
* |
|
10 |
***************************************************************/ |
|
11 |
||
12 |
#include <linux/kernel.h> |
|
13 |
||
14 |
#include "ec_globals.h" |
|
15 |
#include "ec_slave.h" |
|
16 |
#include "ec_dbg.h" |
|
17 |
||
18 |
/***************************************************************/ |
|
19 |
||
20 |
/** |
|
21 |
EtherCAT-Slave-Konstruktor. |
|
22 |
||
23 |
Initialisiert einen EtherCAT-Slave. |
|
24 |
||
25 |
@param slave Zeiger auf den zu initialisierenden Slave |
|
26 |
*/ |
|
27 |
||
28 |
void EtherCAT_slave_init(EtherCAT_slave_t *slave) |
|
29 |
{ |
|
30 |
slave->type = 0; |
|
31 |
slave->revision = 0; |
|
32 |
slave->build = 0; |
|
33 |
||
34 |
slave->ring_position = 0; |
|
35 |
slave->station_address = 0; |
|
36 |
||
37 |
slave->vendor_id = 0; |
|
38 |
slave->product_code = 0; |
|
39 |
slave->revision_number = 0; |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
40 |
slave->serial_number = 0; |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
41 |
|
0 | 42 |
slave->desc = 0; |
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
43 |
|
0 | 44 |
slave->logical_address0 = 0; |
45 |
||
46 |
slave->current_state = ECAT_STATE_UNKNOWN; |
|
47 |
slave->requested_state = ECAT_STATE_UNKNOWN; |
|
48 |
} |
|
49 |
||
50 |
/***************************************************************/ |
|
51 |
||
52 |
/** |
|
53 |
EtherCAT-Slave-Destruktor. |
|
54 |
||
55 |
Im Moment ohne Funktionalität. |
|
56 |
||
57 |
@param slave Zeiger auf den zu zerstörenden Slave |
|
58 |
*/ |
|
59 |
||
60 |
void EtherCAT_slave_clear(EtherCAT_slave_t *slave) |
|
61 |
{ |
|
62 |
// Nothing yet... |
|
63 |
} |
|
64 |
||
65 |
/***************************************************************/ |
|
66 |
||
67 |
/** |
|
68 |
Liest einen bestimmten Kanal des Slaves als Integer-Wert. |
|
69 |
||
70 |
Prüft zuerst, ob der entsprechende Slave eine |
|
71 |
bekannte Beschreibung besitzt, ob dort eine |
|
72 |
read()-Funktion hinterlegt ist und ob die angegebene |
|
73 |
Kanalnummer gültig ist. Wenn ja, wird der dekodierte |
|
74 |
Wert zurückgegeben, sonst ist der Wert 0. |
|
75 |
||
76 |
@param slave EtherCAT-Slave |
|
77 |
@param channel Kanalnummer |
|
78 |
||
79 |
@return Gelesener Wert bzw. 0 |
|
80 |
*/ |
|
81 |
||
82 |
int EtherCAT_read_value(EtherCAT_slave_t *slave, |
|
83 |
unsigned int channel) |
|
84 |
{ |
|
85 |
if (!slave->desc) |
|
86 |
{ |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
87 |
EC_DBG(KERN_WARNING "EtherCAT: Reading failed on slave %04X (addr %0X)" |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
88 |
" - Slave has no description.\n", |
0 | 89 |
slave->station_address, (unsigned int) slave); |
90 |
return 0; |
|
91 |
} |
|
92 |
||
93 |
if (!slave->desc->read) |
|
94 |
{ |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
95 |
EC_DBG(KERN_WARNING "EtherCAT: Reading failed on slave %04X (addr %0X)" |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
96 |
" - Slave type (%s %s) has no read method.\n", |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
97 |
slave->station_address, (unsigned int) slave, |
0 | 98 |
slave->desc->vendor_name, slave->desc->product_name); |
99 |
return 0; |
|
100 |
} |
|
101 |
||
102 |
if (channel >= slave->desc->channels) |
|
103 |
{ |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
104 |
EC_DBG(KERN_WARNING "EtherCAT: Reading failed on slave %4X (addr %0X)" |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
105 |
" - Type (%s %s) has no channel %i.\n", |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
106 |
slave->station_address, (unsigned int) slave, |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
107 |
slave->desc->vendor_name, slave->desc->product_name, |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
108 |
channel); |
0 | 109 |
return 0; |
110 |
} |
|
111 |
||
112 |
return slave->desc->read(slave->process_data, channel); |
|
113 |
} |
|
114 |
||
115 |
/***************************************************************/ |
|
116 |
||
117 |
/** |
|
118 |
Schreibt einen bestimmten Kanal des Slaves als Integer-Wert . |
|
119 |
||
120 |
Prüft zuerst, ob der entsprechende Slave eine |
|
121 |
bekannte Beschreibung besitzt, ob dort eine |
|
122 |
write()-Funktion hinterlegt ist und ob die angegebene |
|
123 |
Kanalnummer gültig ist. Wenn ja, wird der Wert entsprechend |
|
124 |
kodiert und geschrieben. |
|
125 |
||
126 |
@param slave EtherCAT-Slave |
|
127 |
@param channel Kanalnummer |
|
128 |
@param value Zu schreibender Wert |
|
129 |
*/ |
|
130 |
||
131 |
void EtherCAT_write_value(EtherCAT_slave_t *slave, |
|
132 |
unsigned int channel, |
|
133 |
int value) |
|
134 |
{ |
|
135 |
if (!slave->desc) |
|
136 |
{ |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
137 |
EC_DBG(KERN_WARNING "EtherCAT: Writing failed on slave %04X (addr %0X)" |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
138 |
" - Slave has no description.\n", |
0 | 139 |
slave->station_address, (unsigned int) slave); |
140 |
return; |
|
141 |
} |
|
142 |
||
143 |
if (!slave->desc->write) |
|
144 |
{ |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
145 |
EC_DBG(KERN_WARNING "EtherCAT: Writing failed on slave %04X (addr %0X)" |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
146 |
" - Type (%s %s) has no write method.\n", |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
147 |
slave->station_address, (unsigned int) slave, |
0 | 148 |
slave->desc->vendor_name, slave->desc->product_name); |
149 |
return; |
|
150 |
} |
|
151 |
||
152 |
if (channel >= slave->desc->channels) |
|
153 |
{ |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
154 |
EC_DBG(KERN_WARNING "EtherCAT: Writing failed on slave %4X (addr %0X)" |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
155 |
" - Type (%s %s) has no channel %i.\n", |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
156 |
slave->station_address, (unsigned int) slave, |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
157 |
slave->desc->vendor_name, slave->desc->product_name, |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
158 |
channel); |
0 | 159 |
return; |
160 |
} |
|
161 |
||
162 |
slave->desc->write(slave->process_data, channel, value); |
|
163 |
} |
|
164 |
||
165 |
/***************************************************************/ |