]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
update, bug fixes
authorhadaq <hadaq>
Wed, 19 Aug 2009 17:53:10 +0000 (17:53 +0000)
committerhadaq <hadaq>
Wed, 19 Aug 2009 17:53:10 +0000 (17:53 +0000)
trbrich/pulser.c
trbrich/trb_i2c.c

index 3457ab81f2aeb6fe8bbd0c73fa94e58f82b0363e..48e519080392c34bf1395aabe0ecc3f549e61e9f 100644 (file)
@@ -51,7 +51,7 @@ void usage(const char *progName)
 int main(int argc, char ** argv)
 {
   char hldFileName[256] = "pulser.hld";
-  uint16_t trgNumber = 0;
+  unsigned int trgNumber = 0;
   uint8_t triggerType = 0;
   uint8_t input = 0;
   unsigned int numEvts = UINT_MAX;
@@ -131,7 +131,7 @@ int main(int argc, char ** argv)
     size = trb_ipu_data_read(triggerType, 0xcc, 0xdd, 0xaabb, 
                              buffer, bufferSize);
     if (size == -1) {
-      fprintf(stderr, "Error IPU Read\n");
+      trb_error("Error IPU Read");
       exit(EXIT_FAILURE);
     }
     
@@ -141,11 +141,11 @@ int main(int argc, char ** argv)
       exit(EXIT_FAILURE);
     }
     len = ((buffer[1] >> 16) & 0xffff) + 2;
-    if (len >= size) {
+    if (len != size) {
       fprintf(stderr, "DHRD len error, len=%d  size=%d\n", len, size);
       exit(EXIT_FAILURE);
     } 
-    /*fprintf(stderr, "number padding zeros: %d\n", size - len);*/
+
     if (writeToStdout == 1) {
       fprintf(stdout, "Trigger# %d\n", trgNumber);
       for (i = 0; i < len; i++) {
index 150cf3943409730a4d617120b99c892d079300f0..3cf7ef243d2d2169dc584d164cfff001c4f4bab1 100644 (file)
@@ -14,7 +14,7 @@
 
 static const uint16_t trb_i2c_register = 0x8040;
 
-static const unsigned int timeout = 100;
+static const unsigned int timeout = 1000;
 
 void usage(const char *progName)
 {
@@ -80,23 +80,21 @@ static int readI2CRegister(uint16_t trb_address, int checkStatus,
   int error = 0;
   int i;
   
-  while ((status = trb_register_read(trb_address, trb_i2c_register, 
-                                       buffer, BUFFER_SIZE)) == -1) {
-    ctr++;
+  /* Wait until NoMoreData is withdrawn */
+  do {
+    if ((status = trb_register_read(trb_address, trb_i2c_register, 
+                                    buffer, BUFFER_SIZE)) == -1) {
+      trb_error("Error I2C not ready");
+      return -1;
+    }
+    
     /* Check timeout */
     if (ctr >=  timeout) {
       fprintf(stderr, "Error I2C not ready, timeout\n");
       return -1;
     }
-      
-    /* check trb_statusbits ==  no_more_data --> continue */
-    if ((trb_errno == TRB_TERM_ERRBIT) && 
-        (((trb_statusbits >> 16) & 0x0004) != 0)) {
-      continue;
-    }
-    trb_error("Error I2C not ready");
-    return -1;
-  }
+    ctr++;
+  } while (trb_term.status_channel != 0);
   
   if (checkStatus == 0) return status;
   
@@ -232,6 +230,7 @@ int main(int argc, char** argv)
     
     /* Check whether I2C is ready */
     if (readI2CRegister(trb_address, 0, buffer, BUFFER_SIZE) == -1) {
+      trb_error("I2C not ready");
       exit(EXIT_FAILURE);
     }
 
@@ -242,14 +241,14 @@ int main(int argc, char** argv)
       clearI2C(trb_address);
       exit(EXIT_FAILURE);
     }
-    
+         
     /* Wait for ACK */
     if ((status = readI2CRegister(trb_address, 1, buffer, BUFFER_SIZE)) 
         == -1) {
       clearI2C(trb_address);
       exit(EXIT_FAILURE);
     }
-    
+  
     /* Clear IC2 bus */
     if (clearI2C(trb_address) == -1) {
       exit(EXIT_FAILURE);