]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
trb_i2c modified
authorLudwig Maier <lmaier@crius.e12.ph.tum.de>
Wed, 29 Jan 2014 22:59:04 +0000 (23:59 +0100)
committerLudwig Maier <lmaier@crius.e12.ph.tum.de>
Wed, 29 Jan 2014 22:59:04 +0000 (23:59 +0100)
trbrich/trb_i2c.c

index c2b0acf4db5f0c2d812458d31bcc54f63995a343..02079d28c932aec00087562e0d2bfbd13601dfb8 100644 (file)
@@ -22,6 +22,9 @@ static uint16_t trb_i2c_register = 0x8040;
 
 static const unsigned int timeout = 1000;
 
+static int multBytes = 0;
+
+
 void usage(const char *progName)
 {
   printf("Usage: %s [-h] [-d] [-b numBytes] [-d level] [-V] <COMMAND>\n", 
@@ -29,7 +32,7 @@ void usage(const char *progName)
   printf("Options:\n");
   printf("  -h    give this help\n");
   printf("  -s    SPI Mode\n");
-  printf("  -b    number of bytes to be read 1..4\n");
+  printf("  -b    number of bytes to be read 1..4 (default 1)\n");
   printf("  -d    turn on Debugging Information\n");
   printf("  -V    Version number\n");
   printf("\nCommands:\n");
@@ -83,7 +86,7 @@ typedef enum I2C_ERROR {
 } I2C_STATUS_BITS;
 
 static int readI2CRegister(uint16_t trb_address, int checkStatus, 
-                          uint32_t* buffer, unsigned int bufferSize)
+                           uint32_t* buffer, unsigned int bufferSize)
 {
   unsigned int ctr = 0;
   int status;
@@ -117,7 +120,15 @@ static int readI2CRegister(uint16_t trb_address, int checkStatus,
       error = 1;
     }
   }
-    
+  
+  if (multBytes == 1) {
+    if ((status = trb_register_read(trb_address, trb_i2c_register + 1, 
+                                    buffer, BUFFER_SIZE)) == -1) {
+      trb_error("Error reading in multByte Mode");
+      return -1;
+    }
+  }
+
   return error == 0 ? status : -1;
 }
 
@@ -135,7 +146,7 @@ int main(int argc, char** argv)
 {
   int i;
   int spi_mode = 0;
-  unsigned int num_bytes = 0;
+  unsigned int num_bytes = 1;
   trb_debug = 0;
   
   /* Parse Arguments */
@@ -153,10 +164,11 @@ int main(int argc, char** argv)
       break;
     case 'b':
       num_bytes = strtoul(optarg, NULL, 0);
-      if (num_bytes > 4) {
+      if (!((num_bytes > 0) && (num_bytes <= 4))) {
         usage(basename(argv[0]));
         exit(EXIT_FAILURE);
       }
+      multBytes = 1;
       break;
     case 'd':
       trb_debug = strtoul(optarg, NULL, 0);
@@ -279,7 +291,7 @@ int main(int argc, char** argv)
 
     /* Read Value */
     if (spi_mode == 0) {
-      value = num_bytes == 0 
+      value = multBytes == 0 
         ? (0xff000000 | (i2c_chip << 16) | (i2c_register << 8)) 
         : (0xc0000000 | (num_bytes << 24) | 
            (i2c_chip << 16) | (i2c_register << 8));
@@ -310,7 +322,11 @@ int main(int argc, char** argv)
     
     /* Print results */
     for (i = 0; i < status; i += 2) {
-      printf("0x%04x  0x%02x\n", buffer[i], buffer[i + 1] & 0xff);
+      if (multBytes == 0) {
+        printf("0x%04x  0x%02x\n", buffer[i], buffer[i + 1] & 0xff);
+      } else {
+        printf("0x%04x  0x%08x\n", buffer[i], buffer[i + 1]);
+      }
     }
   
     free(buffer);