me8100_test_dio/wtest.c
changeset 3 fc24e3b47731
child 4 a90b94337569
equal deleted inserted replaced
2:3345048104fc 3:fc24e3b47731
       
     1 /*
       
     2  * Source File : me8100_test_dio.c
       
     3  * Destination : me8100_test_dio
       
     4  * Author      : GG (Guenter Gebhardt)                                 
       
     5  *    
       
     6  *                                                                     
       
     7  * File History: Version   Date       Editor   Action                  
       
     8  *---------------------------------------------------------------------
       
     9  *               1.00.00   01.07.12   GG       first release           
       
    10  *                                                                     
       
    11  *---------------------------------------------------------------------
       
    12  *                                                                     
       
    13  * Description:
       
    14  *   This program shows the use of the driver and the digital inputs
       
    15  *   and outputs. First the outputs are tested in sink and source mode. 
       
    16  *   Then the inputs are tested.
       
    17  */
       
    18 #include <stdio.h>
       
    19 #include <fcntl.h>
       
    20 #include <unistd.h>
       
    21 #include <sys/ioctl.h>
       
    22 #include <signal.h>
       
    23 
       
    24 #include "me8100.h"
       
    25 
       
    26 int main(void){
       
    27   int err = 0;
       
    28   static int file_handle = -1;
       
    29 
       
    30   unsigned short ctrl_a;
       
    31   unsigned short value_a;
       
    32 
       
    33   printf("Write test, PID: %d\n", getpid());
       
    34   file_handle = open("/dev/me8100_0", O_RDWR, 0);
       
    35 
       
    36   if(file_handle < 0){
       
    37     printf("Cannot open path !\n");
       
    38     return 1;
       
    39   }
       
    40 
       
    41   /* Write.
       
    42    * HACK: The driver itself should remember the status
       
    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);
       
    47   if (err) {
       
    48     fprintf(stderr, "Can't setup output to port A\n");
       
    49     return 1;
       
    50   }
       
    51 
       
    52   value_a = 0x00;
       
    53   for (value_a = 0x00; value_a < 0xffff; ++value_a) {
       
    54     ioctl(file_handle, ME8100_WRITE_DO_A, &value_a);
       
    55     printf("Wrote %04x\n", value_a);
       
    56     sleep(3);
       
    57   }
       
    58 
       
    59   err = close(file_handle);
       
    60   if(err){
       
    61     printf("Kann Pfad nicht schliessen\n");
       
    62     return 1;
       
    63   }
       
    64 
       
    65   return 0;
       
    66 }
       
    67 /*
       
    68 	vim:sts=2 sw=2 aw ai sm:
       
    69 */