|
1 /****************************************************************************** |
|
2 * |
|
3 * ec_module.c |
|
4 * |
|
5 * EtherCAT-Master-Treiber |
|
6 * |
|
7 * Autoren: Wilhelm Hagemeister, Florian Pose |
|
8 * |
|
9 * $Id$ |
|
10 * |
|
11 * (C) Copyright IgH 2005 |
|
12 * Ingenieurgemeinschaft IgH |
|
13 * Heinz-Bäcker Str. 34 |
|
14 * D-45356 Essen |
|
15 * Tel.: +49 201/61 99 31 |
|
16 * Fax.: +49 201/61 98 36 |
|
17 * E-mail: sp@igh-essen.com |
|
18 * |
|
19 ******************************************************************************/ |
|
20 |
|
21 #include <linux/module.h> |
|
22 #include <linux/kernel.h> |
|
23 #include <linux/init.h> |
|
24 |
|
25 #include "ec_module.h" |
|
26 |
|
27 /******************************************************************************/ |
|
28 |
|
29 #define SUBVERSION_ID "$Id$" |
|
30 |
|
31 int ecat_master_count = 1; |
|
32 EtherCAT_master_t *ecat_masters = NULL; |
|
33 |
|
34 /******************************************************************************/ |
|
35 |
|
36 MODULE_AUTHOR ("Wilhelm Hagemeister <hm@igh-essen.com>, Florian Pose <fp@igh-essen.com>"); |
|
37 MODULE_DESCRIPTION ("EtherCAT master driver module"); |
|
38 MODULE_LICENSE("GPL"); |
|
39 MODULE_VERSION(SUBVERSION_ID); |
|
40 |
|
41 module_param(ecat_master_count, int, 1); |
|
42 MODULE_PARM_DESC(ecat_master_count, "Number of EtherCAT master to initialize."); |
|
43 |
|
44 module_init(ecat_init_module); |
|
45 module_exit(ecat_cleanup_module); |
|
46 |
|
47 EXPORT_SYMBOL(EtherCAT_master); |
|
48 |
|
49 /******************************************************************************/ |
|
50 |
|
51 /** |
|
52 Init-Funktion des EtherCAT-Master-Treibermodules |
|
53 |
|
54 Initialisiert soviele Master, wie im Parameter ecat_master_count |
|
55 angegeben wurde (Default ist 1). |
|
56 |
|
57 @returns 0, wenn alles o.k., -1 bei ungueltiger Anzahl Master |
|
58 oder zu wenig Speicher. |
|
59 */ |
|
60 |
|
61 int __init ecat_init_module(void) |
|
62 { |
|
63 unsigned int i; |
|
64 |
|
65 printk(KERN_ERR "EtherCAT: Master driver %s\n", SUBVERSION_ID); |
|
66 |
|
67 if (ecat_master_count < 1) |
|
68 { |
|
69 printk(KERN_ERR "EtherCAT: Error - Illegal ecat_master_count: %i\n", |
|
70 ecat_master_count); |
|
71 return -1; |
|
72 } |
|
73 |
|
74 printk(KERN_ERR "EtherCAT: Initializing %i EtherCAT master(s)...\n", |
|
75 ecat_master_count); |
|
76 |
|
77 if ((ecat_masters = (EtherCAT_master_t *) kmalloc(sizeof(EtherCAT_master_t) |
|
78 * ecat_master_count, |
|
79 GFP_KERNEL)) == NULL) |
|
80 { |
|
81 printk(KERN_ERR "EtherCAT: Could not allocate memory for EtherCAT master(s)!\n"); |
|
82 return -1; |
|
83 } |
|
84 |
|
85 for (i = 0; i < ecat_master_count; i++) |
|
86 { |
|
87 EtherCAT_master_init(&ecat_masters[i]); |
|
88 } |
|
89 |
|
90 printk(KERN_ERR "EtherCAT: Master driver initialized.\n"); |
|
91 |
|
92 return 0; |
|
93 } |
|
94 |
|
95 /******************************************************************************/ |
|
96 |
|
97 /** |
|
98 Cleanup-Funktion des EtherCAT-Master-Treibermoduls |
|
99 |
|
100 Entfernt alle Master-Instanzen. |
|
101 */ |
|
102 |
|
103 void __exit ecat_cleanup_module(void) |
|
104 { |
|
105 unsigned int i; |
|
106 |
|
107 printk(KERN_ERR "EtherCAT: Cleaning up master driver...\n"); |
|
108 |
|
109 if (ecat_masters) |
|
110 { |
|
111 for (i = 0; i < ecat_master_count; i++) |
|
112 { |
|
113 EtherCAT_master_clear(&ecat_masters[i]); |
|
114 } |
|
115 |
|
116 kfree(ecat_masters); |
|
117 } |
|
118 |
|
119 printk(KERN_ERR "EtherCAT: Master driver cleaned up.\n"); |
|
120 } |
|
121 |
|
122 /******************************************************************************/ |
|
123 |
|
124 /** |
|
125 Gibt einen Zeiger auf einen bestimmten EtherCAT-Master zurueck. |
|
126 |
|
127 @param index Index des gewuenschten Masters |
|
128 @returns Zeiger auf EtherCAT-Master oder NULL, wenn Parameter ungueltig. |
|
129 */ |
|
130 |
|
131 EtherCAT_master_t *EtherCAT_master(int index) |
|
132 { |
|
133 if (index < 0 || index >= ecat_master_count) |
|
134 { |
|
135 printk(KERN_ERR "EtherCAT: Master %i does not exist!\n", index); |
|
136 return NULL; |
|
137 } |
|
138 |
|
139 return &ecat_masters[index]; |
|
140 } |
|
141 |
|
142 /******************************************************************************/ |