Feldregistrierung: NULL als data_ptr m?glich, field_count 0 = 1.
authorFlorian Pose <fp@igh-essen.com>
Mon, 20 Mar 2006 12:54:17 +0000
changeset 112 eec7639c7be9
parent 111 9963537ec776
child 113 a3dbd6bc8fce
Feldregistrierung: NULL als data_ptr m?glich, field_count 0 = 1.
master/domain.c
mini/mini.c
rt/msr_module.c
--- a/master/domain.c	Mon Mar 20 11:02:39 2006 +0000
+++ b/master/domain.c	Mon Mar 20 12:54:17 2006 +0000
@@ -122,7 +122,7 @@
     ec_field_reg_t *field_reg;
     ec_slave_t *slave;
     ec_fmmu_t *fmmu;
-    unsigned int i, j, found;
+    unsigned int i, j;
     uint32_t data_offset;
 
     if (domain->data) {
@@ -163,22 +163,15 @@
 
     // Alle Prozessdatenzeiger setzen
     list_for_each_entry(field_reg, &domain->field_regs, list) {
-        found = 0;
         for (i = 0; i < field_reg->slave->fmmu_count; i++) {
             fmmu = &field_reg->slave->fmmus[i];
             if (fmmu->domain == domain && fmmu->sync == field_reg->sync) {
                 data_offset = fmmu->logical_start_address - base_address
                     + field_reg->field_offset;
                 *field_reg->data_ptr = domain->data + data_offset;
-                found = 1;
                 break;
             }
         }
-
-        if (!found) { // Sollte nie passieren
-            EC_ERR("FMMU not found. Please report!\n");
-            return -1;
-        }
     }
 
     // Kommando-Array erzeugen
@@ -224,6 +217,12 @@
 /**
    Registriert ein Datenfeld innerhalb einer Domäne.
 
+   - Ist \a data_ptr NULL, so wird der Slave nur auf den Typ überprüft.
+   - Wenn \a field_count 0 ist, wird angenommen, dass 1 Feld registriert werden
+     soll.
+   - Wenn \a field_count größer als 1 ist, wird angenommen, dass \a data_ptr
+     auf ein entsprechend großes Array zeigt.
+
    \return Zeiger auf den Slave bei Erfolg, sonst NULL
 */
 
@@ -257,11 +256,6 @@
     unsigned int field_counter, i, j, orig_field_index, orig_field_count;
     uint32_t field_offset;
 
-    if (!field_count) {
-        EC_ERR("field_count may not be 0!\n");
-        return NULL;
-    }
-
     master = domain->master;
 
     // Adresse übersetzen
@@ -281,6 +275,12 @@
         return NULL;
     }
 
+    if (!data_ptr) {
+        // Wenn data_ptr NULL, Slave als registriert ansehen (nicht warnen).
+        slave->registered = 1;
+    }
+
+    if (!field_count) field_count = 1;
     orig_field_index = field_index;
     orig_field_count = field_count;
 
