public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] i2c bit-banging implementation
@ 2005-06-23  0:28 clifford.joseph
  2005-06-25 13:10 ` Bart Veer
  0 siblings, 1 reply; 4+ messages in thread
From: clifford.joseph @ 2005-06-23  0:28 UTC (permalink / raw)
  To: ecos-discuss

Hi

I am trying to implement an i2c transfer by bit-banging.

I have successfully added the hardware package CYGPKG_IO_I2C to my configuration file. (.ecc)

Iam working on the eb40a evaluation board which has already an i2c device at24c512 eeprom. 

I am using  arm-elf-gcc version 3.2.1

As described I have added this in  the plf_io.h

#define HAL_I2C_EXPORTED_DEVICES                    	          \
    extern cyg_i2c_bus                  cyg_i2c_xyzzy_bus;        \
    extern cyg_i2c_device               cyg_i2c_wallclock_ds1307; \
    extern cyg_i2c_device               cyg_i2c_eeprom;

and in the application  main.cpp file I have implemented the following function

static cyg_bool
hal_alaia_i2c_bitbang(cyg_i2c_bus* bus, cyg_i2c_bitbang_op op)
{
    cyg_bool result    = 0;
    
    switch(op) 
    {

        case CYG_I2C_BITBANG_INIT:
           {
            }
        case CYG_I2C_BITBANG_SCL_HIGH:
            {
            }
…..
…..
….
…..
.
    }
    return result;
}




This is the definition in the i2c.h file

typedef struct cyg_i2c_device {
    struct cyg_i2c_bus* i2c_bus;
    cyg_uint16          i2c_address;
    cyg_uint16          i2c_flags;
    cyg_uint32          i2c_delay;
} cyg_i2c_device;

#define CYG_I2C_DEFAULT_DELAY   10000

// A utility macro for defining an I2C device
#define CYG_I2C_DEVICE(_name_, _bus_, _address_, _flags_, _delay_)  \
    cyg_i2c_device _name_ = {                         	        \
        .i2c_bus        = _bus_,                            		        \
        .i2c_address    = _address_,                                        \
        .i2c_flags      = _flags_,                                                \
        .i2c_delay      = _delay_                                               \
    }

CYG_I2C_DEVICE(cyg_i2c_eeprom, &cyg_i2c_xyzzy_bus, 0xA0, 0x00,CYG_I2C_DEFAULT_DELAY);

It still returns the same error when I compile 

The error is

parse error before ‘.’ token

I am able create my own device without using the macro CYG_I2C_DEVICE by writing the code

extern cyg_i2c_device       cyg_i2c_eeprom;
    cyg_i2c_eeprom.i2c_bus     = &cyg_i2c_xyzzy_bus;
    cyg_i2c_eeprom.i2c_address = 0xA0;  //   10100000;
    cyg_i2c_eeprom.i2c_flags   = 0;
    cyg_i2c_eeprom.i2c_delay   = CYG_I2C_DEFAULT_DELAY;

but then i get an error at line..

   CYG_I2C_BITBANG_BUS( &cyg_i2c_xyzzy_bus, &hal_alaia_i2c_bitbang);
   
parse error before ‘.’ Token

looking at the i2c.h file the implementation of  macro

#define CYG_I2C_BUS(_name_, _init_fn_, _tx_fn_, _rx_fn_, _stop_fn_, _extra_)    \
    cyg_i2c_bus _name_  CYG_HAL_TABLE_ENTRY( i2c_buses ) = {                    \
        .i2c_init_fn    = _init_fn_,                                            \
        .i2c_tx_fn      = _tx_fn_,                                              \
        .i2c_rx_fn      = _rx_fn_,                                              \
        .i2c_stop_fn    = _stop_fn_,                                            \
        .i2c_extra      = _extra_                                               \
    }
Looking at the varios instances where the CYG_HAL_TABLE_ENTRY has been used in the other files

It has been implemented  in this way
Example:

 cyg_httpd_table_entry __name CYG_HAL_TABLE_ENTRY( httpd_table ) = { __pattern, __handler, __arg }

where __pattern, __handler, __arg are the arguments passed on to the httpd_table

Can somebody help me regarding this 

Has anybody been successful in implementing a bit-banging using the i2c package. 

Any idea why there is an error ? 

parse error before ‘.’ Token




--
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] i2c bit-banging implementation
  2005-06-23  0:28 [ECOS] i2c bit-banging implementation clifford.joseph
@ 2005-06-25 13:10 ` Bart Veer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Veer @ 2005-06-25 13:10 UTC (permalink / raw)
  To: clifford.joseph; +Cc: ecos-discuss

