me8100_test_int/test.c
changeset 15 b9baa645576a
parent 12 67e56b4bce81
child 17 b51d4c6816e7
equal deleted inserted replaced
14:c3f6d5e9713a 15:b9baa645576a
    43 
    43 
    44 int main(void){
    44 int main(void){
    45   int err = 0;
    45   int err = 0;
    46   int oflags = 0;
    46   int oflags = 0;
    47 
    47 
    48   unsigned short mask_a;
       
    49   unsigned short ctrl_a;
       
    50 
       
    51   unsigned char icsr;
       
    52 
       
    53   printf("IRQ Test %d\n", getpid());
    48   printf("IRQ Test %d\n", getpid());
    54 
    49 
    55   file_handle = open("/dev/me8100_0a", O_RDONLY, 0);
    50   file_handle = open("/dev/me8100_0a", O_RDONLY, 0);
    56 
    51 
    57   if(file_handle < 0){
    52   if(file_handle < 0){
    71   oflags = fcntl(file_handle, F_GETFL);
    66   oflags = fcntl(file_handle, F_GETFL);
    72 
    67 
    73   /* Inform the driver to put the current process on the fasync queue */
    68   /* Inform the driver to put the current process on the fasync queue */
    74   fcntl(file_handle, F_SETFL, oflags | FASYNC); 
    69   fcntl(file_handle, F_SETFL, oflags | FASYNC); 
    75 
    70 
    76   /* enable both interrupts on the plx, set interrupts to high active */
    71   printf("Waiting for Interrupts\n\n");
    77   icsr =
       
    78     LOCAL_INT1_EN |
       
    79     LOCAL_INT1_POL |
       
    80     PCI_INT_EN;
       
    81 
    72 
    82   err = ioctl(file_handle, ME8100_SETUP_ICSR, &icsr);
    73   for(;;) {
    83   if(err){
    74     sleep(10);
    84     printf("Cannot setup PLX\n");
       
    85     return 1;
       
    86   }
       
    87 
       
    88   /*-------------------- Interrupt caused by bit mask -----------------*/
       
    89 
       
    90   /* Set the proper bit mask for port a */
       
    91   mask_a = 0xffff;
       
    92   err = ioctl(file_handle, ME8100_WRITE_MASK_A, &mask_a);
       
    93   if(err){
       
    94     printf("Cannot write mask a\n");
       
    95     return 1;
       
    96   }
       
    97 
       
    98   /* Enable interrupt signalling by bit mask for port a */
       
    99   ctrl_a = ME8100_CTRL_ENIO | ME8100_CTRL_SOURCE | ME8100_CTRL_IRQ_MASK;
       
   100   err = ioctl(file_handle, ME8100_WRITE_CTRL_A, &ctrl_a);
       
   101   if(err){
       
   102     printf("Cannot write ctrl a\n");
       
   103     return 1;
       
   104   }
       
   105 
       
   106   printf("<<<--- WAITING FOR INTERRUPTS BY BIT MASK --->>>\n\n");
       
   107 
       
   108   i = 0;
       
   109   while(i < 1000) {
       
   110     select(0, NULL, NULL, NULL, NULL);
       
   111   }
    75   }
   112 
    76 
   113   printf("Close path to me8100_0\n");
    77   printf("Close path to me8100_0\n");
   114   err = close(file_handle);
    78   err = close(file_handle);
   115   if(err){
    79   if(err){