]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
check first header bug fix, improved MODE_TERM_ONLY
authorhadaq <hadaq>
Sun, 1 Nov 2009 12:59:06 +0000 (12:59 +0000)
committerhadaq <hadaq>
Sun, 1 Nov 2009 12:59:06 +0000 (12:59 +0000)
libtrbnet/trbnet.c

index f56f3f19585490c21387ba2b62b370c2a2ef4578..a65a1af78695f50420df01957cbc643695b6aa57 100644 (file)
@@ -1,4 +1,4 @@
-const char trbnet_version[] = "$Revision: 2.47 $";
+const char trbnet_version[] = "$Revision: 2.48 $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -423,7 +423,7 @@ static int trb_init_transfer(uint8_t channel)
 }
 
 enum FIFO_READ_MODE {
-  FIFO_MODE_NONE,
+  FIFO_MODE_TERM_ONLY,
   FIFO_MODE_REG_READ,
   FIFO_MODE_REG_READ_MEM,
   FIFO_MODE_REG_WRITE,
@@ -567,11 +567,10 @@ static int trb_fifo_read(uint8_t channel,
         fprintf(stderr, "-------------------------------------------------\n");
       }
 
-
       if (trb_lazy == 0) {
         /* First package: headerType must be HDR or TRM */
         if (packageCtr == 0) {
-          if (!((headerType == HEADER_HDR) | (headerType == HEADER_TRM))) {
+          if (!((headerType == HEADER_HDR) || (headerType == HEADER_TRM))) {
             fifo_flush(channel);
             trb_errno = TRB_FIFO_INVALID_HEADER;
             return -1;
@@ -594,7 +593,17 @@ static int trb_fifo_read(uint8_t channel,
       /* Get Data F0 - F3 and store it in User-Data-Buffer if requested */
       switch (mode) {
 
-      case FIFO_MODE_NONE:
+      case FIFO_MODE_TERM_ONLY:
+        if (packageCtr > 0) {
+          fifo_flush(channel);
+          trb_errno = TRB_INVALID_PKG_NUMBER;
+          return -1; 
+        }
+        if (headerType != HEADER_TRM) {
+          fifo_flush(channel);
+          trb_errno = TRB_FIFO_INVALID_HEADER;
+          return -1;  
+        }
         break;
 
       case FIFO_MODE_REG_READ:
@@ -910,15 +919,15 @@ static int unlockPorts()
     SEM_UNDO               /*  */
   };
 
-  /* Unblock Signals */
-  sigprocmask(SIG_SETMASK, &blockSetOld, NULL);
-
   /* Release semaphore */
   if (semop(semid, &sops, 1) == -1) {
     trb_errno = TRB_SEMAPHORE;
     return -1;
   }
 
+  /* Unblock Signals */
+  sigprocmask(SIG_SETMASK, &blockSetOld, NULL);
+
   return 0;
 }
 
@@ -1412,7 +1421,7 @@ int trb_send_trigger(uint8_t type,
   }
 
   /* Check for replay packets (trigger) */
-  status = trb_fifo_read(0, FIFO_MODE_NONE, NULL, 0);
+  status = trb_fifo_read(0, FIFO_MODE_TERM_ONLY, NULL, 0);
 
   if (unlockPorts() == -1) return -1;
 
@@ -1480,7 +1489,7 @@ int trb_send_trigger_rich(uint8_t trg_input,
   }
 
   /* Check for replay packets (slowcontrol) */
-  status = trb_fifo_read(3, FIFO_MODE_NONE, NULL, 0);
+  status = trb_fifo_read(3, FIFO_MODE_TERM_ONLY, NULL, 0);
   if (status == -1) {
     fifo_flush(0);
     unlockPorts();
@@ -1488,7 +1497,7 @@ int trb_send_trigger_rich(uint8_t trg_input,
   }
 
   /* Check for replay packets (trigger) */
-  status = trb_fifo_read(0, FIFO_MODE_NONE, NULL, 0);
+  status = trb_fifo_read(0, FIFO_MODE_TERM_ONLY, NULL, 0);
 
   if (unlockPorts() == -1) return -1;