Re: [PARPORT] need a code snippet ...

From: Tim Waugh (twaugh@redhat.com)
Date: Thu Mar 15 2001 - 11:08:14 EST

  • Next message: Philip Blundell: "Re: [PARPORT] Questions with ppdev"

    On Thu, Mar 15, 2001 at 09:52:46AM -0500, Craig Haller wrote:

    > We are developing a parallel port device for the embedded systems
    > market and need to make it fully Linux compatible. We are new to
    > Linux. Can some forward an example code snippet, from which we will
    > continue, that:

    First of all, there are several different ways to do this. The way
    you choose will ultimately depend on which version of the Linux kernel
    you intend to write drivers for.

    You might want to consider making the specifications available for the
    device (in terms of what to send/receive and when, and what it means),
    so that Linux drivers can be written for you by Linux advocates who
    decide that they want to use your device.

    > 1. Opens the parport driver
    > 2. "Attempts" to set up ECP mode
    > 3. Sends a buffer
    > 4. Recieves a buffer
    > 5. Closes the port

    Under 2.4.x kernels, this is (supposed to be) easy to do from user
    space, like this (might not compile):

    #include <stdio.h>
    #include <sys/ioctl.h>
    #include "parport.h"
    #include "ppdev.h"

    int main ()
    {
            // No error checking..

            int mode;
            char *buffer;

            // Open the parport driver
            int fd = open ("/dev/parport0", O_RDWR);

            // Attempt to set up ECP mode
            mode = IEEE1284_MODE_ECP;
            ioctl (fd, PPNEGOT, &mode);

            buffer = malloc (20);

            // Send a buffer
            write (fd, buffer, 20);

            // Receive a buffer
            read (fd, buffer, 20);

            // Close the port
            close (fd);
    }

    Here, "parport.h" and "ppdev.h" are the files from the kernel source
    tree (just put them in your source directory).

    For 2.2.x kernels, the /dev/parport0 driver isn't in the mainstream
    source and so you need to apply a kernel patch to make the above
    program work.

    Another way of doing it is to write an in-kernel driver. For this too
    I'd recommend writing for 2.4.x kernels than 2.2.x kernels, since
    there is better support for things like ECP transfers and IEEE 1284
    negotiation.

    Take a look at <URL:http://people.redhat.com/twaugh/parport/html/> for
    more information about writing parport drivers for 2.4.x kernels.

    Hope that helps.

    Tim.
    */



    -- To unsubscribe, send mail to: linux-parport-request@torque.net --
    -- with the single word "unsubscribe" in the body of the message. --



    This archive was generated by hypermail 2b29 : Thu Mar 15 2001 - 11:10:26 EST