Now failure in template based part of C code also release the master for later use...
authorEdouard Tisserant
Fri, 05 Apr 2013 21:47:37 +0900
changeset 2117 accc4cbca8d3
parent 2116 2b1980a038b1
child 2120 8e6e6364087e
Now failure in template based part of C code also release the master for later use...
etherlab/EthercatCFileGenerator.py
etherlab/plc_etherlab.c
--- a/etherlab/EthercatCFileGenerator.py	Fri Apr 05 16:49:41 2013 +0900
+++ b/etherlab/EthercatCFileGenerator.py	Fri Apr 05 21:47:37 2013 +0900
@@ -31,7 +31,7 @@
 
     if (ecrt_slave_config_pdos(slave%(slave)d, EC_END, slave_%(slave)d_syncs)) {
         SLOGF(LOG_CRITICAL, "EtherCAT failed to configure PDOs for slave %(device_type)s at alias %(alias)d and position %(position)d.");
-        return -1;
+        goto ecat_failed;
     }
 """
 
@@ -41,7 +41,7 @@
         EC_WRITE_%(data_type)s((uint8_t *)value, %(data)s);
         if (ecrt_master_sdo_download(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &abort_code)) {
             SLOGF(LOG_CRITICAL, "EtherCAT Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d. Error: %%d", abort_code);
-            return -1;
+            goto ecat_failed;
         }
     }
 """
@@ -51,7 +51,7 @@
         uint8_t value[%(data_size)d];
         if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
             SLOGF(LOG_CRITICAL, "EtherCAT failed to get default value for output PDO in slave %(device_type)s at alias %(alias)d and position %(position)d. Error: %%ud", abort_code);
-            return -1;
+            goto ecat_failed;
         }
         %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
     }
--- a/etherlab/plc_etherlab.c	Fri Apr 05 16:49:41 2013 +0900
+++ b/etherlab/plc_etherlab.c	Fri Apr 05 21:47:37 2013 +0900
@@ -47,13 +47,13 @@
     uint32_t abort_code;
     size_t result_size;
     
-	master = ecrt_request_master(%(master_number)d);
-	if (!master) {
+    master = ecrt_request_master(%(master_number)d);
+    if (!master) {
         SLOGF(LOG_CRITICAL, "EtherCAT master request failed!");
         return -1;
     }
 
-	if(!(domain1 = ecrt_master_create_domain(master))){
+    if(!(domain1 = ecrt_master_create_domain(master))){
         SLOGF(LOG_CRITICAL, "EtherCAT Domain Creation failed!");
         goto ecat_failed;
     }
@@ -66,7 +66,7 @@
         goto ecat_failed;
     }
 
-	ecrt_master_set_send_interval(master, common_ticktime__);
+    ecrt_master_set_send_interval(master, common_ticktime__);
 
     // slaves initialization
 %(slaves_initialization)s
@@ -91,15 +91,15 @@
     return 0;
 
 ecat_failed:
-	ecrt_release_master(master);
+    ecrt_release_master(master);
     return -1;
 
 }
 
 void __cleanup_%(location)s(void)
 {
-	//release master
-	ecrt_release_master(master);
+    //release master
+    ecrt_release_master(master);
     first_sent = 0;
 }