>>>>> " " ==   <clifford.joseph@clarinox.com> writes:

     > I am trying to implement an i2c transfer by bit-banging
     <snip>

     > It still returns the same error when I compile
     > The error is
     > parse error before ?.? token

     <snip>

     > Looking at the varios instances where the CYG_HAL_TABLE_ENTRY
     > has been used in the other files it has been implemented in
     > this way. Example:

     >  cyg_httpd_table_entry __name CYG_HAL_TABLE_ENTRY( httpd_table ) =
     >     { __pattern, __handler, __arg }

     > where __pattern, __handler, __arg are the arguments passed on to the httpd_table

     > Can somebody help me regarding this

     > Has anybody been successful in implementing a bit-banging using the i2c package

     > Any idea why there is an error ?

     > parse error before ?.? Token

Yes, there have been successful implementations of the bit-bang code.
In fact the first ever I2C driver used bit-banging.

There is no significant difference between the cyg_httpd_table_entry
macro and the I2C bus one. The latter uses a gcc extension called
Designated Initializers,
http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Designated-Inits.html#Designated%20Inits
The aim is to allow the cyg_i2c_bus structure to be changed in future,
including adding new fields at the start or in the middle of the
structure, without invalidating existing instances of the
CYG_I2C_BUS() macro.

Unfortunately it is not possible to tell from the error message
exactly what the problem is. To confuse things further I suspect the
original email has been garbled somewhere along the way.

I suggest you try compiling the source code in two steps. First use
gcc -E to just run the preprocessor on the file. Then compile the
resulting file normally. This should give you a line number for the
parse error, and a matching source file without the potentially
confusing macros.

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

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

* Re: [ECOS] i2c bit-banging implementation
@ 2005-07-14  2:13 clifford.joseph
  0 siblings, 0 replies; 4+ messages in thread
From: clifford.joseph @ 2005-07-14  2:13 UTC (permalink / raw)
  To: bartv; +Cc: ecos-discuss

Hi Bart 

I have successfully implemented the I2C bit-banging by writing the macros in C file.

I am able to communicate succesfully with the Eeprom on the eb40a board

Thank you 



--
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] i2c bit-banging implementation
  2005-07-01  5:10 clifford.joseph
@ 2005-07-02 16:10 ` Bart Veer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Veer @ 2005-07-02 16:10 UTC (permalink / raw)
  To: clifford.joseph; +Cc: ecos-discuss

>>>>> "Clifford" ==   <clifford.joseph@clarinox.com> writes:

    Clifford> Thank you for the reply
    Clifford> I am sending you the exact information printed after
    Clifford> compiling

    Clifford> L2CapDataClientMain=2Ecpp is where main() is

    Clifford> i have compiled the code with g++ -E -g

    Clifford> this is the message i get

    <snip>

As Andrew has already said, this is not exactly what I had in mind.

However I think I have now figured out what the problem is. The I2C
macros use the gcc designated inits language extension, and it turns
out that g++ does not implement this extension, This is a rather
unfortunate discrepancy, but may be inevitable because of the
differences in language syntax. If I try to instantiate an I2C bus or
device in C++ code I get errors like:

  i2c.cxx:154: error: expected primary-expression before '.' token

Not quite the error message you are seeing, but we may be using
different versions of the compiler.

The solution for now is to instantiate the I2C bus and devices in C
code instead of C++.

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

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

end of thread, other threads:[~2005-07-14  2:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-23  0:28 [ECOS] i2c bit-banging implementation clifford.joseph
2005-06-25 13:10 ` Bart Veer
2005-07-01  5:10 clifford.joseph
2005-07-02 16:10 ` Bart Veer
2005-07-14  2:13 clifford.joseph

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