]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
trb3 reset added
authorhadaq <hadaq>
Thu, 14 Jun 2012 13:20:04 +0000 (13:20 +0000)
committerhadaq <hadaq>
Thu, 14 Jun 2012 13:20:04 +0000 (13:20 +0000)
libtrbnet/trbnet.c

index 44165cac909889ddbc074b982897ef47f0824c9e..bca6df608cc492dc4d1c6bc7c4fa52e203787bbd 100644 (file)
@@ -1,4 +1,4 @@
-const char trbnet_version[] = "$Revision: 4.23 $  Local";
+const char trbnet_version[] = "$Revision: 4.24 $  Local";
 
 #include <stdlib.h>
 #include <signal.h>
@@ -22,7 +22,7 @@ const char trbnet_version[] = "$Revision: 4.23 $  Local";
 #define PCIBAR 0
                                                  
 static uint32_t dataBuffer[DMA_BUFFER_NUM_PAGES * 1024];
-static unsigned int dataBufferSize = 0;
+static unsigned int dataBufferSize = 0;  /* Size of dataBuffer in BYTES */
 
 static struct pexor_trbnet_io pexorDescriptor;
 int dma_size = 0;
@@ -39,7 +39,7 @@ int pexor_dma = 1;
 
 static uint16_t udpBuffer[750]; /* Maxminum is payload of one Ethernet-Frame */
 static uint16_t dataBuffer[4096 * 1024];
-static unsigned int dataBufferSize = 0;
+static unsigned int dataBufferSize = 0;  /* Size of dataBuffer in BYTES */
 static int trb3_sockfd = -1;
 static int trb3_sockfd_in = -1;
 static uint16_t trb3_port = 25000; 
@@ -385,7 +385,7 @@ static int getUDPPackage()
       : TRB_TRB3_SOCKET_ERROR;
     return -1;
   }
-  dataBufferSize = status / 2;
+  dataBufferSize = status;
   
   /* Adjust endianess ... */
   if (trb_debug > 2) {
@@ -427,6 +427,29 @@ static int sendTrbPackage(size_t size)
   
   return status;
 }
+
+static int sendTrbPackage_nowait(size_t size)
+{
+  int i;
+  
+  /* Adjust endianess ... */
+  for (i = 0; i < size; i++) {
+    if (trb_debug > 2) {
+      if (i == 0) {
+        fprintf(stderr, "udp sent:\n");
+      }
+      fprintf(stderr, "%d  0x%04x\n", i, udpBuffer[i]);
+    }
+    udpBuffer[i] = htons(udpBuffer[i]);
+  }
+  
+  if (send(trb3_sockfd, (void*)udpBuffer, size * 2, MSG_CONFIRM) == -1) {
+    trb_errno = TRB_TRB3_SOCKET_ERROR;
+    return -1;
+  }
+    
+  return 0;
+}
 #endif /* TRB3 */
 
 /* ------ Internal Functions -------------------------------------------- */
@@ -1683,7 +1706,6 @@ int trb_register_read(uint16_t trb_address,
     unlockPorts(0);
     return -1;
   }
-  dataBufferSize = status;
 
 #else
 
@@ -1779,7 +1801,6 @@ int trb_registertime_read(uint16_t trb_address,
     unlockPorts(0);
     return -1;
   }
-  dataBufferSize = status;
 
 #else
   /* Send command to pexor driver */
@@ -1886,7 +1907,6 @@ int trb_register_read_mem(uint16_t trb_address,
     unlockPorts(0);
     return -1;
   }
-  dataBufferSize = status;
 
 #else
 
@@ -2004,7 +2024,6 @@ int trb_registertime_read_mem(uint16_t trb_address,
     unlockPorts(0);
     return -1;
   }
-  dataBufferSize = status;
 
 #else
 
@@ -2111,7 +2130,6 @@ int trb_register_write(uint16_t trb_address,
     unlockPorts(0);
     return -1;
   }
-  dataBufferSize = status;
 
 #else
   /* Send command to pexor driver */
