bzr branch
http://darksoft.org/webbzr/alps/pcitool
210
by Suren A. Chilingaryan
Some tests are added |
1 |
#define _BSD_SOURCE
|
302
by Suren A. Chilingaryan
Fixes out-of-source builds and minor build issues |
2 |
#define _DEFAULT_SOURCE
|
210
by Suren A. Chilingaryan
Some tests are added |
3 |
#define _POSIX_C_SOURCE 199309L
|
4 |
#include <stdio.h> |
|
5 |
#include <stdlib.h> |
|
6 |
#include <unistd.h> |
|
7 |
#include <stdarg.h> |
|
8 |
#include <time.h> |
|
9 |
#include <sched.h> |
|
10 |
#include <sys/time.h> |
|
11 |
||
12 |
#include "pcilib.h" |
|
13 |
#include "irq.h" |
|
14 |
#include "kmem.h" |
|
15 |
||
16 |
#define DEVICE "/dev/fpga0"
|
|
17 |
//#define REALTIME
|
|
18 |
||
19 |
#define BAR PCILIB_BAR0
|
|
214
by Suren A. Chilingaryan
Support new revision of UFO cameras... |
20 |
#define BITS 32
|
210
by Suren A. Chilingaryan
Some tests are added |
21 |
#define MASK ((1ll << BITS) - 1)
|
22 |
||
23 |
||
24 |
#define WR(addr, value) { *(uint32_t*)(bar + addr) = value; }
|
|
25 |
#define RD(addr, value) { value = *(uint32_t*)(bar + addr); }
|
|
26 |
||
27 |
unsigned long long bits[BITS]; |
|
28 |
||
29 |
int main(int argc, char *argv[]) { |
|
30 |
uint32_t i, j; |
|
31 |
pcilib_t *pci; |
|
32 |
uint32_t reg, value, diff, errors; |
|
33 |
void* volatile bar; |
|
34 |
||
35 |
unsigned long long attempts = 0, failures = 0; |
|
36 |
||
37 |
if (argc < 2) { |
|
38 |
printf("Usage: %s <register>\n", argv[0]); |
|
39 |
exit(0); |
|
40 |
}
|
|
41 |
||
42 |
if (sscanf(argv[1], "%x", ®) != 1) { |
|
43 |
printf("Can't parse register %s\n", argv[1]); |
|
44 |
exit(1); |
|
45 |
}
|
|
46 |
||
47 |
#ifdef REALTIME
|
|
48 |
pid_t pid; |
|
49 |
struct sched_param sched = {0}; |
|
50 |
||
51 |
pid = getpid(); |
|
52 |
sched.sched_priority = sched_get_priority_min(SCHED_FIFO); |
|
53 |
if (sched_setscheduler(pid, SCHED_FIFO, &sched)) |
|
54 |
printf("Warning: not able to get real-time priority\n"); |
|
55 |
#endif /* REALTIME */ |
|
56 |
||
57 |
pci = pcilib_open(DEVICE, PCILIB_MODEL_DETECT); |
|
58 |
if (!pci) { |
|
59 |
printf("pcilib_open\n"); |
|
60 |
exit(1); |
|
61 |
}
|
|
62 |
||
324
by Suren A. Chilingaryan
Documentation update |
63 |
bar = pcilib_resolve_bar_address(pci, BAR, 0); |
210
by Suren A. Chilingaryan
Some tests are added |
64 |
if (!bar) { |
65 |
pcilib_close(pci); |
|
66 |
printf("map bar\n"); |
|
67 |
exit(1); |
|
68 |
}
|
|
69 |
||
70 |
for (i = 0; 1; i++) { |
|
71 |
WR(reg, (i%MASK)); |
|
72 |
RD(reg, value); |
|
73 |
||
74 |
attempts++; |
|
75 |
if (value != (i%MASK)) { |
|
76 |
failures++; |
|
77 |
||
78 |
diff = value ^ (i%MASK); |
|
79 |
for (errors = 0, j = 0; j < BITS; j++) |
|
80 |
if (diff&(1<<j)) errors++; |
|
81 |
bits[errors]++; |
|
82 |
||
83 |
//printf("written: %x, read: %x\n", i, value);
|
|
84 |
}
|
|
85 |
||
86 |
if ((i % 1048576 ) == 0) { |
|
87 |
printf("Attempts %llu, failures %llu (", attempts, failures); |
|
88 |
for (j = 1; j < BITS; j++) |
|
89 |
printf("%llu ", bits[j]); |
|
90 |
printf(")\n"); |
|
91 |
}
|
|
92 |
||
93 |
}
|
|
94 |
||
95 |
pcilib_close(pci); |
|
96 |
}
|