public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] device driver enquirey - c label
@ 2006-12-16  8:38 Yi Tang
  2006-12-16 19:20 ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Yi Tang @ 2006-12-16  8:38 UTC (permalink / raw)
  To: ecos-discuss

Hello,

It's the first time for me to write a device driver. I have got a simple, 
silly question, hope someone in this group can instruct me.

In the eCos reference, I found that there is one item in nearly all io 
functions, the "C label".

like this one:

DEVTAB_ENTRY(l, name, dep_name, handlers, init, lookup, priv)

l: The "C" label for this entry.

also can be found in DEVIO_TABLE and other functions.

Can anyone tell me what it is used for and which element I should assign it 
to?

Regards,
Tony 



-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

* Re: [ECOS] device driver enquirey - c label
  2006-12-16  8:38 [ECOS] device driver enquirey - c label Yi Tang
@ 2006-12-16 19:20 ` Andrew Lunn
  2006-12-17 14:38   ` [ECOS] device driver enquirey Yi Tang
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2006-12-16 19:20 UTC (permalink / raw)
  To: Yi Tang; +Cc: ecos-discuss

On Sat, Dec 16, 2006 at 06:37:57PM +1000, Yi Tang wrote:
> Hello,
> 
> It's the first time for me to write a device driver. I have got a simple, 
> silly question, hope someone in this group can instruct me.
> 
> In the eCos reference, I found that there is one item in nearly all io 
> functions, the "C label".
> 
> like this one:
> 
> DEVTAB_ENTRY(l, name, dep_name, handlers, init, lookup, priv)
> 
> l: The "C" label for this entry.
> 
> also can be found in DEVIO_TABLE and other functions.

It is used to tell eCos about devices. You don't need to assign it to
anything. It causes an entry to be placed into the list of device.

          Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

* Re: [ECOS] device driver enquirey
  2006-12-16 19:20 ` Andrew Lunn
@ 2006-12-17 14:38   ` Yi Tang
  2006-12-17 16:50     ` Andrew Lunn
  0 siblings, 1 reply; 4+ messages in thread
From: Yi Tang @ 2006-12-17 14:38 UTC (permalink / raw)
  To: ecos-discuss

Hi,

I still don't understand the routine for ecos to find the specific I/O 
functions simply using handlers and cyg_io_xxx functions.

Some examples use the cyg_io_lookup fuctions to pass the device info to 
"handle", like this:
    err = cyg_io_lookup( "/dev/serial", &handle );

but where the device info of this lookup function comes from. Through the 
definition of DEVTAB_ENTRY?

Following is my test driver for a gpio, I use cyg_io_lookup function to get 
the correct "handle", but Cyg_ErrNo returns -2, no entitiy found. Hope you 
can instruct me if anything wrong in my code.

Thanks a lot

Regards,
Tony

--------------------------------------------------------------
#include <stdio.h>
#include <cyg/io/devtab.h>
#include <cyg/io/io.h>
#include <cyg/hal/drv_api.h>
#include "gpio.h"

static int mask;
int *gpio_reg = (int *) GPIO_ADDR;
cyg_devio_table_t cyg_io_gpio_devio;

Cyg_ErrNo gpio_write(cyg_io_handle_t handle, const void *buf, cyg_uint32 
*len);
Cyg_ErrNo gpio_read(cyg_io_handle_t handle, void *buf, cyg_uint32 *len);
cyg_bool gpio_select(cyg_io_handle_t handle, cyg_uint32 imask, CYG_ADDRWORD 
info);
Cyg_ErrNo gpio_get_config(cyg_io_handle_t handle, cyg_uint32 key, void *buf, 
cyg_uint32 *len);
Cyg_ErrNo gpio_set_config(cyg_io_handle_t handle, cyg_uint32 key, const void 
*buf, cyg_uint32 *len);

DEVTAB_ENTRY(gpio_entry,
             "/dev/gpio",
             0,                     // Does not depend on a lower level 
interface
             &cyg_io_gpio_devio,
             0,
             0,                     // No initialization/lookup needed
    0);

DEVIO_TABLE(cyg_io_gpio_devio,
            gpio_write,
            gpio_read,
            gpio_select,
            gpio_get_config,
            gpio_set_config
    );

static Cyg_ErrNo gpio_write(cyg_io_handle_t handle, const void *buf, 
cyg_uint32 *len)
{
 gpio_reg[GPIO_OUT/4] = *(cyg_uint32*)buf & mask;
 return(ENOERR);
}

static Cyg_ErrNo gpio_read(cyg_io_handle_t handle, void *buf, cyg_uint32 
*len)
{
 cyg_uint32 *tmp;
 *tmp = gpio_reg[GPIO_OUT/4] & mask;
 buf = tmp;
 return(ENOERR);
}

/* software mask for GPIO , if set '0', the bit is enalbed for I/O, if set 
'1', it's masked for I/O, default is 0, all I/O enabled */
static cyg_bool gpio_select(cyg_io_handle_t handle, cyg_uint32 which, 
CYG_ADDRWORD info)
{
 mask = - which;
 return(ENOERR);
}

static Cyg_ErrNo gpio_get_config(cyg_io_handle_t handle, cyg_uint32 key, 
void *buf, cyg_uint32 *len)
{
 switch (key) {
  case GPIO_DIR_INFO:
   *(cyg_uint32*)buf = gpio_reg[GPIO_DIR/4];
   break;
  case GPIO_IMASK_INFO:
   *(cyg_uint32*)buf = gpio_reg[GPIO_IMASK/4];
   break;
  case GPIO_POLAR_INFO:
   *(cyg_uint32*)buf = gpio_reg[GPIO_POLAR/4];
   break;
  case GPIO_EDGE_INFO:
   *(cyg_uint32*)buf = gpio_reg[GPIO_EDGE/4];
   break;
  default:
   return(ENOENT);
 }
 return (ENOERR);
}


static Cyg_ErrNo gpio_set_config(cyg_io_handle_t handle, cyg_uint32 key, 
const void *buf, cyg_uint32 *len)
{
 switch (key) {
  case GPIO_DIR_INFO:
   gpio_reg[GPIO_DIR/4] = *(cyg_uint32*)buf;
   break;
  case GPIO_IMASK_INFO:
   gpio_reg[GPIO_IMASK/4] = *(cyg_uint32*)buf;
   break;
  case GPIO_POLAR_INFO:
   gpio_reg[GPIO_POLAR/4] = *(cyg_uint32*)buf;
   break;
  case GPIO_EDGE_INFO:
   gpio_reg[GPIO_EDGE/4] = *(cyg_uint32*)buf;
   break;
  default:
   return(ENOENT);
 }
 return (ENOERR);
}
/* EOF of gpio.c */



-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

* Re: [ECOS] device driver enquirey
  2006-12-17 14:38   ` [ECOS] device driver enquirey Yi Tang