@@ -292,8 +292,9 @@
             field = sync->fields[j];
             if (!strcmp(field->name, field_name)) {
                 if (field_counter++ == field_index) {
-                    ec_domain_reg_field(domain, slave, sync, field_offset,
-                                        data_ptr++);
+                    if (data_ptr)
+                        ec_domain_reg_field(domain, slave, sync, field_offset,
+                                            data_ptr++);
                     if (!(--field_count)) return slave;
                     field_index++;
                 }
@@ -326,7 +327,7 @@
 {
     ec_field_init_t *field;
 
-    for (field = fields; field->data_ptr; field++)
+    for (field = fields; field->slave_address; field++)
         if (!ecrt_domain_register_field(domain, field->slave_address,
                                         field->vendor_name,
                                         field->product_name, field->data_ptr,
--- a/mini/mini.c	Mon Mar 20 11:02:39 2006 +0000
+++ b/mini/mini.c	Mon Mar 20 12:54:17 2006 +0000
@@ -29,25 +29,23 @@
 ec_domain_t *domain1 = NULL;
 
 // Datenfelder
-void *r_ssi_input, *r_ssi_status;
-void *r_field[9];
-void *r_4102[3];
+void *r_ssi_input, *r_ssi_status, *r_4102[3];
 
 // Kanäle
 uint32_t k_pos;
 uint8_t k_stat;
 
 ec_field_init_t domain1_fields[] = {
-    {&r_ssi_input,  "1", "Beckhoff", "EL5001", "InputValue",  0, 1},
-    {&r_ssi_status, "1", "Beckhoff", "EL5001", "Status",      0, 1},
-    {&r_field[1],   "2", "Beckhoff", "EL4132", "OutputValue", 0, 1},
-    {&r_field[2],   "3", "Beckhoff", "EL3162", "InputValue",  0, 1},
+    {&r_ssi_input,  "1", "Beckhoff", "EL5001", "InputValue",  0},
+    {&r_ssi_status, "1", "Beckhoff", "EL5001", "Status",      0},
+    {NULL,          "2", "Beckhoff", "EL4132", "OutputValue", 0},
+    {NULL,          "3", "Beckhoff", "EL3162", "InputValue",  0},
     {r_4102,        "4", "Beckhoff", "EL4102", "OutputValue", 0, 2},
-    {&r_field[4],   "5", "Beckhoff", "EL5001", "InputValue",  0, 1},
-    {&r_field[5],   "6", "Beckhoff", "EL1014", "InputValue",  0, 1},
-    {&r_field[6],   "7", "Beckhoff", "EL2004", "OutputValue", 0, 1},
-    {&r_field[7],   "8", "Beckhoff", "EL4132", "OutputValue", 0, 1},
-    {&r_field[8],   "9", "Beckhoff", "EL4132", "OutputValue", 0, 1},
+    {NULL,          "5", "Beckhoff", "EL5001", "InputValue",  0},
+    {NULL,          "6", "Beckhoff", "EL1014", "InputValue",  0},
+    {NULL,          "7", "Beckhoff", "EL2004", "OutputValue", 0},
+    {NULL,          "8", "Beckhoff", "EL4132", "OutputValue", 0},
+    {NULL,          "9", "Beckhoff", "EL4132", "OutputValue", 0},
     {}
 };
 
@@ -58,7 +56,7 @@
     static unsigned int counter = 0;
 
 #ifdef ASYNC
-    // Prozessdaten emfpangen
+    // Prozessdaten empfangen
     ecrt_master_async_receive(master);
     ecrt_domain_process(domain1);
 
@@ -70,13 +68,14 @@
     ecrt_domain_queue(domain1);
     ecrt_master_async_send(master);
 #else
-    // Prozessdaten senden und emfpangen
+    // Prozessdaten senden und empfangen
     ecrt_domain_queue(domain1);
     ecrt_master_sync_io(master);
     ecrt_domain_process(domain1);
 
     // Prozessdaten verarbeiten
-    k_pos   = EC_READ_U32(r_ssi);
+    k_pos   = EC_READ_U32(r_ssi_input);
+    k_stat  = EC_READ_U8(r_ssi_status);
 #endif
 
     if (counter) {
--- a/rt/msr_module.c	Mon Mar 20 11:02:39 2006 +0000
+++ b/rt/msr_module.c	Mon Mar 20 12:54:17 2006 +0000
@@ -66,12 +66,12 @@
 uint32_t k_finished;
 
 ec_field_init_t domain1_fields[] = {
-    {&r_ssi,  "1", "Beckhoff", "EL5001", "InputValue", 0, 1},
+    {&r_ssi,  "1", "Beckhoff", "EL5001", "InputValue", 0},
     {}
 };
 
 ec_field_init_t domain2_fields[] = {
-    {&r_ssi2,  "1", "Beckhoff", "EL5001", "InputValue", 0, 1},
+    {&r_ssi2,  "1", "Beckhoff", "EL5001", "InputValue", 0},
     {}
 };