Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Dec 2007 16:55:54 +0100
From:      Gaye Abdoulaye Walsimou <walsimou@walsimou.com>
To:        freebsd-drivers@freebsd.org
Subject:   write/read data to/from parallel port
Message-ID:  <47693F0A.3000304@walsimou.com>

next in thread | raw e-mail | index | archive | help
Hello List,
I am trying to learn driver writing under FreeBSD. My first goal is 
reading/writing data through parallel port (0x378).
here is some dmesg output

ppc0: <Parallel port> at port 0x378-0x37f irq 7 on isa0
ppc0: SMC-like chipset (ECP/EPP/PS2/NIBBLE) in COMPATIBLE mode
ppc0: FIFO with 16/16/16 bytes threshold

Do I have to read all doc about ISA devices in the arch-handbook, 
because there isn't any other way to do it?
Here is what I began to do (inspired by the arch-handbook, I can kldload 
and kldunload) :


#include <sys/types.h>
#include <sys/module.h>
#include <sys/systm.h>  /* uprintf */
#include <sys/errno.h>
#include <sys/param.h>  /* defines used in kernel.h */
#include <sys/kernel.h> /* types used in module initialization */
#include <sys/conf.h>   /* cdevsw struct */
#include <sys/uio.h>    /* uio struct */
#include <sys/malloc.h>

/* Function prototypes */
static d_open_t      mpp0_open;
static d_close_t     mpp0_close;
static d_read_t      mpp0_read;
static d_write_t     mpp0_write;

/* Character device entry points */
static struct cdevsw mpp0_cdevsw = {
    .d_version = D_VERSION,
    .d_open = mpp0_open,
    .d_close = mpp0_close,
    .d_read = mpp0_read,
    .d_write = mpp0_write,
    .d_name = "mpp0",
};


/* vars */
static struct cdev *mpp0_dev;


/*
 * This function is called by the kld[un]load(2) system calls to
 * determine what actions to take when a module is loaded or unloaded.
 */

static int
mpp0_loader(struct module *m, int what, void *arg)
{
    int err = 0;

    switch (what) {
    case MOD_LOAD:                /* kldload */
        mpp0_dev = make_dev(&mpp0_cdevsw,
            0,
            UID_ROOT,
            GID_WHEEL,
            0666,
            "mpp0");
        uprintf("mpp0 device loaded.\n");
        break;
    case MOD_UNLOAD:        /* kldunload*/
        destroy_dev(mpp0_dev);
        uprintf("mpp0 device unloaded.\n");
        break;
    default:
        err = EOPNOTSUPP;
        break;
    }
    return(err);
}

static int
mpp0_open(struct cdev *dev, int oflags, int devtype, struct thread *p)
{
    int err = 0;

    uprintf("Opened device \"mpp0\" successfully.\n");
    return(err);
}

static int
mpp0_close(struct cdev *dev, int fflag, int devtype, struct thread *p)
{
    uprintf("Closing device \"mpp0\" successfully.\n");
    return(0);
}



static int
mpp0_read(struct cdev *dev, struct uio *uio, int ioflag)
{
    int err = 0;
    if(uio->uio_resid > 0)
    {
        uprintf("Reading device \"mpp0\"\n");
       
    }
    return(err);
}


static int
mpp0_write(struct cdev *dev, struct uio *uio, int ioflag)
{
    int err = 0;
    if(uio->uio_resid > 0)
    {
        uprintf("Writing device \"mpp0\"\n");       
   
    }
    return(err);
}

DEV_MODULE(mpp0,mpp0_loader,NULL);





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?47693F0A.3000304>