14 * D-45356 Essen |
14 * D-45356 Essen |
15 * Tel.: +49 201/61 99 31 |
15 * Tel.: +49 201/61 99 31 |
16 * Fax.: +49 201/61 98 36 |
16 * Fax.: +49 201/61 98 36 |
17 * E-mail: sp@igh-essen.com |
17 * E-mail: sp@igh-essen.com |
18 * |
18 * |
19 ******************************************************************************/ |
19 *****************************************************************************/ |
20 |
20 |
21 #include <linux/module.h> |
21 #include <linux/module.h> |
22 #include <linux/kernel.h> |
22 #include <linux/kernel.h> |
23 #include <linux/init.h> |
23 #include <linux/init.h> |
24 |
24 |
25 #include "ec_module.h" |
25 #include "ec_module.h" |
26 |
26 |
27 /******************************************************************************/ |
27 /*****************************************************************************/ |
28 |
28 |
29 #define LITERAL(X) #X |
29 #define LIT(X) #X |
30 #define STRINGIFY(X) LITERAL(X) |
30 #define STR(X) LIT(X) |
31 |
31 |
32 #define COMPILE_INFO "Revision " STRINGIFY(EC_REV) \ |
32 #define COMPILE_INFO "Revision " STR(EC_REV) \ |
33 ", compiled by " STRINGIFY(EC_USER) \ |
33 ", compiled by " STR(EC_USER) \ |
34 " at " STRINGIFY(EC_DATE) |
34 " at " STR(EC_DATE) |
35 |
35 |
36 /******************************************************************************/ |
36 /*****************************************************************************/ |
37 |
37 |
38 int ecat_master_count = 1; |
38 int ecat_master_count = 1; |
39 EtherCAT_master_t *ecat_masters = NULL; |
39 EtherCAT_master_t *ecat_masters = NULL; |
40 int *ecat_masters_reserved = NULL; |
40 int *ecat_masters_reserved = NULL; |
41 |
41 |
42 /******************************************************************************/ |
42 /*****************************************************************************/ |
43 |
43 |
44 MODULE_AUTHOR ("Wilhelm Hagemeister <hm@igh-essen.com>, Florian Pose <fp@igh-essen.com>"); |
44 MODULE_AUTHOR ("Wilhelm Hagemeister <hm@igh-essen.com>," |
|
45 "Florian Pose <fp@igh-essen.com>"); |
45 MODULE_DESCRIPTION ("EtherCAT master driver module"); |
46 MODULE_DESCRIPTION ("EtherCAT master driver module"); |
46 MODULE_LICENSE("GPL"); |
47 MODULE_LICENSE("GPL"); |
47 MODULE_VERSION(COMPILE_INFO); |
48 MODULE_VERSION(COMPILE_INFO); |
48 |
49 |
49 module_param(ecat_master_count, int, 1); |
50 module_param(ecat_master_count, int, 1); |
50 MODULE_PARM_DESC(ecat_master_count, "Number of EtherCAT master to initialize."); |
51 MODULE_PARM_DESC(ecat_master_count, |
|
52 "Number of EtherCAT master to initialize."); |
51 |
53 |
52 module_init(ecat_init_module); |
54 module_init(ecat_init_module); |
53 module_exit(ecat_cleanup_module); |
55 module_exit(ecat_cleanup_module); |
54 |
56 |
55 EXPORT_SYMBOL(EtherCAT_register_device); |
57 EXPORT_SYMBOL(EtherCAT_register_device); |
56 EXPORT_SYMBOL(EtherCAT_unregister_device); |
58 EXPORT_SYMBOL(EtherCAT_unregister_device); |
57 EXPORT_SYMBOL(EtherCAT_request); |
59 EXPORT_SYMBOL(EtherCAT_request); |
58 EXPORT_SYMBOL(EtherCAT_release); |
60 EXPORT_SYMBOL(EtherCAT_release); |
59 |
61 |
60 /******************************************************************************/ |
62 /*****************************************************************************/ |
61 |
63 |
62 /** |
64 /** |
63 Init-Funktion des EtherCAT-Master-Treibermodules |
65 Init-Funktion des EtherCAT-Master-Treibermodules |
64 |
66 |
65 Initialisiert soviele Master, wie im Parameter ecat_master_count |
67 Initialisiert soviele Master, wie im Parameter ecat_master_count |
73 { |
75 { |
74 unsigned int i; |
76 unsigned int i; |
75 |
77 |
76 printk(KERN_ERR "EtherCAT: Master driver, %s\n", COMPILE_INFO); |
78 printk(KERN_ERR "EtherCAT: Master driver, %s\n", COMPILE_INFO); |
77 |
79 |
78 if (ecat_master_count < 1) |
80 if (ecat_master_count < 1) { |
79 { |
81 printk(KERN_ERR "EtherCAT: Error - Illegal" |
80 printk(KERN_ERR "EtherCAT: Error - Illegal ecat_master_count: %i\n", |
82 " ecat_master_count: %i\n", ecat_master_count); |
81 ecat_master_count); |
|
82 return -1; |
83 return -1; |
83 } |
84 } |
84 |
85 |
85 printk(KERN_ERR "EtherCAT: Initializing %i EtherCAT master(s)...\n", |
86 printk(KERN_ERR "EtherCAT: Initializing %i EtherCAT master(s)...\n", |
86 ecat_master_count); |
87 ecat_master_count); |
87 |
88 |
88 if ((ecat_masters = (EtherCAT_master_t *) kmalloc(sizeof(EtherCAT_master_t) |
89 if ((ecat_masters = |
89 * ecat_master_count, |
90 (EtherCAT_master_t *) kmalloc(sizeof(EtherCAT_master_t) |
90 GFP_KERNEL)) == NULL) |
91 * ecat_master_count, |
91 { |
92 GFP_KERNEL)) == NULL) { |
92 printk(KERN_ERR "EtherCAT: Could not allocate memory for EtherCAT master(s)!\n"); |
93 printk(KERN_ERR "EtherCAT: Could not allocate" |
93 return -1; |
94 " memory for EtherCAT master(s)!\n"); |
94 } |
95 return -1; |
95 |
96 } |
96 if ((ecat_masters_reserved = (int *) kmalloc(sizeof(int) * ecat_master_count, |
97 |
97 GFP_KERNEL)) == NULL) |
98 if ((ecat_masters_reserved = |
98 { |
99 (int *) kmalloc(sizeof(int) * ecat_master_count, |
99 printk(KERN_ERR "EtherCAT: Could not allocate memory for reservation flags!\n"); |
100 GFP_KERNEL)) == NULL) { |
|
101 printk(KERN_ERR "EtherCAT: Could not allocate" |
|
102 " memory for reservation flags!\n"); |
100 kfree(ecat_masters); |
103 kfree(ecat_masters); |
101 return -1; |
104 return -1; |
102 } |
105 } |
103 |
106 |
104 for (i = 0; i < ecat_master_count; i++) |
107 for (i = 0; i < ecat_master_count; i++) |
157 oder das Geraet nicht geoeffnet werden konnte. |
161 oder das Geraet nicht geoeffnet werden konnte. |
158 */ |
162 */ |
159 |
163 |
160 int EtherCAT_register_device(int index, EtherCAT_device_t *device) |
164 int EtherCAT_register_device(int index, EtherCAT_device_t *device) |
161 { |
165 { |
162 if (index < 0 || index >= ecat_master_count) |
166 if (index < 0 || index >= ecat_master_count) { |
163 { |
|
164 printk(KERN_ERR "EtherCAT: Master %i does not exist!\n", index); |
167 printk(KERN_ERR "EtherCAT: Master %i does not exist!\n", index); |
165 return -1; |
168 return -1; |
166 } |
169 } |
167 |
170 |
168 return EtherCAT_master_open(&ecat_masters[index], device); |
171 return EtherCAT_master_open(&ecat_masters[index], device); |
169 } |
172 } |
170 |
173 |
171 /***************************************************************/ |
174 /*****************************************************************************/ |
172 |
175 |
173 /** |
176 /** |
174 Loescht das EtherCAT-Geraet, auf dem der Master arbeitet. |
177 Loescht das EtherCAT-Geraet, auf dem der Master arbeitet. |
175 |
178 |
176 @param master Der EtherCAT-Master |
179 @param master Der EtherCAT-Master |
177 @param device Das EtherCAT-Geraet |
180 @param device Das EtherCAT-Geraet |
178 */ |
181 */ |
179 |
182 |
180 void EtherCAT_unregister_device(int index, EtherCAT_device_t *device) |
183 void EtherCAT_unregister_device(int index, EtherCAT_device_t *device) |
181 { |
184 { |
182 if (index < 0 || index >= ecat_master_count) |
185 if (index < 0 || index >= ecat_master_count) { |
183 { |
|
184 printk(KERN_WARNING "EtherCAT: Master %i does not exist!\n", index); |
186 printk(KERN_WARNING "EtherCAT: Master %i does not exist!\n", index); |
185 return; |
187 return; |
186 } |
188 } |
187 |
189 |
188 EtherCAT_master_close(&ecat_masters[index], device); |
190 EtherCAT_master_close(&ecat_masters[index], device); |
189 } |
191 } |
190 |
192 |
191 /******************************************************************************/ |
193 /*****************************************************************************/ |
192 |
194 |
193 /** |
195 /** |
194 Reserviert einen bestimmten EtherCAT-Master und das zugehörige Gerät. |
196 Reserviert einen bestimmten EtherCAT-Master und das zugehörige Gerät. |
195 |
197 |
196 Gibt einen Zeiger auf den reservierten EtherCAT-Master zurueck. |
198 Gibt einen Zeiger auf den reservierten EtherCAT-Master zurueck. |