From 735aff52f0b280365f0e525cb67dbd25e638663d Mon Sep 17 00:00:00 2001 From: hadaq Date: Sun, 25 Jul 2010 16:37:45 +0000 Subject: [PATCH] new timeout, added timeout to flush_channel function --- libtrbnet/trbnet.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/libtrbnet/trbnet.c b/libtrbnet/trbnet.c index 4f339d4..552ffe0 100644 --- a/libtrbnet/trbnet.c +++ b/libtrbnet/trbnet.c @@ -1,4 +1,4 @@ -const char trbnet_version[] = "$Revision: 2.70 $"; +const char trbnet_version[] = "$Revision: 2.71 $"; #include #include @@ -128,7 +128,7 @@ const char trbnet_version[] = "$Revision: 2.70 $"; #define SHORT_TRANSFER 0x0100 /* Other */ -#define MAX_TIME_OUT 1500000 +#define MAX_TIMEOUT 5000000 #define DATA_BUFFER_SIZE 8192 /* ---------------------------------------------------------------------- */ @@ -389,7 +389,10 @@ static void fifo_flush(uint8_t channel) fifoAddress = CHANNEL_N_RECEIVER_DATA | ((channel * 2 + 1) << 4); do { - read32_from_FPGA(fifoAddress, &tmp); + unsigned int timeout = 0; + do { + read32_from_FPGA(fifoAddress, &tmp); + } while (((tmp & MASK_FIFO_VALID) == 0) && (++timeout < MAX_TIMEOUT)); /* DEBUG INFO */ if ((trb_debug > 1) && ((tmp & MASK_FIFO_VALID) != 0)) { fprintf(stderr, "FLUSH_FIFO_%03d: 0x%08x\n", counter, tmp); @@ -408,7 +411,7 @@ static int trb_wait_tx_not_busy(uint8_t channel) return -1; } - while (timeout < MAX_TIME_OUT) { + while (timeout < MAX_TIMEOUT) { read32_from_FPGA(CHANNEL_N_SENDER_STATUS | ((channel * 2 + 1) << 4), &tmp); if ((tmp & MASK_TX_RUNNING) == 0) { return 0; @@ -440,7 +443,7 @@ static int trb_init_transfer(uint8_t channel) &tmp); if ((tmp & MASK_FIFO_EMPTY) == 0) { trb_errno = TRB_FIFO_NOT_EMPTY; - /* clear fifo ???*/ + fifo_flush(channel); return -1; } @@ -494,15 +497,15 @@ static int trb_fifo_read(uint8_t channel, do { dma_size = read32_from_FPGA_dma(fifoBuffer, tmp, DATA_BUFFER_SIZE); - } while ((dma_size == 0) && (++timeout < MAX_TIME_OUT)); + } while ((dma_size == 0) && (++timeout < MAX_TIMEOUT)); } else { /* Standard */ do { read32_from_FPGA(fifoBuffer, tmp); - } while (((*tmp & MASK_FIFO_VALID) == 0) && (++timeout < MAX_TIME_OUT)); + } while (((*tmp & MASK_FIFO_VALID) == 0) && (++timeout < MAX_TIMEOUT)); } - if (timeout >= MAX_TIME_OUT) { + if (timeout >= MAX_TIMEOUT) { fifo_flush(channel); trb_errno = TRB_FIFO_TIMEOUT; return -1; @@ -877,9 +880,9 @@ static int trb_fifo_read(uint8_t channel, timeout = 0; do { read32_from_FPGA(fifoBuffer, tmp); - } while (((*tmp & MASK_FIFO_VALID) == 0) && (++timeout < MAX_TIME_OUT)); + } while (((*tmp & MASK_FIFO_VALID) == 0) && (++timeout < MAX_TIMEOUT)); - if (timeout >= MAX_TIME_OUT) { + if (timeout >= MAX_TIMEOUT) { fifo_flush(channel); trb_errno = TRB_FIFO_INCOMPLETE; return -1; -- 2.43.0