From 881c7081af013a24e799d80e2136e6a5adbd30c0 Mon Sep 17 00:00:00 2001 From: hadaq Date: Sun, 1 Nov 2009 12:59:06 +0000 Subject: [PATCH] check first header bug fix, improved MODE_TERM_ONLY --- libtrbnet/trbnet.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/libtrbnet/trbnet.c b/libtrbnet/trbnet.c index f56f3f1..a65a1af 100644 --- a/libtrbnet/trbnet.c +++ b/libtrbnet/trbnet.c @@ -1,4 +1,4 @@ -const char trbnet_version[] = "$Revision: 2.47 $"; +const char trbnet_version[] = "$Revision: 2.48 $"; #include #include @@ -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; -- 2.43.0