how an application program utilizes the driver.

David Hawkins dwh at ovro.caltech.edu
Thu Sep 21 02:14:46 EST 2006


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









More information about the Linuxppc-embedded mailing list