This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: device driver enquirey
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