21 #include <sys/ioctl.h> |
21 #include <sys/ioctl.h> |
22 #include <signal.h> |
22 #include <signal.h> |
23 |
23 |
24 #include "me8100.h" |
24 #include "me8100.h" |
25 |
25 |
|
26 #define USE_WRITE |
|
27 |
26 int main(void){ |
28 int main(void){ |
27 int err = 0; |
29 int err = 0; |
28 static int file_handle = -1; |
30 static int file_handle = -1; |
29 |
31 |
|
32 #ifndef USE_WRITE |
30 unsigned short ctrl_a; |
33 unsigned short ctrl_a; |
|
34 #endif |
31 unsigned short value_a; |
35 unsigned short value_a; |
32 |
36 |
33 printf("Write test, PID: %d\n", getpid()); |
37 printf("Write test, PID: %d\n", getpid()); |
34 file_handle = open("/dev/me8100_0", O_RDWR, 0); |
38 #ifdef USE_WRITE |
|
39 printf("Using write()\n"); |
|
40 #endif |
|
41 file_handle = open("/dev/me8100_0", O_WRONLY, 0); |
35 |
42 |
36 if(file_handle < 0){ |
43 if(file_handle < 0){ |
37 printf("Cannot open path !\n"); |
44 printf("Cannot open path !\n"); |
38 return 1; |
45 return 1; |
39 } |
46 } |
40 |
47 |
41 /* Write. |
48 #ifndef USE_WRITE |
42 * HACK: The driver itself should remember the status |
49 ctrl_a = ME8100_CTRL_ENIO | ME8100_CTRL_SOURCE | ME8100_CTRL_IRQ_MASK; |
43 * of the IRQ bits in its control register |
|
44 */ |
|
45 ctrl_a = ME8100_CTL_ENIO | ME8100_CTL_SOURCE | ME8100_CTL_IRQ_MASK; |
|
46 err = ioctl(file_handle, ME8100_WRITE_CTRL_A, &ctrl_a); |
50 err = ioctl(file_handle, ME8100_WRITE_CTRL_A, &ctrl_a); |
47 if (err) { |
51 if (err) { |
48 fprintf(stderr, "Can't setup output to port A\n"); |
52 fprintf(stderr, "Can't setup output to port A\n"); |
49 return 1; |
53 return 1; |
50 } |
54 } |
|
55 #endif |
51 |
56 |
52 value_a = 0x00; |
57 for (value_a = 0x01; value_a < 0xffff; ++value_a) { |
53 for (value_a = 0x00; value_a < 0xffff; ++value_a) { |
58 #ifndef USE_WRITE |
54 ioctl(file_handle, ME8100_WRITE_DO_A, &value_a); |
59 ioctl(file_handle, ME8100_WRITE_DO_A, &value_a); |
|
60 #else |
|
61 write(file_handle, &value_a, sizeof(value_a)); |
|
62 #endif |
55 printf("Wrote %04x\n", value_a); |
63 printf("Wrote %04x\n", value_a); |
56 sleep(3); |
64 sleep(3); |
57 } |
65 } |
58 |
66 |
59 err = close(file_handle); |
67 err = close(file_handle); |