This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: i2c driver complie error


>>>>> "liu" == liu hua <rongye_liu@hotmail.com> writes:

    liu> I need help for i2c driver.
    liu> In my project,I use the PCA9564 (I2C bus controller). So,I
    liu> will write a driver for PCA9564. I download the I2C driver
    liu> code from eCos CVS server,and write a test driver
    liu> i2c_pca9564.c. This driver use the code from I2C doc file.
    liu> But,when I complie the eCos with configtool,there are some
    liu> compile error:

There were a number of problems with that documentation, caused by
excessive cutting and pasting. These have now been fixed. Then you
introduced a few more problems in your code:

    <snip>

    liu> #define HAL_I2C_EXPORTED_DEVICES                                   \
    liu> extern cyg_i2c_bus                  cyg_i2c_xyzzy_bus;          \
    liu> extern cyg_i2c_device               cyg_i2c_wallclock_ds1307;   \
    liu> extern cyg_i2c_device               hal_alaia_i2c_fs6377;

This should go into a platform HAL header file, usually plf_io.h, not
in your driver sources. An I2C bus device driver does not know what
devices are attached to the bus, that is a characteristic of the
platform.

    liu> struct xyzzy_data {
    liu> 	int test;
    liu> } *xyzzy_object;

    liu> static cyg_bool
    liu> xyzzy_i2c_extra(cyg_i2c_bus* bus)
    liu> {
    liu>     cyg_bool result    = 0;

    liu>     return result;
    liu> }

The driver's extra field can be a pointer to a function if that is
appropriate, but more commonly it will be a pointer to a data
structure (i.e. a struct xyzzy_data) holding driver-specific
information. If the driver does not need any such data, e.g. because
all the state is held in statics, then a NULL pointer can be used.

    liu> static cyg_uint32
    liu> xyzzy_i2c_tx(const cyg_i2c_device* dev,
    liu>              cyg_bool send_start,
    liu>               cyg_uint8* tx_data, cyg_uint32 count,
    liu>              cyg_bool send_stop)
    liu> {
    liu>   	printf("tx t2c xyzzy...\n");
  
    liu> }

The documentation used the wrong prototype. It should be:

    static cyg_uint32
    xyzzy_i2c_tx(const cyg_i2c_device* dev,
                 cyg_bool send_start,
                 const cyg_uint8* tx_data, cyg_uint32 count,
                 cyg_bool send_stop)
    {
      	printf("tx t2c xyzzy...\n");
    }

    liu> static cyg_uint32
    liu> xyzzy_i2c_rx(const cyg_i2c_device* dev,
    liu>              cyg_bool send_start,
    liu>               cyg_uint8* tx_data, cyg_uint32 count,
    liu>              cyg_bool send_stop)
    liu> {
    liu>   	printf("rx i2c xyzzy...\n");
    liu> }

Again the prototype was wrong. It should be:

    static cyg_uint32
    xyzzy_i2c_rx(const cyg_i2c_device* dev,
                 cyg_bool send_start,
                 cyg_uint8* rx_data, cyg_uint32 count,
                 cyg_bool send_nack, cyg_bool send_stop)
    {
       	printf("rx i2c xyzzy...\n");
    }

    liu> CYG_I2C_BUS(cyg_i2c_xyzzy_bus,
    liu>             xyzzy_i2c_init,
    liu>             xyzzy_i2c_tx,
    liu>             xyzzy_i2c_rx,
    liu>             xyzzy_i2c_stop,
    liu>             (void *) xyzzy_i2c_extra);

Although optional, these should really be &xyzzy_i2c_init,
&xyzzy_i2c_tx, etc.
            
    liu> CYG_I2C_DEVICE( cyg_i2c_wallclock_ds1307,            
    liu>                 cyg_i2c_xyzzy_bus,                  
    liu>                0x68,                                
    liu>                0x00,                                
    liu>                CYG_I2C_DEFAULT_DELAY);

    liu> CYG_I2C_DEVICE(hal_alaia_i2c_fs6377,                
    liu>                cyg_i2c_xyzzy_bus,                  
    liu>                0x58,                                
    liu>                0x00,                                
    liu>                CYG_I2C_DEFAULT_DELAY);

Both device instantiations need to use &cyg_i2c_xyzzy_bus. Devices are
normally instantiated in the platform HAL, not in a bus device driver,
since only the platform knows what devices are attached to the bus.

Bart

-- 
Bart Veer                       eCos Configuration Architect
http://www.ecoscentric.com/     The eCos and RedBoot experts


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]