me8100_test_dio/wtest.c
changeset 4 a90b94337569
parent 3 fc24e3b47731
child 7 ee662c2e14f9
--- a/me8100_test_dio/wtest.c	Wed Jan 16 15:54:58 2002 +0100
+++ b/me8100_test_dio/wtest.c	Wed Jan 16 20:29:27 2002 +0100
@@ -23,35 +23,43 @@
 
 #include "me8100.h"
 
+#define USE_WRITE
+
 int main(void){
   int err = 0;
   static int file_handle = -1;
 
+#ifndef USE_WRITE
   unsigned short ctrl_a;
+#endif
   unsigned short value_a;
 
   printf("Write test, PID: %d\n", getpid());
-  file_handle = open("/dev/me8100_0", O_RDWR, 0);
+#ifdef USE_WRITE
+  printf("Using write()\n");
+#endif
+  file_handle = open("/dev/me8100_0", O_WRONLY, 0);
 
   if(file_handle < 0){
     printf("Cannot open path !\n");
     return 1;
   }
 
-  /* Write.
-   * HACK: The driver itself should remember the status
-   * of the IRQ bits in its control register
-   */
-  ctrl_a = ME8100_CTL_ENIO | ME8100_CTL_SOURCE | ME8100_CTL_IRQ_MASK;
+#ifndef USE_WRITE
+  ctrl_a = ME8100_CTRL_ENIO | ME8100_CTRL_SOURCE | ME8100_CTRL_IRQ_MASK;
   err = ioctl(file_handle, ME8100_WRITE_CTRL_A, &ctrl_a);
   if (err) {
     fprintf(stderr, "Can't setup output to port A\n");
     return 1;
   }
+#endif
 
-  value_a = 0x00;
-  for (value_a = 0x00; value_a < 0xffff; ++value_a) {
+  for (value_a = 0x01; value_a < 0xffff; ++value_a) {
+#ifndef USE_WRITE
     ioctl(file_handle, ME8100_WRITE_DO_A, &value_a);
+#else
+    write(file_handle, &value_a, sizeof(value_a));
+#endif
     printf("Wrote %04x\n", value_a);
     sleep(3);
   }