]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
major bug in FIFO_READ_MEM... fixed (wrong static variable)
authorhadaq <hadaq>
Fri, 29 Oct 2010 18:46:22 +0000 (18:46 +0000)
committerhadaq <hadaq>
Fri, 29 Oct 2010 18:46:22 +0000 (18:46 +0000)
libtrbnet/trbnet.c

index 830342dbbe4f8e4ff994a5618f6f3c2a7164bb87..1914c0a347d8f47d78311a726308db680dd488e1 100644 (file)
@@ -1,4 +1,4 @@
-const char trbnet_version[] = "$Revision: 2.85 $";
+const char trbnet_version[] = "$Revision: 2.86 $";
 
 #include <stdlib.h>
 #include <signal.h>
@@ -512,6 +512,9 @@ static int trb_fifo_read(uint8_t channel,
 
   /* Read FIFO-Buffer, copy to User-Buffer */
   while ((*tmp & MASK_FIFO_VALID) != 0) {
+    uint32_t* lastHeader = NULL; /* used by FIFO_MODE_REG_READ_MEM Mode */
+    uint32_t memLen = 0;         /* used by FIFO_MODE_REG_READ_MEM     
+                                    and FIFO_MODE_IPU_DATA Mode         */
     fifoDebugCtr++;
 
     if (((*tmp & MASK_FIFO_TYPE) >> SHIFT_FIFO_TYPE) == FIFO_TYPE_IS_HEADER) {
@@ -553,8 +556,8 @@ static int trb_fifo_read(uint8_t channel,
       }
 
       if (((*tmp & MASK_FIFO_TYPE) >> SHIFT_FIFO_TYPE) !=
-           (counter - 1) % 2) {
-        /* Error: invalid sequence (not 0, 1, .), flush FIFO-BUFFER and exit */
+          (counter - 1) % 2) {
+        /* Error: invalid sequence (not 0, 1, .), flush FIFO-BUFFER, exit */
         fifo_flush(channel);
         trb_errno = TRB_FIFO_SEQUENZ;
         return -1;
@@ -735,9 +738,6 @@ static int trb_fifo_read(uint8_t channel,
 
         case FIFO_MODE_REG_READ_MEM:
           {
-            static uint32_t* lastHeader = NULL;
-            static uint32_t memLen = 0;
-
             switch (headerType) {
             case HEADER_HDR:
               if (dataCtr < dsize) {
@@ -773,6 +773,7 @@ static int trb_fifo_read(uint8_t channel,
             case HEADER_TRM:
               if (lastHeader != NULL) {
                 *lastHeader |= (memLen << 16);
+                lastHeader = NULL;
               }
               break;
 
@@ -787,9 +788,6 @@ static int trb_fifo_read(uint8_t channel,
 
         case FIFO_MODE_REGTIME_READ_MEM:
           {
-            static uint32_t* lastHeader = NULL;
-            static uint32_t memLen = 0;
-            
             switch (headerType) {
             case HEADER_HDR:
               if (dataCtr < dsize) {
@@ -826,6 +824,7 @@ static int trb_fifo_read(uint8_t channel,
             case HEADER_TRM:
               if (lastHeader != NULL) {
                 *lastHeader |= (memLen << 16);
+                lastHeader = NULL;
               }
               break;
 
@@ -843,13 +842,12 @@ static int trb_fifo_read(uint8_t channel,
 
         case FIFO_MODE_IPU_DATA:
           {
-            static unsigned int len = 0;
             unsigned int i;
 
             switch (headerType) {
 
             case HEADER_TRM:
-              if ((packageCtr > 0) && (dataCtr != len)) {
+              if ((packageCtr > 0) && (dataCtr != memLen)) {
                 /* Error invalid length */
                 fifo_flush(channel);
                 trb_errno = TRB_HDR_DLEN;
@@ -863,11 +861,11 @@ static int trb_fifo_read(uint8_t channel,
                 trb_errno = TRB_FIFO_INVALID_HEADER;
                 return -1;
               }
-              len = (unsigned int)package.F2;
+              memLen = (unsigned int)package.F2;
               break;
 
             case HEADER_DAT:
-              for (i = 0; (i < 2) && (dataCtr < len); i++) {
+              for (i = 0; (i < 2) && (dataCtr < memLen); i++) {
                 if (dataCtr < dsize) {
                   data[dataCtr++] = (i == 0)
                     ? (((uint32_t)package.F0 << 16) |
@@ -1920,7 +1918,7 @@ int network_reset()
   usleep(1000);
    
   write32_to_FPGA(0x10, 0x8000);
-  sleep(10);
+  sleep(8);
   
   com_reset();