@@ -2207,50 +2225,49 @@ int trb_register_write_mem(uint16_t trb_address,
 
 #elif defined TRB3
 
-  udpBuffer[0] = HEADER_HDR | 0x30;
-  udpBuffer[1] = sender_address;
-  udpBuffer[2] = trb_address;
-  udpBuffer[3] = 0;
-  udpBuffer[4] = CMD_REGISTER_WRITE_MEM;
+    udpBuffer[0] = HEADER_HDR | 0x30;
+    udpBuffer[1] = sender_address;
+    udpBuffer[2] = trb_address;
+    udpBuffer[3] = 0;
+    udpBuffer[4] = CMD_REGISTER_WRITE_MEM;
   
-  udpBuffer[5] = HEADER_DAT | 0x30;
-  if (option == 0) {
-    udpBuffer[6] = reg_address + ctr;
-  } else {
-    udpBuffer[6] = reg_address;
-  }
-  udpBuffer[7] = config;
-  udpBuffer[8] = 0;
-  udpBuffer[9] = 0;
+    udpBuffer[5] = HEADER_DAT | 0x30;
+    if (option == 0) {
+      udpBuffer[6] = reg_address + ctr;
+    } else {
+      udpBuffer[6] = reg_address;
+    }
+    udpBuffer[7] = config;
+    udpBuffer[8] = 0;
+    udpBuffer[9] = 0;
   
-  udpCtr = 10;  
-  for (i = 0; i < len; i++, ctr++) {
-    udpBuffer[udpCtr++] = HEADER_DAT | 0x30;
-    udpBuffer[udpCtr++] = 0x00000000;
-    udpBuffer[udpCtr++] = (data[ctr] >> 16) & 0xffff;
-    udpBuffer[udpCtr++] = data[ctr] & 0xffff;
-    udpBuffer[udpCtr++] = 0x00000000;
-  }
+    udpCtr = 10;  
+    for (i = 0; i < len; i++, ctr++) {
+      udpBuffer[udpCtr++] = HEADER_DAT | 0x30;
+      udpBuffer[udpCtr++] = 0x00000000;
+      udpBuffer[udpCtr++] = (data[ctr] >> 16) & 0xffff;
+      udpBuffer[udpCtr++] = data[ctr] & 0xffff;
+      udpBuffer[udpCtr++] = 0x00000000;
+    }
 
-  udpBuffer[udpCtr++] = HEADER_TRM | 0x30;
-  udpBuffer[udpCtr++] = 0;
-  udpBuffer[udpCtr++] = 0;
-  udpBuffer[udpCtr++] = 0;
-  udpBuffer[udpCtr++] = CMD_REGISTER_WRITE_MEM;
+    udpBuffer[udpCtr++] = HEADER_TRM | 0x30;
+    udpBuffer[udpCtr++] = 0;
+    udpBuffer[udpCtr++] = 0;
+    udpBuffer[udpCtr++] = 0;
+    udpBuffer[udpCtr++] = CMD_REGISTER_WRITE_MEM;
   
-  status = sendTrbPackage(udpCtr);
+    status = sendTrbPackage(udpCtr);
   
-  if (status < 0) {
-    unlockPorts(0);
-    return -1;
-  }
-  dataBufferSize = status;
+    if (status < 0) {
+      unlockPorts(0);
+      return -1;
+    }
 
 #else
 
     /* Send command to pexor driver */
     if (write(pexorFileHandle,
-             (void*)(data + ctr), len * 4) != len * 4) {
+              (void*)(data + ctr), len * 4) != len * 4) {
       unlockPorts(0);
       trb_errno = pexor_to_trb_error();
       return -1;
@@ -2350,7 +2367,6 @@ int trb_read_uid(uint16_t trb_address,
     unlockPorts(0);
     return -1;
   }
-  dataBufferSize = status;
 
 #else
   /* Send command to pexor driver */
@@ -2458,7 +2474,6 @@ int trb_set_address(uint64_t uid,
     unlockPorts(0);
     return -1;
   }
-  dataBufferSize = status;
 
 #else
 
@@ -3013,8 +3028,39 @@ int fpga_register_write(uint32_t reg_address, uint32_t value)
 
 int network_reset()
 {
-  trb_errno = TRB_TRB3_CMD_NOT_SUPPORTED;
-  return -1;
+  int status;
+  
+  trb_errno = TRB_NONE;
+  
+  if (lockPorts(0) == -1) return -1;
+  
+  /* Init transfer */
+  if (trb_init_transfer(3) == -1) {
+    unlockPorts(0);
+    return -1;
+  }
+  
+  /* DEBUG INFO */
+  if (trb_debug > 0) {
+    fprintf(stderr, "Init_Transfer done.\n");
+  }
+
+  udpBuffer[0] = HEADER_HDR | 0x8030;
+  udpBuffer[1] = sender_address;
+  udpBuffer[2] = 0x0000;
+  udpBuffer[3] = 0;
+  udpBuffer[4] = CMD_NETADMINISTRATION;
+  
+  status = sendTrbPackage_nowait(5);
+    
+  if (status < 0) {
+    unlockPorts(0);
+    return -1;
+  }
+
+  sleep(8);
+
+  return status;
 }
 
 int com_reset()