@ 2006-12-17 16:50     ` Andrew Lunn
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2006-12-17 16:50 UTC (permalink / raw)
  To: Yi Tang; +Cc: ecos-discuss

On Mon, Dec 18, 2006 at 12:38:33AM +1000, Yi Tang wrote:
> Hi,
> 
> I still don't understand the routine for ecos to find the specific I/O 
> functions simply using handlers and cyg_io_xxx functions.
> 
> Some examples use the cyg_io_lookup fuctions to pass the device info to 
> "handle", like this:
>    err = cyg_io_lookup( "/dev/serial", &handle );
> 
> but where the device info of this lookup function comes from. Through the 
> definition of DEVTAB_ENTRY?
> 
> Following is my test driver for a gpio, I use cyg_io_lookup function to get 
> the correct "handle", but Cyg_ErrNo returns -2, no entitiy found. Hope you 
> can instruct me if anything wrong in my code.

Do you have this as a package inside the eCos build tree?

If so, you need to specify that the gpio.o object file is placed into
libextra.a. In your CDL file you need something like:

compile         -library=libextras.a gpio.c

The problem is that none of the functions in gpio.c are referenced by
name. So the linker thinks they are not needed and throws them
away. Object files in libextra the linker is not allowed to throw
away.

You can see what symbols are in your executable with eg:

arm-elf-nm test

where test is the elf executable. Change arm- to what ever, eg ppc-,
mips-, ...

        Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

end of thread, other threads:[~2006-12-17 16:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-16  8:38 [ECOS] device driver enquirey - c label Yi Tang
2006-12-16 19:20 ` Andrew Lunn
2006-12-17 14:38   ` [ECOS] device driver enquirey Yi Tang
2006-12-17 16:50     ` Andrew Lunn

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 read-only IMAP folder(s) and NNTP newsgroup(s).