187 |
187 |
188 /*****************************************************************************/ |
188 /*****************************************************************************/ |
189 |
189 |
190 /** |
190 /** |
191 Slave destructor. |
191 Slave destructor. |
|
192 Clears and frees a slave object. |
|
193 */ |
|
194 |
|
195 void ec_slave_destroy(ec_slave_t *slave /**< EtherCAT slave */) |
|
196 { |
|
197 ec_sdo_t *sdo, *next_sdo; |
|
198 |
|
199 // free all SDOs |
|
200 list_for_each_entry_safe(sdo, next_sdo, &slave->sdo_dictionary, list) { |
|
201 list_del(&sdo->list); |
|
202 ec_sdo_destroy(sdo); |
|
203 } |
|
204 |
|
205 // free SDO kobject |
|
206 if (slave->sdo_dictionary_fetched) kobject_del(&slave->sdo_kobj); |
|
207 kobject_put(&slave->sdo_kobj); |
|
208 |
|
209 // destroy self |
|
210 kobject_del(&slave->kobj); |
|
211 kobject_put(&slave->kobj); |
|
212 } |
|
213 |
|
214 /*****************************************************************************/ |
|
215 |
|
216 /** |
|
217 Clear and free slave. |
|
218 This method is called by the kobject, |
|
219 once there are no more references to it. |
192 */ |
220 */ |
193 |
221 |
194 void ec_slave_clear(struct kobject *kobj /**< kobject of the slave */) |
222 void ec_slave_clear(struct kobject *kobj /**< kobject of the slave */) |
195 { |
223 { |
196 ec_slave_t *slave; |
224 ec_slave_t *slave; |
197 ec_sii_string_t *string, *next_str; |
225 ec_sii_string_t *string, *next_str; |
198 ec_sii_sync_t *sync, *next_sync; |
226 ec_sii_sync_t *sync, *next_sync; |
199 ec_sii_pdo_t *pdo, *next_pdo; |
227 ec_sii_pdo_t *pdo, *next_pdo; |
200 ec_sii_pdo_entry_t *entry, *next_ent; |
228 ec_sii_pdo_entry_t *entry, *next_ent; |
201 ec_sdo_t *sdo, *next_sdo; |
|
202 ec_sdo_data_t *sdodata, *next_sdodata; |
229 ec_sdo_data_t *sdodata, *next_sdodata; |
203 |
230 |
204 slave = container_of(kobj, ec_slave_t, kobj); |
231 slave = container_of(kobj, ec_slave_t, kobj); |
205 |
232 |
206 // free all string objects |
233 // free all string objects |
232 |
259 |
233 if (slave->sii_group) kfree(slave->sii_group); |
260 if (slave->sii_group) kfree(slave->sii_group); |
234 if (slave->sii_image) kfree(slave->sii_image); |
261 if (slave->sii_image) kfree(slave->sii_image); |
235 if (slave->sii_order) kfree(slave->sii_order); |
262 if (slave->sii_order) kfree(slave->sii_order); |
236 if (slave->sii_name) kfree(slave->sii_name); |
263 if (slave->sii_name) kfree(slave->sii_name); |
237 |
|
238 // free all SDOs |
|
239 list_for_each_entry_safe(sdo, next_sdo, &slave->sdo_dictionary, list) { |
|
240 list_del(&sdo->list); |
|
241 kobject_del(&sdo->kobj); |
|
242 kobject_put(&sdo->kobj); |
|
243 } |
|
244 |
|
245 // free SDO kobject FIXME |
|
246 if (slave->sdo_dictionary_fetched) kobject_del(&slave->sdo_kobj); |
|
247 kobject_put(&slave->sdo_kobj); |
|
248 |
264 |
249 // free all SDO configurations |
265 // free all SDO configurations |
250 list_for_each_entry_safe(sdodata, next_sdodata, &slave->sdo_confs, list) { |
266 list_for_each_entry_safe(sdodata, next_sdodata, &slave->sdo_confs, list) { |
251 list_del(&sdodata->list); |
267 list_del(&sdodata->list); |
252 kfree(sdodata->data); |
268 kfree(sdodata->data); |