]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
added function trb_nettrace
authorhadaq <hadaq>
Sat, 25 Feb 2012 20:36:27 +0000 (20:36 +0000)
committerhadaq <hadaq>
Sat, 25 Feb 2012 20:36:27 +0000 (20:36 +0000)
libtrbnet/trbcmd.c
libtrbnet/trbnet.c
libtrbnet/trbnet.h

index 0ad76a78058b6958df4c958bdea098c975d0cf93..d70ca8c35382bc71af17303553e33d5921777fb8 100644 (file)
@@ -25,7 +25,7 @@
 
 static int hexMode = HEXMODE;
 
-static const char trbcmd_version[] = "$Revision: 2.78 $";
+static const char trbcmd_version[] = "$Revision: 2.79 $";
 
 #define BACKLOG 10
 static uint16_t tcp_port = 55555;
@@ -142,7 +142,8 @@ void usage(const char *progName)
           "clear bits of a register\n");
   fprintf(stdout, "   loadbit <trbaddress> <register> <bitmask> <val>  -> "
           "load bits of a register\n");
-
+  fprintf(stdout, "   nettrace <trbaddress>                            -> "
+          "trace TRBNet-Path of an endpoint\n");
   fprintf(stdout, "   reload <trbaddress>                              -> "
           "reload FPGA\n");
   fprintf(stdout, "   reset                                            -> "
@@ -357,6 +358,7 @@ int start(int argc, char **argv)
                                    buffer, BUFFER_SIZE);
         if (status == -1) {
           logError(ERROR, "read_register failed: %s\n", trb_strerror());
+          return -1;
         } else {
           for (i = 0; i < status; i += 2) {
             fprintf(stdout, "0x%04x  0x%08x\n", buffer[i], buffer[i + 1]);
@@ -397,6 +399,7 @@ int start(int argc, char **argv)
                                        buffer, BUFFER_SIZE);
         if (status == -1) {
           logError(ERROR, "read_register failed: %s\n", trb_strerror());
+          return -1;
         } else {
           for (i = 0; i < status; i += 3) {
             fprintf(stdout, "0x%04x  0x%08x 0x%04x\n",
@@ -1154,7 +1157,6 @@ int start(int argc, char **argv)
         if (status == -1) {
           logError(ERROR, "clearbit of register failed: %s\n",
                    trb_strerror());
-
           return -1;
         }
 
@@ -1194,7 +1196,40 @@ int start(int argc, char **argv)
                    trb_strerror());
           return -1;
         }
+        
+      } else if (strncmp(cmd[0], "nettrace", CMD_SIZE) == 0) {
+
+        /*******************************************/
+        /* Nettrace                                */
+        /*******************************************/
 
+        int status = 0;
+
+        if (cmdLen != 2) {
+          logError(ERROR, "Invalid command, try -h option\n");
+          return -1;
+        }
+
+        trb_address = strtoul(cmd[1], NULL, hexMode == 1 ? 16 : 0);
+
+        /* DEBUG Info */
+        if (trb_debug > 0) {
+          fprintf(stderr,
+                  "Command: NETTRACE: trb_address: 0x%04x\n",
+                  trb_address);
+        }
+
+        status = trb_nettrace(trb_address, buffer, BUFFER_SIZE);
+        if (status == -1) {
+          logError(ERROR, "nettrace of trbaddress 0x%04x failed: %s\n",
+                   trb_address, trb_strerror());
+          return -1;
+        }
+        
+        for (i = 0; i < status; i += 2) {
+          fprintf(stdout, "0x%04x  0x%08x\n", buffer[i], buffer[i + 1]);
+        }
+        
       } else {
 
         /*******************************************/
index 42303bcc5e5de6cf3fb350de2940ddc31f6435d7..4a977adea920670d8116479922216d7c275b889b 100644 (file)
@@ -1,4 +1,4 @@
-const char trbnet_version[] = "$Revision: 4.16 $  Local";
+const char trbnet_version[] = "$Revision: 4.17 $  Local";
 
 #include <stdlib.h>
 #include <signal.h>
@@ -1461,6 +1461,8 @@ int trb_register_read(uint16_t trb_address,
   write32_to_FPGA(CHANNEL_3_SENDER_DATA, 0x00000000);
   write32_to_FPGA(CHANNEL_3_SENDER_CONTROL, CMD_REGISTER_READ);
 #else
+
+
   /* Send command to pexor driver */
   pexorDescriptor.trb_address = trb_address;
   pexorDescriptor.reg_address = reg_address;
@@ -2510,3 +2512,59 @@ int trb_register_modify(uint16_t trb_address,
 
   return 0;
 }
+
+int trb_nettrace(uint16_t trb_address,
+                 uint32_t *data,
+                 unsigned int dsize)
+{
+  static const size_t NUM_ENDPOINTS = 1024;
+  uint32_t *buffer = NULL;
+  int status = 0;
+  unsigned int i;
+  unsigned int ctr;
+  
+  trb_errno = TRB_NONE;
+  
+  if (lockPorts(1) == -1) return -1;
+  
+  buffer = (uint32_t *) malloc(sizeof(uint32_t) * NUM_ENDPOINTS * 2);
+  if (buffer == NULL) abort(); 
+  
+  /* DEBUG INFO */
+  if (trb_debug > 0) {
+    fprintf(stderr, "nettrace started.\n");
+  }
+  
+  if (trb_register_read(0xfffe, 0xa5, buffer, NUM_ENDPOINTS * 2) == -1) {
+    unlockPorts(1);
+    free(buffer);
+    return -1;
+  }
+  trb_register_read_mem(trb_address, 0, 0, 1, buffer, NUM_ENDPOINTS * 2);
+  
+  status = trb_register_read(0xfffe, 0xa5, buffer, NUM_ENDPOINTS * 2);
+  if (unlockPorts(1) == -1) return -1; 
+  
+  if (status == -1) {
+    free(buffer);
+    return -1;
+  }
+  
+  ctr = 0;
+  for (i = 0; (i + 1) < status; i += 2) {
+    if (buffer[i + 1] == 0) {
+      fprintf(stderr, "hallo\n");
+      continue;
+    }
+    if (ctr + 1 >= dsize) {
+      trb_errno = TRB_USER_BUFFER_OVF;
+      free(buffer);
+      return -1;
+    }
+    data[ctr++] = buffer[i];
+    data[ctr++] = buffer[i + 1];
+  }
+  
+  free(buffer);
+  return ctr;
+}
index ca26107e4515adfe47e5aee6d7a97ff252bab02e..df2f6c8645a352ed292c1ec89de656c93e3115aa 100644 (file)
@@ -88,6 +88,10 @@ int fpga_register_read(uint32_t reg_address,
 int fpga_register_write(uint32_t reg_address,
                         uint32_t value);
 
+int trb_nettrace(uint16_t trb_address,
+                 uint32_t *data,
+                 unsigned int dsize);
+
 #ifdef PEXOR
 int fpga_register_read_mem(uint32_t reg_address, 
                            uint32_t* data,