]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
new adcsnoop function added
authorhadaq <hadaq>
Wed, 11 Nov 2009 22:19:13 +0000 (22:19 +0000)
committerhadaq <hadaq>
Wed, 11 Nov 2009 22:19:13 +0000 (22:19 +0000)
trbrich/trbrichcmd.c

index dad594634bd55f7205e25887cc9a7378c066c58a..2d886dccfc4a8699b7a3ed7f187bc9ac50818fca 100644 (file)
@@ -13,7 +13,7 @@
 
 #define TEMP_RESOLUTION 0.0625
 
-static const char trb_i2c_version[] = "$Revision: 1.4 $"; 
+static const char trb_i2c_version[] = "$Revision: 1.5 $"; 
 
 static const uint16_t adcm_uid_register = 0xc000;
 
@@ -24,8 +24,12 @@ void usage(const char *progName)
   printf("  -h    give this help\n");
   printf("  -V    Version number\n");
   printf("\nCommands:\n");
-  printf("   uid <trb_address>     -> read uids from APV-FrondEnds\n");
-  printf("   temp <trb_address>    -> read temperatures from APV-FrondEnds\n");
+  printf("   uid <trb_address>      "
+         "-> read uids from APV-FrondEnds\n");
+  printf("   temp <trb_address>     "
+         "-> read temperatures from APV-FrondEnds\n");
+  printf("   adcsnoop <trb_address> "
+         "-> ADC Snifer Tool\n");
 }
 
 /* ------ MAIN ---------------------------------------------------------- */
@@ -176,6 +180,68 @@ int main(int argc, char** argv)
       printf("\n");
     }
     
+  } else if (strcmp(argv[optind], "adcsnoop") == 0) {
+    
+    /*************************************************/
+    /* Read Temperatures                             */
+    /*************************************************/
+    
+    uint32_t *sampleBuffer = NULL;
+    uint32_t *buffer = NULL;
+    uint16_t trb_address = 0;
+    unsigned int ch = 0;
+    unsigned int i = 0;
+    
+    if (argc - optind != 2) {
+      usage(argv[0]);
+      exit(EXIT_FAILURE);
+    }   
+    
+    trb_address = (uint16_t)strtoul(argv[optind + 1], NULL, 0);
+    
+    if ((buffer = (uint32_t*)malloc(sizeof(uint32_t) * 1025)) == NULL) {
+      abort();
+    }
+    if ((sampleBuffer = 
+         (uint32_t*)malloc(sizeof(uint32_t) * 1024 * 16)) == NULL) {
+      abort();
+    }
+    
+    for (ch = 0; ch < 16; ch++) {
+      uint16_t reg_address = 0xf000 + (0x800 * (ch / 8));
+      uint32_t value = (ch % 8);
+      uint32_t start = 0;
+      if (trb_register_write(trb_address, reg_address, 0x4000 | value) == -1) {
+        trb_error("Error start sampling");
+        exit(EXIT_FAILURE);
+      } 
+      usleep(100000);
+      if (trb_register_write(trb_address, adcm_uid_register, value) == -1) {
+        trb_error("Error stop sampling");
+        exit(EXIT_FAILURE);
+      } 
+      
+      if (trb_register_read_mem(trb_address, reg_address,
+                                0, 1024, buffer, 1025) == -1) {
+        trb_error("Error reading sampleBuffer");
+        exit(EXIT_FAILURE);
+      }
+      
+      start = ((buffer[i + 1] >> 16) & 0x3ff);
+      for (i = 0; i < 1024; i++) {
+        sampleBuffer[ch * 1024 + i] = buffer[start + 1] & 0x0fff; 
+        start = start >= 1023 ? 0 : start + 1;
+      }
+    }
+    
+    for (i = 0; i < 1024; i++) {
+      fprintf(stdout, "%4d  ", i);
+      for (ch = 0; ch < 16; ch++) {
+        fprintf(stdout, "  %4d", sampleBuffer[ch * 1024 + i]);
+      }
+      fprintf(stdout, "\n");
+    }
+  
   } else {
     usage(basename(argv[0]));
     exit(EXIT_FAILURE);