-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
72 lines (67 loc) · 1.48 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "mcpPciDriver_ioctl.h"
int main(int argc, char **argv) {
struct mcpPciDriverRead req;
int testfd;
unsigned char cmd;
testfd = open("/dev/test", O_RDWR | O_NONBLOCK);
if (!testfd) {
perror("open");
exit(1);
}
argc--;
argv++;
if (!argc) exit(1);
cmd = **argv;
argc--;
argv++;
if (!argc) exit(1);
if (cmd == 'r') {
req.address = strtoul(*argv, NULL, 0);
req.value = 0x00000000;
req.barno = 1;
if (ioctl(testfd, TEST_IOCREAD, &req)) {
perror("ioctl");
close(testfd);
exit(1);
}
} else if (cmd == 'w') {
req.address = strtoul(*argv, NULL, 0);
req.barno = 1;
argc--;
argv++;
if (!argc) exit(1);
req.value = strtoul(*argv, NULL, 0);
if (ioctl(testfd, TEST_IOCWRITE, &req)) {
perror("ioctl");
close(testfd);
exit(1);
}
} else if (cmd == 'R') {
req.address = strtoul(*argv, NULL, 0);
req.value = 0x00000000;
req.barno = 0;
if (ioctl(testfd, TEST_IOCREAD, &req)) {
perror("ioctl");
close(testfd);
exit(1);
}
} else if (cmd == 'W') {
req.address = strtoul(*argv, NULL, 0);
req.barno = 0;
argc--;
argv++;
if (!argc) exit(1);
req.value = strtoul(*argv, NULL, 0);
if (ioctl(testfd, TEST_IOCWRITE, &req)) {
perror("ioctl");
close(testfd);
exit(1);
}
}
printf("0x%8.8X: 0x%8.8X\n", req.address, req.value);
close(testfd);
exit(0);
}