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