diff -r -u5 -N -x CVS -x *~ -x .#* cvs/ecos/packages/io/i2c/current/ChangeLog work/ecos/packages/io/i2c/current/ChangeLog --- cvs/ecos/packages/io/i2c/current/ChangeLog Fri Jul 15 13:52:27 2005 +++ work/ecos/packages/io/i2c/current/ChangeLog Sun Oct 15 20:01:12 2006 @@ -1,5 +1,11 @@ +2006-10-15 Csordas, Peter + * src/i2c.cxx + * include/i2c.h : added function: + cyg_bool cyg_i2c_transfer_mode(cyg_i2c_device*, cyg_bool); + Interface for switching between polled and IT driven transfer + 2005-06-30 Bart Veer * src/i2c.cxx (cyg_i2c_init): remove incorrect const 2005-05-11 Bart Veer Binary files cvs/ecos/packages/io/i2c/current/doc/~$i2c.rtf and work/ecos/packages/io/i2c/current/doc/~$i2c.rtf differ diff -r -u5 -N -x CVS -x *~ -x .#* cvs/ecos/packages/io/i2c/current/include/i2c.h work/ecos/packages/io/i2c/current/include/i2c.h --- cvs/ecos/packages/io/i2c/current/include/i2c.h Sat May 14 09:31:03 2005 +++ work/ecos/packages/io/i2c/current/include/i2c.h Sun Oct 15 20:23:22 2006 @@ -64,10 +64,13 @@ cyg_uint16 i2c_address; cyg_uint16 i2c_flags; cyg_uint32 i2c_delay; } cyg_i2c_device; +//i2c_flags bitmasks +#define CYG_I2C_POLLED_MODE 1 + #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_ = { \ @@ -111,10 +114,11 @@ // simple transmits and receives, and transaction-oriented routines // for more complicated operations including those involving repeated // starts. externC cyg_uint32 cyg_i2c_tx(const cyg_i2c_device*, const cyg_uint8*, cyg_uint32); externC cyg_uint32 cyg_i2c_rx(const cyg_i2c_device*, cyg_uint8*, cyg_uint32); +externC cyg_bool cyg_i2c_transfer_mode(cyg_i2c_device*, cyg_bool); externC void cyg_i2c_transaction_begin(const cyg_i2c_device*); externC cyg_bool cyg_i2c_transaction_begin_nb(const cyg_i2c_device*); externC cyg_uint32 cyg_i2c_transaction_tx(const cyg_i2c_device*, cyg_bool, const cyg_uint8*, cyg_uint32, cyg_bool); externC cyg_uint32 cyg_i2c_transaction_rx(const cyg_i2c_device*, cyg_bool, cyg_uint8*, cyg_uint32, cyg_bool, cyg_bool); externC void cyg_i2c_transaction_stop(const cyg_i2c_device*); diff -r -u5 -N -x CVS -x *~ -x .#* cvs/ecos/packages/io/i2c/current/src/i2c.cxx work/ecos/packages/io/i2c/current/src/i2c.cxx --- cvs/ecos/packages/io/i2c/current/src/i2c.cxx Fri Jul 15 13:52:27 2005 +++ work/ecos/packages/io/i2c/current/src/i2c.cxx Sun Oct 15 20:11:02 2006 @@ -124,17 +124,35 @@ result = cyg_i2c_transaction_rx(dev, true, buf, count, true, true); cyg_i2c_transaction_end(dev); return result; } +//Chose transaction method: polled or IT driven +// Handles the CYG_I2C_POLLED_MODE bit of i2c_flags, that should be checked in the implemented bus functions +extern "C" cyg_bool +cyg_i2c_transfer_mode(cyg_i2c_device* dev, cyg_bool polled) +{ + //Do not change transaction mode during transfer + //(we do not know, whether current or other divece is transfering, but we can afford this...) + if (cyg_drv_mutex_trylock(&(dev->i2c_bus->i2c_lock))) + { + if(polled) dev->i2c_flags=(dev->i2c_flags)|CYG_I2C_POLLED_MODE; + else dev->i2c_flags=(dev->i2c_flags)&(~CYG_I2C_POLLED_MODE); + cyg_drv_mutex_unlock(&(dev->i2c_bus->i2c_lock)); + return(true); + } + return false; +} + + // Transaction begin/end relate to the per-bus locking. There does not // seem to be any need to interact with the hardware at this point. extern "C" void cyg_i2c_transaction_begin(const cyg_i2c_device* dev) { cyg_i2c_bus* bus; - + CYG_CHECK_DATA_PTR(dev, "valid I2C device pointer required"); bus = dev->i2c_bus; CYG_CHECK_DATA_PTR(bus, "I2C device does not point at a valid bus structure"); while (! cyg_drv_mutex_lock(&(bus->i2c_lock)));