--- a/lib/master.c Thu Aug 05 09:54:06 2010 +0200
+++ b/lib/master.c Thu Sep 16 10:16:12 2010 +0200
@@ -53,6 +53,60 @@
/*****************************************************************************/
+void ec_master_clear_config(ec_master_t *master)
+{
+ ec_domain_t *d, *next_d;
+ ec_slave_config_t *c, *next_c;
+
+ d = master->first_domain;
+ while (d) {
+ next_d = d->next;
+ ec_domain_clear(d);
+ d = next_d;
+ }
+ master->first_domain = NULL;
+
+ c = master->first_config;
+ while (c) {
+ next_c = c->next;
+ ec_slave_config_clear(c);
+ c = next_c;
+ }
+ master->first_config = NULL;
+}
+
+/*****************************************************************************/
+
+void ec_master_clear(ec_master_t *master)
+{
+ if (master->process_data) {
+ munmap(master->process_data, master->process_data_size);
+ }
+
+ ec_master_clear_config(master);
+
+ if (master->fd != -1) {
+ close(master->fd);
+ }
+}
+
+/*****************************************************************************/
+
+void ec_master_add_domain(ec_master_t *master, ec_domain_t *domain)
+{
+ if (master->first_domain) {
+ ec_domain_t *d = master->first_domain;
+ while (d->next) {
+ d = d->next;
+ }
+ d->next = domain;
+ } else {
+ master->first_domain = domain;
+ }
+}
+
+/*****************************************************************************/
+
ec_domain_t *ecrt_master_create_domain(ec_master_t *master)
{
ec_domain_t *domain;
@@ -71,14 +125,33 @@
return 0;
}
+ domain->next = NULL;
domain->index = (unsigned int) index;
domain->master = master;
domain->process_data = NULL;
+
+ ec_master_add_domain(master, domain);
+
return domain;
}
/*****************************************************************************/
+void ec_master_add_slave_config(ec_master_t *master, ec_slave_config_t *sc)
+{
+ if (master->first_config) {
+ ec_slave_config_t *c = master->first_config;
+ while (c->next) {
+ c = c->next;
+ }
+ c->next = sc;
+ } else {
+ master->first_config = sc;
+ }
+}
+
+/*****************************************************************************/
+
ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master,
uint16_t alias, uint16_t position, uint32_t vendor_id,
uint32_t product_code)
@@ -105,10 +178,16 @@
return 0;
}
+ sc->next = NULL;
sc->master = master;
sc->index = data.config_index;
sc->alias = alias;
sc->position = position;
+ sc->first_sdo_request = NULL;
+ sc->first_voe_handler = NULL;
+
+ ec_master_add_slave_config(master, sc);
+
return sc;
}
@@ -389,8 +468,9 @@
fprintf(stderr, "Failed to deactivate master: %s\n", strerror(errno));
return;
}
-}
-
+
+ ec_master_clear_config(master);
+}
/*****************************************************************************/
@@ -405,7 +485,6 @@
return 0;
}
-
/*****************************************************************************/
void ecrt_master_send(ec_master_t *master)