All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hawkins <dwh@ovro.caltech.edu>
To: Ming Liu <eemingliu@hotmail.com>
Cc: linuxppc-embedded@ozlabs.org
Subject: Re: how an application program utilizes the driver.
Date: Wed, 20 Sep 2006 09:14:46 -0700	[thread overview]
Message-ID: <451168F6.3030701@ovro.caltech.edu> (raw)
In-Reply-To: <BAY110-F240E99BA0EDF765EC09402B2230@phx.gbl>

Hi Ming,

> My situation is: I want to write a driver for my custom device.(In the 
> driver there are some functions defined to read or write my device.) Then 
> in my application program, I use these defined functions to operate my 
> hardware device. I think this is a normal process to operate the hardware 
> with driver+app, right? 

Right, but you've missed a few critical points.

For your custom device, you'll create a driver that implements
*kernel space* functions my_driver_open(), read(), write(), close()
etc. You'll install that module and create an appropriate
device node, eg. /dev/my_driver.

In your *user-space* application code, you'll open that device

int main(argc, argv) ...

  int fd = open("/dev/my_driver" ...)


and then write to your device ...

  int write(fd, buffer, len);

or read from your device ...

  int read(fd, buffer, len);

The user-space calls open, read, write eventually call down into
your driver space code. The driver and application are not
linked, they communicate via the /dev interface.

You really should read through Linux Device Drivers by Rubini,
or check out a tutorial such as

http://www.ovro.caltech.edu/~dwh/correlator/pdf/LNX-723-Hawkins.pdf
http://www.ovro.caltech.edu/~dwh/correlator/software/driver_design.tar.gz
http://www.ovro.caltech.edu/~dwh/correlator/index.html

Regards,
Dave

  reply	other threads:[~2006-09-20 16:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-20 13:48 how an application program utilizes the driver Ming Liu
2006-09-20 16:14 ` David Hawkins [this message]
2006-09-20 16:30   ` Josh Boyer
2006-09-21  8:13   ` Ming Liu
2006-09-21 17:06 ` Eric Nuckols

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=451168F6.3030701@ovro.caltech.edu \
    --to=dwh@ovro.caltech.edu \
    --cc=eemingliu@hotmail.com \
    --cc=linuxppc-embedded@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.