summaryrefslogtreecommitdiffstats
path: root/dma.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2011-07-14 00:09:41 +0200
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2011-07-14 00:09:41 +0200
commit9f17f71885344d93b16fdc17458aa28ba350a480 (patch)
tree2b652d79f2a3beece014da67ad532d357ad37e6c /dma.c
parent72e8984e195ad5d57b0461b4e6e8f205315e9764 (diff)
downloadpcitool-9f17f71885344d93b16fdc17458aa28ba350a480.tar.gz
pcitool-9f17f71885344d93b16fdc17458aa28ba350a480.tar.bz2
pcitool-9f17f71885344d93b16fdc17458aa28ba350a480.tar.xz
pcitool-9f17f71885344d93b16fdc17458aa28ba350a480.zip
Add timeout to pcilib_skip_dma
Diffstat (limited to 'dma.c')
-rw-r--r--dma.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/dma.c b/dma.c
index 04f1446..7e06b2e 100644
--- a/dma.c
+++ b/dma.c
@@ -9,6 +9,7 @@
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <arpa/inet.h>
+#include <sys/time.h>
#include <errno.h>
#include <assert.h>
@@ -165,7 +166,14 @@ static int pcilib_dma_read_callback(void *arg, pcilib_dma_flags_t flags, size_t
}
static int pcilib_dma_skip_callback(void *arg, pcilib_dma_flags_t flags, size_t bufsize, void *buf) {
-// if (arg) (*(uint32_t*)arg) += bufsize;
+ struct timeval *tv = (struct timeval*)arg;
+ struct timeval cur;
+
+ if (tv) {
+ gettimeofday(&cur, NULL);
+ if ((cur.tv_sec > tv->tv_sec)||((cur.tv_sec == tv->tv_sec)&&(cur.tv_usec > tv->tv_usec))) return 0;
+ }
+
return 1;
}
@@ -215,11 +223,20 @@ int pcilib_read_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size
int pcilib_skip_dma(pcilib_t *ctx, pcilib_dma_engine_t dma) {
int err;
- size_t skipped = 0;
+ struct timeval tv, cur;
+
+ gettimeofday(&tv, NULL);
+ tv.tv_usec += PCILIB_DMA_SKIP_TIMEOUT;
+ tv.tv_sec += tv.tv_usec / 1000000;
+ tv.tv_usec += tv.tv_usec % 1000000;
+
do {
// IMMEDIATE timeout is not working properly, so default is set
- err = pcilib_stream_dma(ctx, dma, 0, 0, PCILIB_DMA_FLAGS_DEFAULT, PCILIB_DMA_TIMEOUT, pcilib_dma_skip_callback, &skipped);
- } while ((!err)&&(skipped > 0));
+ err = pcilib_stream_dma(ctx, dma, 0, 0, PCILIB_DMA_FLAGS_DEFAULT, PCILIB_DMA_TIMEOUT, pcilib_dma_skip_callback, &tv);
+ gettimeofday(&cur, NULL);
+ } while ((!err)&&((cur.tv_sec < tv.tv_sec)||((cur.tv_sec == tv.tv_sec)&&(cur.tv_usec < tv.tv_usec))));
+
+ if ((cur.tv_sec > tv.tv_sec)||((cur.tv_sec == tv.tv_sec)&&(cur.tv_usec > tv.tv_usec))) return PCILIB_ERROR_TIMEOUT;
return 0;
}