I seem to be crashing my system every time I attempt to open /dev/ppi0!  I get a kernel panic, and it usually explains that nexus_setup_intr is unhappy.  I traced this all down to  /usr/src/sys/i386/i386/nexus.c  where it claims that somebody tried to setup an irq that failed to allocate.  I suspected that I might have a kernel slightly out of sync with my libraries, so I did the complete cvsup, buildworld, and installworld last night.  Everything seems to be operating correctly, with the exception of the ppi driver.

The piece of code I was running looks like this:

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>

#define PPIGDATA        _IOR('P', 10, u_int8_t)
#define PPIGSTATUS      _IOR('P', 11, u_int8_t)
#define PPIGCTRL        _IOR('P', 12, u_int8_t)
#define PPIGEPPD        _IOR('P', 13, u_int8_t)
#define PPIGECR         _IOR('P', 14, u_int8_t)
#define PPIGFIFO        _IOR('P', 15, u_int8_t)

#define PPISDATA        _IOW('P', 16, u_int8_t)
#define PPISSTATUS      _IOW('P', 17, u_int8_t)
#define PPISCTRL        _IOW('P', 18, u_int8_t)
#define PPISEPPD        _IOW('P', 19, u_int8_t)
#define PPISECR         _IOW('P', 20, u_int8_t)
#define PPISFIFO        _IOW('P', 21, u_int8_t)

#define PPIGEPPA        _IOR('P', 22, u_int8_t)
#define PPISEPPA        _IOR('P', 23, u_int8_t)
#define n(flags) (~(flags) & (flags))

/*
 * Parallel Port Chipset control bits.
 */
#define STROBE          0x01
#define AUTOFEED        0x02
#define nINIT           0x04
#define SELECTIN        0x08
#define IRQENABLE       0x10
#define PCD             0x20

#define nSTROBE         n(STROBE)
#define nAUTOFEED       n(AUTOFEED)
#define INIT            n(nINIT)
#define nSELECTIN       n(SELECTIN)
#define nPCD            n(PCD)
 

int pport_fd;

main()
{
  unsigned char data, status, ctrl;
  int pattern = 'A';

  pport_fd = open( "/dev/ppi0", O_RDONLY );
  if( pport_fd < 0 )
  {
    fprintf( stderr, "\nFailed to open printer port! 0x%x\n", pport_fd );
    exit( 1 );
  }
  else
  {
    printf( "\nopened port\n" ); fflush( stdout );
  }

  while( 1 )
  {
    ioctl( pport_fd, PPIGDATA,   &data );
    ioctl( pport_fd, PPIGSTATUS, &status );
    ioctl( pport_fd, PPIGCTRL,   &ctrl );

    printf("Status: 0x%.2x, Ctrl: 0x%.2x, Data: 0x%.2x\n", status, ctrl, data);
    sleep( 1 );
  }
}
 

It explodes when it hits the open() statement.  The only other clue I have is that I always find a lpd.core lying around in /, but the date is way off.  Does anyone have a clue whats going on?

Also, what I am really trying to do here is read a signal pin into FreeBSD somehow.  Its either 0 or +5V and it doesn't have to be real-time or fast or anything but accurate.  I just basically want to sample and detect whether or not a button on a custom panel is being pressed or not.  We would even be willing to get the signal in through the PE, -ACK, or whatever pins.

I have tried going through the /dev/joy0 interface and it doesn't seem to sense anything ( though the hardware is  PC-104 stuff, so I didn't put much faith in this ).  The joy device driver does detect the port and it seems to read something, but its always the same value.   I don't actually have a joystick to test this, so this could actually be working but I might not be pulling the pins to ground or +5 or whatever they are supposed to be pulled to.

One thing that makes me very proud of FreeBSD is that its device drivers actually did work with the sound card DSP whereas the manufacturer's drivers did not!  Also, this sysem uses the M-systems Disk On Chip2000, and FreeBSD already had the support right there in the LINT file, while Linux would have required kernel and LILO patches.
 
 
 

Reply via email to