[Linux-parport] Problems in interrupt handler

Axel Bayerl axel.bayerl at gmail.com
Thu Mar 11 01:14:16 EST 2010


I am trying to understand the ppdev parallel port driver, specifically
the interrupt handler.

But, tying to run the following program:

#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/ppdev.h>
#include <linux/parport.h>

int main(int argc, char **argv)
{
   int fd, mode;
   fd=open("/dev/parport0", O_RDWR);
   if (fd == -1) {
       perror ("open");
       return 1;
   }

   if (ioctl (fd, PPEXCL)) {
       perror ("PPCLAIM");
       close (fd);
       return 1;
   }

   if (ioctl (fd, PPCLAIM)) {
       perror ("PPCLAIM");
       close (fd);
       return 1;
   }

   for (;;)
   {
       int irqc;
       int busy = PARPORT_STATUS_ACK | PARPORT_STATUS_ERROR;
       int acking = PARPORT_STATUS_ERROR;
       int ready = PARPORT_STATUS_BUSY | PARPORT_STATUS_ACK |
PARPORT_STATUS_ERROR;
       char ch;

       /* Set up the control lines when an interrupt happens. */
       ioctl (fd, PPWCTLONIRQ, &busy);

       /* Now we're ready. */
       ioctl (fd, PPWCONTROL, &ready);

       /* Wait for an interrupt. */
       {
           fd_set rfds;
           FD_ZERO (&rfds);
           FD_SET (fd, &rfds);
           int i=select (fd + 1, &rfds, NULL, NULL, NULL);
           fprintf(stderr,"asd1-%d\n", i);
           if (!i)
               /* Caught a signal? */
               continue;
           fprintf(stderr,"asd2-%d\n", i);
       }

       /* We are now marked as busy. */

       /* Fetch the data. */
       ioctl (fd, PPRDATA, &ch);

       /* Clear the interrupt. */
       ioctl (fd, PPCLRIRQ, &irqc);
       if (irqc > 1)
         fprintf (stderr, "Arghh! Missed %d interrupt%s!\n",
          irqc - 1, irqc >= 2 ? "s" : "");

       /* Ack it. */
       ioctl (fd, PPWCONTROL, &acking);
       usleep (100);
       ioctl (fd, PPWCONTROL, &busy);

       putchar (ch);
       fflush(0);
   }

   if(ioctl(fd, PPRELEASE))
       printf("Argh! (3)");

   close(fd);
   return 0;
}

and short-circuiting nAck to GND, i get this output:


-------- (Lots of same lines) -------
asd1-1
asd2-1
asd1-1
asd2-1
asd1-1
asd2-1
asd1-1
asd2-1
----- (at some point near here i connected the pins) -------
Arghh! Missed 16 interrupts!
asd1-1
asd2-1
Arghh! Missed 55 interrupts!
asd1-1
asd2-1
Arghh! Missed 54 interrupts!
asd1-1
asd2-1
Arghh! Missed 53 interrupts!
asd1-1
asd2-1
Arghh! Missed 53 interrupts!
asd1-1
asd2-1
Arghh! Missed 56 interrupts!
-------- (same pattern of output till i hit ^C) -------

And even if i restart the program the second group of output still
shows up, only solution is to rmmod ppdev, parport_pc and parport, and
to modprobe them again.

The code was extracted from:
http://people.redhat.com/twaugh/parport/html/x916.html

Hardware specs:

lspci -nnvv
05:08.0 Communication controller [0780]: NetMos Technology PCI 1 port
parallel adapter [9710:9805] (rev 01)
        Subsystem: LSI Logic / Symbios Logic Device [1000:0010]
        Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop-
ParErr- Stepping- SERR+ FastB2B- DisINTx-
        Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium
>TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
        Interrupt: pin A routed to IRQ 17
        Region 0: I/O ports at cc00 [size=8]
        Region 1: I/O ports at c880 [size=8]
        Region 2: I/O ports at c800 [size=8]
        Region 3: I/O ports at c480 [size=8]
        Region 4: I/O ports at c400 [size=8]
        Region 5: I/O ports at c080 [size=16]
        Kernel driver in use: parport_pc

uname -a
        Linux rolland 2.6.32-2-686 #1 SMP Thu Feb 11 04:08:42 UTC 2010
i686 GNU/Linux

Debian GNU/Linux sid



More information about the Linux-parport mailing list