33 /*****************************************************************************/ |
33 /*****************************************************************************/ |
34 |
34 |
35 #define EC_LIT(X) #X |
35 #define EC_LIT(X) #X |
36 #define EC_STR(X) EC_LIT(X) |
36 #define EC_STR(X) EC_LIT(X) |
37 |
37 |
38 #define COMPILE_INFO "Revision " EC_STR(EC_REV) \ |
38 #define COMPILE_INFO "Revision " EC_STR(SVNREV) \ |
39 ", compiled by " EC_STR(EC_USER) \ |
39 ", compiled by " EC_STR(USER) \ |
40 " at " EC_STR(EC_DATE) |
40 " at " __DATE__ " " __TIME__ |
41 |
41 |
42 /*****************************************************************************/ |
42 /*****************************************************************************/ |
43 |
43 |
44 int ec_master_count = 1; |
44 int ec_master_count = 1; |
45 ec_master_t *ec_masters = NULL; |
45 ec_master_t *ec_masters = NULL; |
153 /**< Interrupt-Service-Routine */ |
153 /**< Interrupt-Service-Routine */ |
154 struct module *module |
154 struct module *module |
155 /**< Zeiger auf das Modul */ |
155 /**< Zeiger auf das Modul */ |
156 ) |
156 ) |
157 { |
157 { |
158 ec_device_t *device; |
|
159 ec_master_t *master; |
158 ec_master_t *master; |
|
159 |
|
160 if (!net_dev) { |
|
161 EC_WARN("Device is NULL!\n"); |
|
162 return NULL; |
|
163 } |
160 |
164 |
161 if (master_index >= ec_master_count) { |
165 if (master_index >= ec_master_count) { |
162 EC_ERR("Master %i does not exist!\n", master_index); |
166 EC_ERR("Master %i does not exist!\n", master_index); |
163 return NULL; |
167 return NULL; |
164 } |
168 } |
165 |
169 |
166 if (!net_dev) { |
|
167 EC_WARN("Device is NULL!\n"); |
|
168 return NULL; |
|
169 } |
|
170 |
|
171 master = ec_masters + master_index; |
170 master = ec_masters + master_index; |
172 |
171 |
173 if (master->device_registered) { |
172 if (master->device) { |
174 EC_ERR("Master %i already has a device!\n", master_index); |
173 EC_ERR("Master %i already has a device!\n", master_index); |
175 return NULL; |
174 return NULL; |
176 } |
175 } |
177 |
176 |
178 device = &master->device; |
177 if (!(master->device = (ec_device_t *) kmalloc(sizeof(ec_device_t), |
179 |
178 GFP_KERNEL))) { |
180 if (ec_device_init(device, master) < 0) return NULL; |
179 EC_ERR("Failed allocating device!\n"); |
181 |
180 return NULL; |
182 device->dev = net_dev; |
181 } |
183 device->tx_skb->dev = net_dev; |
182 |
184 device->isr = isr; |
183 if (ec_device_init(master->device, master, net_dev, isr, module)) |
185 device->module = module; |
184 return NULL; |
186 |
185 |
187 master->device_registered = 1; |
186 return master->device; |
188 |
|
189 return device; |
|
190 } |
187 } |
191 |
188 |
192 /*****************************************************************************/ |
189 /*****************************************************************************/ |
193 |
190 |
194 /** |
191 /** |
208 return; |
205 return; |
209 } |
206 } |
210 |
207 |
211 master = ec_masters + master_index; |
208 master = ec_masters + master_index; |
212 |
209 |
213 if (!master->device_registered || &master->device != device) { |
210 if (!master->device || master->device != device) { |
214 EC_WARN("Unable to unregister device!\n"); |
211 EC_WARN("Unable to unregister device!\n"); |
215 return; |
212 return; |
216 } |
213 } |
217 |
214 |
218 master->device_registered = 0; |
215 ec_device_clear(master->device); |
219 ec_device_clear(device); |
216 kfree(master->device); |
|
217 master->device = NULL; |
220 } |
218 } |
221 |
219 |
222 /****************************************************************************** |
220 /****************************************************************************** |
223 * |
221 * |
224 * Echtzeitschnittstelle |
222 * Echtzeitschnittstelle |
251 goto req_return; |
249 goto req_return; |
252 } |
250 } |
253 |
251 |
254 master = &ec_masters[index]; |
252 master = &ec_masters[index]; |
255 |
253 |
256 if (!master->device_registered) { |
254 if (!master->device) { |
257 EC_ERR("Master %i has no device assigned yet!\n", index); |
255 EC_ERR("Master %i has no device assigned yet!\n", index); |
258 goto req_return; |
256 goto req_return; |
259 } |
257 } |
260 |
258 |
261 if (!try_module_get(master->device.module)) { |
259 if (!try_module_get(master->device->module)) { |
262 EC_ERR("Failed to reserve device module!\n"); |
260 EC_ERR("Failed to reserve device module!\n"); |
263 goto req_return; |
261 goto req_return; |
264 } |
262 } |
265 |
263 |
266 if (ec_master_open(master) < 0) { |
264 if (ec_master_open(master)) { |
267 EC_ERR("Failed to open device!\n"); |
265 EC_ERR("Failed to open device!\n"); |
268 goto req_module_put; |
266 goto req_module_put; |
269 } |
267 } |
270 |
268 |
271 if (ec_scan_for_slaves(master) != 0) { |
269 if (!master->device->link_state) EC_WARN("Link is DOWN.\n"); |
|
270 |
|
271 if (ec_master_bus_scan(master) != 0) { |
272 EC_ERR("Bus scan failed!\n"); |
272 EC_ERR("Bus scan failed!\n"); |
273 goto req_close; |
273 goto req_close; |
274 } |
274 } |
275 |
275 |
276 ec_masters_reserved[index] = 1; |
276 ec_masters_reserved[index] = 1; |
316 EC_INFO("===== Stopping master %i... =====\n", i); |
316 EC_INFO("===== Stopping master %i... =====\n", i); |
317 |
317 |
318 ec_master_close(master); |
318 ec_master_close(master); |
319 ec_master_reset(master); |
319 ec_master_reset(master); |
320 |
320 |
321 module_put(master->device.module); |
321 module_put(master->device->module); |
322 ec_masters_reserved[i] = 0; |
322 ec_masters_reserved[i] = 0; |
323 |
323 |
324 EC_INFO("===== Master %i stopped. =====\n", i); |
324 EC_INFO("===== Master %i stopped. =====\n", i); |
325 return; |
325 return; |
326 } |
326 } |