linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* how an application program utilizes the driver.
@ 2006-09-20 13:48 Ming Liu
  2006-09-20 16:14 ` David Hawkins
  2006-09-21 17:06 ` Eric Nuckols
  0 siblings, 2 replies; 5+ messages in thread
From: Ming Liu @ 2006-09-20 13:48 UTC (permalink / raw)
  To: linuxppc-embedded

Dear all,
Maybe this question sounds stupid for most software engineers. But I really 
have much confusion on this topic. So I have to ask for explanation.

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? 

My driver is defined in drv_hello.c. I have compiled it into a module 
drv_hello.ko and it could be insmoded or rmmoded correctly. It looks like:

//drv_hello.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("Dual BSD/GPL");

void show_hello(){
    printk("hello.\n");
}

static int hello_init(void){
    printk(KERN_ALERT "module starts.\n");
    return 0;
}

static void hello_exit(void){
    printk(KERN_ALERT "module exits.\n");
}

module_init(hello_init);
module_exit(hello_exit);

EXPORT_SYMBOL(show_hello);



In my application program app_hello.c, I use the function show_hello to 
achieve the simple task: print "hello" on the console. Here is my app 
program:

//app_hello.c
extern void show_hello();

int main(int argc, char** argv)
{
    show_hello();

    return 0;
}

Then, here comes my problem: I don't know how to compile my application 
program and then it could dynamically refer to the function show_hello() 
defined in the memory area of the driver module. How can I tell the 
compiler and linker that the app program is expected to be linked with the 
driver module dynamically? If possible, please give me a detailed 
explanation. 

Waiting for your suggestion. Thanks for your help.

Regards
Ming

_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger:  http://messenger.msn.com/cn  

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how an application program utilizes the driver.
  2006-09-20 13:48 how an application program utilizes the driver Ming Liu
@ 2006-09-20 16:14 ` David Hawkins
  2006-09-20 16:30   ` Josh Boyer
  2006-09-21  8:13   ` Ming Liu
  2006-09-21 17:06 ` Eric Nuckols
  1 sibling, 2 replies; 5+ messages in thread
From: David Hawkins @ 2006-09-20 16:14 UTC (permalink / raw)
  To: Ming Liu; +Cc: linuxppc-embedded

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how an application program utilizes the driver.
  2006-09-20 16:14 ` David Hawkins
@ 2006-09-20 16:30   ` Josh Boyer
  2006-09-21  8:13   ` Ming Liu
  1 sibling, 0 replies; 5+ messages in thread
From: Josh Boyer @ 2006-09-20 16:30 UTC (permalink / raw)
  To: David Hawkins; +Cc: linuxppc-embedded

On Wed, 2006-09-20 at 09:14 -0700, David Hawkins wrote:
> 
> You really should read through Linux Device Drivers by Rubini,

Which is available here:

http://lwn.net/Kernel/LDD3/

josh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: how an application program utilizes the driver.
  2006-09-20 16:14 ` David Hawkins
  2006-09-20 16:30   ` Josh Boyer
@ 2006-09-21  8:13   ` Ming Liu
  1 sibling, 0 replies; 5+ messages in thread
From: Ming Liu @ 2006-09-21  8:13 UTC (permalink / raw)
  To: dwh, jdub; +Cc: linuxppc-embedded

Dear Dave and Josh,
Thanks so much for your suggestion first.

Yes, it looks that I am really a beginner and there are so many points I 
cannot understand well. So I will follow your suggestions and go through 
those material first...

In fact, I am reading LDD3 now. However, it seems that the book is mainly 
focused on the driver part and there is not some chapter to tell how apps 
work with drivers. So after a rough glance, I still have much confusion. :(

I will read more to understand this topic. Thanks for your help again.

Regards
Ming


>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
>
>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
>
>
>
>
>
>

_________________________________________________________________
享用世界上最大的电子邮件系统― MSN Hotmail。  http://www.hotmail.com  

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: how an application program utilizes the driver.
  2006-09-20 13:48 how an application program utilizes the driver Ming Liu
  2006-09-20 16:14 ` David Hawkins
@ 2006-09-21 17:06 ` Eric Nuckols
  1 sibling, 0 replies; 5+ messages in thread
From: Eric Nuckols @ 2006-09-21 17:06 UTC (permalink / raw)
  To: linuxppc-embedded

this probably isn't the level /topic to ask on the list, so I suggest 
reading the Linux Device Drivers book...

you'll want to access the device via ioctl() calls , but there has to be a 
little more involved to get to that point:

experiment with the scull device driver in this book

http://lwn.net/images/pdf/LDD3/ch06.pdf

----Original Message Follows----
From: "Ming Liu" <eemingliu@hotmail.com>
To: linuxppc-embedded@ozlabs.org
Subject: how an application program utilizes the driver.
Date: Wed, 20 Sep 2006 13:48:25 +0000

Dear all,
Maybe this question sounds stupid for most software engineers. But I really
have much confusion on this topic. So I have to ask for explanation.

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?

My driver is defined in drv_hello.c. I have compiled it into a module
drv_hello.ko and it could be insmoded or rmmoded correctly. It looks like:

//drv_hello.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("Dual BSD/GPL");

void show_hello(){
     printk("hello.\n");
}

static int hello_init(void){
     printk(KERN_ALERT "module starts.\n");
     return 0;
}

static void hello_exit(void){
     printk(KERN_ALERT "module exits.\n");
}

module_init(hello_init);
module_exit(hello_exit);

EXPORT_SYMBOL(show_hello);



In my application program app_hello.c, I use the function show_hello to
achieve the simple task: print "hello" on the console. Here is my app
program:

//app_hello.c
extern void show_hello();

int main(int argc, char** argv)
{
     show_hello();

     return 0;
}

Then, here comes my problem: I don't know how to compile my application
program and then it could dynamically refer to the function show_hello()
defined in the memory area of the driver module. How can I tell the
compiler and linker that the app program is expected to be linked with the
driver module dynamically? If possible, please give me a detailed
explanation.

Waiting for your suggestion. Thanks for your help.

Regards
Ming

_________________________________________________________________
ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà MSN Messenger:  http://messenger.msn.com/cn

_______________________________________________
Linuxppc-embedded mailing list
Linuxppc-embedded@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-embedded

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-09-21 17:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-20 13:48 how an application program utilizes the driver Ming Liu
2006-09-20 16:14 ` David Hawkins
2006-09-20 16:30   ` Josh Boyer
2006-09-21  8:13   ` Ming Liu
2006-09-21 17:06 ` Eric Nuckols

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).