Add I2C frequency to the i2c_msg_s structure

This commit is contained in:
Gregory Nutt 2016-02-01 14:17:20 -06:00
parent f9053182d3
commit 6ad641888b
21 changed files with 308 additions and 252 deletions

View File

@ -11429,3 +11429,9 @@
board with NXP LPCExpresso LPC1768. The GSM module is one of LISA-C200, board with NXP LPCExpresso LPC1768. The GSM module is one of LISA-C200,
LISA-U200 or SARA-G350. The GPS module is one of MAX-M7 or MAX-M8. From LISA-U200 or SARA-G350. The GPS module is one of MAX-M7 or MAX-M8. From
Vladimir Komendantskiy (2016-01-31). Vladimir Komendantskiy (2016-01-31).
* drivers/, arch/, include/, numerous files: May restructuring of the I2C
interface necessary to eliminate some thread-safety issues inherent in
the legacy I2C interface design. This effects the interface definition,
all I2C clients, and all low-level I2C drivers. I have used caution,
but I still expect a change of this magnitude to introduce some errors.
Any bug reports of bug fixes will be much appreciated (2016-02-01).

@ -1 +1 @@
Subproject commit 4d7a2777081a9773029829531c12b18059fd71e8 Subproject commit 7d40326c7f8ca77993caaa7bb940e3ae2a631f9d

12
TODO
View File

@ -1614,18 +1614,14 @@ o Other drivers (drivers/)
in a multi-tasking I2C environment: in a multi-tasking I2C environment:
- I2C_SETFREQUENCY: Frequency setting can be overwritten by other - I2C_SETFREQUENCY: Frequency setting can be overwritten by other
I2C usage. I2C usage.
- I2C_SETADDRESS: The I2C address can and will be changed by other - I2C_TRANSFER: This interface is almost self but even can suffer
I2C usage. NOTE also that I2C_SETADDRESS also sets the address width if there are differing frequency settings.
(either 7 or 10 bits).
- I2C_TRANSFER: This is the only interface that is properly self
contained and protected from most mult-tasking issues. But even
this interface can suffer if there are differing frequency settings.
Status: Open Status: Open
Priority: Medium-High. The fix is easy but effects a lot of software. There Priority: Medium-High. The fix is easy but effects a lot of software. There
are two ways to fix theses problems: (1) Add a locking method such are two ways to fix theses problems: (1) Add a locking method such
as is provided with the SPI interface, or (2) make each interface as is provided with the SPI interface, or (2) make each interface
self-contained and atomic: Remove the I2C_FREQUENCY and I2C_ADDRESS self-contained and atomic: Remove the I2C_FREQUENCY and add
methods; Add frequency to the I2C_TRANSFER message structure. frequency to the I2C_TRANSFER message structure.
o Linux/Cywgin simulation (arch/sim) o Linux/Cywgin simulation (arch/sim)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2
arch

@ -1 +1 @@
Subproject commit 490bbe2d7b5b67ff7efc052abb2e2071ff0aac5c Subproject commit 18c2083af2a73f710e2777c42ccd7ca8ae4096bf

@ -1 +1 @@
Subproject commit 7286dea76c9a19895a14d02b593c4c6356461a9d Subproject commit 588811152643ca752381a52ec57986c0c4b1a376

View File

@ -266,6 +266,7 @@ uint16_t wm8904_readreg(FAR struct wm8904_dev_s *priv, uint8_t regaddr)
/* Set up to write the address */ /* Set up to write the address */
msg[0].frequency = priv->lower->frequency;
msg[0].addr = priv->lower->address; msg[0].addr = priv->lower->address;
msg[0].flags = 0; msg[0].flags = 0;
msg[0].buffer = &regaddr; msg[0].buffer = &regaddr;
@ -273,6 +274,7 @@ uint16_t wm8904_readreg(FAR struct wm8904_dev_s *priv, uint8_t regaddr)
/* Followed by the read data */ /* Followed by the read data */
msg[1].frequency = priv->lower->frequency;
msg[1].addr = priv->lower->address; msg[1].addr = priv->lower->address;
msg[1].flags = I2C_M_READ; msg[1].flags = I2C_M_READ;
msg[1].buffer = data; msg[1].buffer = data;

View File

@ -79,16 +79,13 @@ int i2c_read(FAR struct i2c_master_s *dev,
/* Setup for the transfer */ /* Setup for the transfer */
msg.frequency = config->frequency,
msg.addr = config->address, msg.addr = config->address,
msg.flags = (flags | I2C_M_READ); msg.flags = (flags | I2C_M_READ);
msg.buffer = buffer; msg.buffer = buffer;
msg.length = buflen; msg.length = buflen;
/* Then perform the transfer /* Then perform the transfer. */
*
* REVISIT: The following two operations must become atomic in order to
* assure thread safety.
*/
I2C_SETFREQUENCY(dev, config->frequency); I2C_SETFREQUENCY(dev, config->frequency);
return I2C_TRANSFER(dev, &msg, 1); return I2C_TRANSFER(dev, &msg, 1);

View File

@ -74,16 +74,13 @@ int i2c_write(FAR struct i2c_master_s *dev,
/* Setup for the transfer */ /* Setup for the transfer */
msg.frequency = config->frequency,
msg.addr = config->address; msg.addr = config->address;
msg.flags = (config->addrlen == 10) ? I2C_M_TEN : 0; msg.flags = (config->addrlen == 10) ? I2C_M_TEN : 0;
msg.buffer = (FAR uint8_t *)buffer; /* Override const */ msg.buffer = (FAR uint8_t *)buffer; /* Override const */
msg.length = buflen; msg.length = buflen;
/* Then perform the transfer /* Then perform the transfer. */
*
* REVISIT: The following two operations must become atomic in order to
* assure thread safety.
*/
I2C_SETFREQUENCY(dev, config->frequency); I2C_SETFREQUENCY(dev, config->frequency);
return I2C_TRANSFER(dev, &msg, 1); return I2C_TRANSFER(dev, &msg, 1);

View File

@ -82,6 +82,7 @@ int i2c_writeread(FAR struct i2c_master_s *dev,
/* Format two messages: The first is a write */ /* Format two messages: The first is a write */
msg[0].frequency = config->frequency,
msg[0].addr = config->address; msg[0].addr = config->address;
msg[0].flags = flags; msg[0].flags = flags;
msg[0].buffer = (FAR uint8_t *)wbuffer; /* Override const */ msg[0].buffer = (FAR uint8_t *)wbuffer; /* Override const */
@ -101,15 +102,12 @@ int i2c_writeread(FAR struct i2c_master_s *dev,
rbuflen = -rbuflen; rbuflen = -rbuflen;
} }
msg[1].frequency = config->frequency,
msg[1].addr = config->address; msg[1].addr = config->address;
msg[1].buffer = rbuffer; msg[1].buffer = rbuffer;
msg[1].length = rbuflen; msg[1].length = rbuflen;
/* Then perform the transfer /* Then perform the transfer. */
*
* REVISIT: The following two operations must become atomic in order to
* assure thread safety.
*/
I2C_SETFREQUENCY(dev, config->frequency); I2C_SETFREQUENCY(dev, config->frequency);
return I2C_TRANSFER(dev, msg, 2); return I2C_TRANSFER(dev, msg, 2);

View File

@ -318,6 +318,7 @@ static int mxt_getreg(FAR struct mxt_dev_s *priv, uint16_t regaddr,
addrbuf[0] = regaddr & 0xff; addrbuf[0] = regaddr & 0xff;
addrbuf[1] = (regaddr >> 8) & 0xff; addrbuf[1] = (regaddr >> 8) & 0xff;
msg[0].frequency = priv->frequency;
msg[0].addr = priv->lower->address; msg[0].addr = priv->lower->address;
msg[0].flags = 0; msg[0].flags = 0;
msg[0].buffer = addrbuf; msg[0].buffer = addrbuf;
@ -325,6 +326,7 @@ static int mxt_getreg(FAR struct mxt_dev_s *priv, uint16_t regaddr,
/* Followed by the read data */ /* Followed by the read data */
msg[1].frequency = priv->frequency;
msg[1].addr = priv->lower->address; msg[1].addr = priv->lower->address;
msg[1].flags = I2C_M_READ; msg[1].flags = I2C_M_READ;
msg[1].buffer = buffer; msg[1].buffer = buffer;
@ -390,6 +392,7 @@ static int mxt_putreg(FAR struct mxt_dev_s *priv, uint16_t regaddr,
addrbuf[0] = regaddr & 0xff; addrbuf[0] = regaddr & 0xff;
addrbuf[1] = (regaddr >> 8) & 0xff; addrbuf[1] = (regaddr >> 8) & 0xff;
msg[0].frequency = priv->frequency;
msg[0].addr = priv->lower->address; msg[0].addr = priv->lower->address;
msg[0].flags = 0; msg[0].flags = 0;
msg[0].buffer = addrbuf; msg[0].buffer = addrbuf;
@ -397,6 +400,7 @@ static int mxt_putreg(FAR struct mxt_dev_s *priv, uint16_t regaddr,
/* Followed by the write data (with no repeated start) */ /* Followed by the write data (with no repeated start) */
msg[1].frequency = priv->frequency;
msg[1].addr = priv->lower->address; msg[1].addr = priv->lower->address;
msg[1].flags = I2C_M_NORESTART; msg[1].flags = I2C_M_NORESTART;
msg[1].buffer = (FAR uint8_t *)buffer; msg[1].buffer = (FAR uint8_t *)buffer;
@ -1511,7 +1515,9 @@ static int mxt_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{ {
FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg); FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg);
DEBUGASSERT(priv->lower != NULL && ptr != NULL); DEBUGASSERT(priv->lower != NULL && ptr != NULL);
priv->frequency = I2C_SETFREQUENCY(priv->i2c, *ptr);
priv->frequency = *ptr;
(void)I2C_SETFREQUENCY(priv->i2c, *ptr);
} }
break; break;
@ -1734,7 +1740,8 @@ static int mxt_hwinitialize(FAR struct mxt_dev_s *priv)
/* Set the selected I2C frequency */ /* Set the selected I2C frequency */
priv->frequency = I2C_SETFREQUENCY(priv->i2c, priv->lower->frequency); priv->frequency = priv->lower->frequency;
(void)I2C_SETFREQUENCY(priv->i2c, priv->lower->frequency);
/* Read the info registers from the device */ /* Read the info registers from the device */

View File

@ -408,6 +408,7 @@ uint8_t stmpe811_getreg8(FAR struct stmpe811_dev_s *priv, uint8_t regaddr)
/* Setup 8-bit STMPE811 address write message */ /* Setup 8-bit STMPE811 address write message */
msg[0].frequency = priv->config->frequency; /* I2C frequency */
msg[0].addr = priv->config->address; /* 7-bit address */ msg[0].addr = priv->config->address; /* 7-bit address */
msg[0].flags = 0; /* Write transaction, beginning with START */ msg[0].flags = 0; /* Write transaction, beginning with START */
msg[0].buffer = &regaddr; /* Transfer from this address */ msg[0].buffer = &regaddr; /* Transfer from this address */
@ -416,6 +417,7 @@ uint8_t stmpe811_getreg8(FAR struct stmpe811_dev_s *priv, uint8_t regaddr)
/* Set up the 8-bit STMPE811 data read message */ /* Set up the 8-bit STMPE811 data read message */
msg[1].frequency = priv->config->frequency; /* I2C frequency */
msg[1].addr = priv->config->address; /* 7-bit address */ msg[1].addr = priv->config->address; /* 7-bit address */
msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */
msg[1].buffer = &regval; /* Transfer to this address */ msg[1].buffer = &regval; /* Transfer to this address */
@ -472,6 +474,7 @@ void stmpe811_putreg8(FAR struct stmpe811_dev_s *priv,
/* Setup 8-bit STMPE811 address write message */ /* Setup 8-bit STMPE811 address write message */
msg.frequency = priv->config->frequency; /* I2C frequency */
msg.addr = priv->config->address; /* 7-bit address */ msg.addr = priv->config->address; /* 7-bit address */
msg.flags = 0; /* Write transaction, beginning with START */ msg.flags = 0; /* Write transaction, beginning with START */
msg.buffer = txbuffer; /* Transfer from this address */ msg.buffer = txbuffer; /* Transfer from this address */
@ -513,6 +516,7 @@ uint16_t stmpe811_getreg16(FAR struct stmpe811_dev_s *priv, uint8_t regaddr)
/* Setup 8-bit STMPE811 address write message */ /* Setup 8-bit STMPE811 address write message */
msg[0].frequency = priv->config->frequency; /* I2C frequency */
msg[0].addr = priv->config->address; /* 7-bit address */ msg[0].addr = priv->config->address; /* 7-bit address */
msg[0].flags = 0; /* Write transaction, beginning with START */ msg[0].flags = 0; /* Write transaction, beginning with START */
msg[0].buffer = &regaddr; /* Transfer from this address */ msg[0].buffer = &regaddr; /* Transfer from this address */
@ -521,6 +525,7 @@ uint16_t stmpe811_getreg16(FAR struct stmpe811_dev_s *priv, uint8_t regaddr)
/* Set up the 8-bit STMPE811 data read message */ /* Set up the 8-bit STMPE811 data read message */
msg[1].frequency = priv->config->frequency; /* I2C frequency */
msg[1].addr = priv->config->address; /* 7-bit address */ msg[1].addr = priv->config->address; /* 7-bit address */
msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */
msg[1].buffer = rxbuffer; /* Transfer to this address */ msg[1].buffer = rxbuffer; /* Transfer to this address */

View File

@ -432,6 +432,7 @@ static int tsc2007_activate(FAR struct tsc2007_dev_s *priv, uint8_t cmd)
data = TSC2007_SETUP; data = TSC2007_SETUP;
msg.frequency = priv->config->frequency; /* I2C frequency */
msg.addr = priv->config->address; /* 7-bit address */ msg.addr = priv->config->address; /* 7-bit address */
msg.flags = 0; /* Write transaction, beginning with START */ msg.flags = 0; /* Write transaction, beginning with START */
msg.buffer = &data; /* Transfer from this address */ msg.buffer = &data; /* Transfer from this address */
@ -445,6 +446,7 @@ static int tsc2007_activate(FAR struct tsc2007_dev_s *priv, uint8_t cmd)
data = cmd; data = cmd;
msg.frequency = priv->config->frequency; /* I2C frequency */
msg.addr = priv->config->address; /* 7-bit address */ msg.addr = priv->config->address; /* 7-bit address */
msg.flags = 0; /* Write transaction, beginning with START */ msg.flags = 0; /* Write transaction, beginning with START */
msg.buffer = &data; /* Transfer from this address */ msg.buffer = &data; /* Transfer from this address */
@ -483,6 +485,7 @@ static int tsc2007_transfer(FAR struct tsc2007_dev_s *priv, uint8_t cmd)
* STOP condition... * STOP condition...
*/ */
msg.frequency = priv->config->frequency; /* I2C frequency */
msg.addr = priv->config->address; /* 7-bit address */ msg.addr = priv->config->address; /* 7-bit address */
msg.flags = 0; /* Write transaction, beginning with START */ msg.flags = 0; /* Write transaction, beginning with START */
msg.buffer = &cmd; /* Transfer from this address */ msg.buffer = &cmd; /* Transfer from this address */
@ -527,6 +530,7 @@ static int tsc2007_transfer(FAR struct tsc2007_dev_s *priv, uint8_t cmd)
* data byte has been received... * data byte has been received...
*/ */
msg.frequency = priv->config->frequency; /* I2C frequency */
msg.addr = priv->config->address; /* 7-bit address */ msg.addr = priv->config->address; /* 7-bit address */
msg.flags = I2C_M_READ; /* Read transaction, beginning with START */ msg.flags = I2C_M_READ; /* Read transaction, beginning with START */
msg.buffer = data12; /* Transfer to this address */ msg.buffer = data12; /* Transfer to this address */
@ -1068,7 +1072,8 @@ static int tsc2007_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{ {
FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg); FAR uint32_t *ptr = (FAR uint32_t *)((uintptr_t)arg);
DEBUGASSERT(priv->config != NULL && ptr != NULL); DEBUGASSERT(priv->config != NULL && ptr != NULL);
priv->config->frequency = I2C_SETFREQUENCY(priv->i2c, *ptr); priv->config->frequency = *ptr;
(void)I2C_SETFREQUENCY(priv->i2c, *ptr);
} }
break; break;

View File

@ -82,6 +82,7 @@ void ssd1306_sendbyte(FAR struct ssd1306_dev_s *priv, uint8_t regval)
/* Setup 8-bit SSD1306 address write message */ /* Setup 8-bit SSD1306 address write message */
msg.frequency = CONFIG_SSD1306_I2CFREQ; /* I2C frequency */
msg.addr = priv->addr; /* 7-bit address */ msg.addr = priv->addr; /* 7-bit address */
msg.flags = 0; /* Write transaction, beginning with START */ msg.flags = 0; /* Write transaction, beginning with START */
msg.buffer = txbuffer; /* Transfer from this address */ msg.buffer = txbuffer; /* Transfer from this address */
@ -117,6 +118,7 @@ void ssd1306_sendblk(FAR struct ssd1306_dev_s *priv, uint8_t *data, uint8_t len)
/* Setup 8-bit SSD1306 address write message */ /* Setup 8-bit SSD1306 address write message */
msg.frequency = CONFIG_SSD1306_I2CFREQ; /* I2C frequency */
msg.addr = priv->addr; /* 7-bit address */ msg.addr = priv->addr; /* 7-bit address */
msg.flags = 0; /* Write transaction, beginning with START */ msg.flags = 0; /* Write transaction, beginning with START */
msg.buffer = data; /* Transfer from this address */ msg.buffer = data; /* Transfer from this address */

View File

@ -22,7 +22,12 @@ config LIS331DL
bool "ST LIS331DL device support" bool "ST LIS331DL device support"
default n default n
select I2C select I2C
select I2C_TRANSFER
config LIS331DL_I2C_FREQUENCY
bool "LIS331DL I2C frequency"
default 100000
range 1 100000
depends on LIS331DL
config SN_LSM9DS1 config SN_LSM9DS1
bool "STMicro LSM9DS1 support" bool "STMicro LSM9DS1 support"

View File

@ -76,6 +76,7 @@ uint8_t adxl345_getreg8(FAR struct adxl345_dev_s *priv, uint8_t regaddr)
/* Setup 8-bit ADXL345 address write message */ /* Setup 8-bit ADXL345 address write message */
msg[0].frequency = priv->config->frequency; /* I2C frequency */
msg[0].addr = priv->config->address; /* 7-bit address */ msg[0].addr = priv->config->address; /* 7-bit address */
msg[0].flags = 0; /* Write transaction, beginning with START */ msg[0].flags = 0; /* Write transaction, beginning with START */
msg[0].buffer = &regaddr; /* Transfer from this address */ msg[0].buffer = &regaddr; /* Transfer from this address */
@ -84,6 +85,7 @@ uint8_t adxl345_getreg8(FAR struct adxl345_dev_s *priv, uint8_t regaddr)
/* Set up the 8-bit ADXL345 data read message */ /* Set up the 8-bit ADXL345 data read message */
msg[1].frequency = priv->config->frequency; /* I2C frequency */
msg[1].addr = priv->config->address; /* 7-bit address */ msg[1].addr = priv->config->address; /* 7-bit address */
msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */
msg[1].buffer = &regval; /* Transfer to this address */ msg[1].buffer = &regval; /* Transfer to this address */
@ -140,6 +142,7 @@ void adxl345_putreg8(FAR struct adxl345_dev_s *priv,
/* Setup 8-bit ADXL345 address write message */ /* Setup 8-bit ADXL345 address write message */
msg.frequency = priv->config->frequency; /* I2C frequency */
msg.addr = priv->config->address; /* 7-bit address */ msg.addr = priv->config->address; /* 7-bit address */
msg.flags = 0; /* Write transaction, beginning with START */ msg.flags = 0; /* Write transaction, beginning with START */
msg.buffer = txbuffer; /* Transfer from this address */ msg.buffer = txbuffer; /* Transfer from this address */
@ -180,6 +183,7 @@ uint16_t adxl345_getreg16(FAR struct adxl345_dev_s *priv, uint8_t regaddr)
/* Setup 8-bit ADXL345 address write message */ /* Setup 8-bit ADXL345 address write message */
msg[0].frequency = priv->config->frequency; /* I2C frequency */
msg[0].addr = priv->config->address; /* 7-bit address */ msg[0].addr = priv->config->address; /* 7-bit address */
msg[0].flags = 0; /* Write transaction, beginning with START */ msg[0].flags = 0; /* Write transaction, beginning with START */
msg[0].buffer = &regaddr; /* Transfer from this address */ msg[0].buffer = &regaddr; /* Transfer from this address */
@ -188,6 +192,7 @@ uint16_t adxl345_getreg16(FAR struct adxl345_dev_s *priv, uint8_t regaddr)
/* Set up the 8-bit ADXL345 data read message */ /* Set up the 8-bit ADXL345 data read message */
msg[1].frequency = priv->config->frequency; /* I2C frequency */
msg[1].addr = priv->config->address; /* 7-bit address */ msg[1].addr = priv->config->address; /* 7-bit address */
msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */ msg[1].flags = I2C_M_READ; /* Read transaction, beginning with Re-START */
msg[1].buffer = rxbuffer; /* Transfer to this address */ msg[1].buffer = rxbuffer; /* Transfer to this address */

View File

@ -54,6 +54,11 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#ifndef CONFIG_LIS331DL_I2C_FREQUENCY
# define CONFIG_LIS331DL_I2C_FREQUENCY
#endif
/* LIS331DL Internal Registers **********************************************/ /* LIS331DL Internal Registers **********************************************/
#define ST_LIS331DL_WHOAMI 0x0F /* who am I register */ #define ST_LIS331DL_WHOAMI 0x0F /* who am I register */
@ -182,12 +187,14 @@ static int lis331dl_access(FAR struct lis331dl_dev_s *dev, uint8_t subaddr,
struct i2c_msg_s msgv[2] = struct i2c_msg_s msgv[2] =
{ {
{ {
.frequency = CONFIG_LIS331DL_I2C_FREQUENCY,
.addr = dev->address, .addr = dev->address,
.flags = 0, .flags = 0,
.buffer = &subaddr, .buffer = &subaddr,
.length = 1 .length = 1
}, },
{ {
.frequency = CONFIG_LIS331DL_I2C_FREQUENCY,
.addr = dev->address, .addr = dev->address,
.flags = flags, .flags = flags,
.buffer = buf, .buffer = buf,

View File

@ -54,6 +54,7 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Driver Definitions *******************************************************/ /* Driver Definitions *******************************************************/
#define MAX_REFCLK_FREQ 75000000 #define MAX_REFCLK_FREQ 75000000
@ -133,11 +134,13 @@ static int cs2100_write_reg(FAR const struct cs2100_config_s *config,
/* Construct the I2C message (write N+1 bytes with no restart) */ /* Construct the I2C message (write N+1 bytes with no restart) */
msga[0].frequency = config->i2cfreq;
msgs[0].addr = config->i2caddr; msgs[0].addr = config->i2caddr;
msgs[0].flags = 0; msgs[0].flags = 0;
msgs[0].buffer = &regaddr; msgs[0].buffer = &regaddr;
msgs[0].length = 1; msgs[0].length = 1;
msga[1].frequency = config->i2cfreq;
msgs[1].addr = config->i2caddr; msgs[1].addr = config->i2caddr;
msgs[1].flags = I2C_M_NORESTART; msgs[1].flags = I2C_M_NORESTART;
msgs[1].buffer = &regval; msgs[1].buffer = &regval;
@ -175,6 +178,7 @@ static int cs2100_read_reg(FAR const struct cs2100_config_s *config,
/* Construct the I2C message (write 1 bytes, restart, read N bytes) */ /* Construct the I2C message (write 1 bytes, restart, read N bytes) */
msg.frequency = config->i2cfreq;
msg.addr = config->i2caddr; msg.addr = config->i2caddr;
msg.flags = 0; msg.flags = 0;
msg.buffer = &regaddr; msg.buffer = &regaddr;
@ -185,6 +189,7 @@ static int cs2100_read_reg(FAR const struct cs2100_config_s *config,
ret = I2C_TRANSFER(config->i2c, &msg, 1); ret = I2C_TRANSFER(config->i2c, &msg, 1);
if (ret == OK) if (ret == OK)
{ {
msg.frequency = config->i2cfreq;
msg.addr = config->i2caddr; msg.addr = config->i2caddr;
msg.flags = I2C_M_READ; msg.flags = I2C_M_READ;
msg.buffer = regval; msg.buffer = regval;
@ -235,6 +240,7 @@ static int cs2100_write_ratio(FAR const struct cs2100_config_s *config,
buffer[3] = (uint8_t)((ratio >> 8) & 0xff); buffer[3] = (uint8_t)((ratio >> 8) & 0xff);
buffer[4] = (uint8_t)(ratio & 0xff); buffer[4] = (uint8_t)(ratio & 0xff);
msg.frequency = config->i2cfreq;
msg.addr = config->i2caddr; msg.addr = config->i2caddr;
msg.flags = 0; msg.flags = 0;
msg.buffer = buffer; msg.buffer = buffer;
@ -274,6 +280,7 @@ static int cs2100_read_ratio(FAR const struct cs2100_config_s *config,
buffer[0] = CS2100_RATIO0; buffer[0] = CS2100_RATIO0;
msg.frequency = config->i2cfreq;
msg.addr = config->i2caddr; msg.addr = config->i2caddr;
msg.flags = 0; msg.flags = 0;
msg.buffer = buffer; msg.buffer = buffer;
@ -284,6 +291,7 @@ static int cs2100_read_ratio(FAR const struct cs2100_config_s *config,
ret = I2C_TRANSFER(config->i2c, &msg, 1); ret = I2C_TRANSFER(config->i2c, &msg, 1);
if (ret == OK) if (ret == OK)
{ {
msg.frequency = config->i2cfreq;
msg.addr = config->i2caddr; msg.addr = config->i2caddr;
msg.flags = I2C_M_READ; msg.flags = I2C_M_READ;
msg.buffer = buffer; msg.buffer = buffer;

View File

@ -300,6 +300,7 @@ int up_rtc_getdatetime(FAR struct tm *tp)
secaddr = DSXXXX_TIME_SECR; secaddr = DSXXXX_TIME_SECR;
msg[0].frequency = CONFIG_DS3231_I2C_FREQUENCY;
msg[0].addr = DS3231_I2C_ADDRESS; msg[0].addr = DS3231_I2C_ADDRESS;
msg[0].flags = 0; msg[0].flags = 0;
msg[0].buffer = &secaddr; msg[0].buffer = &secaddr;
@ -309,6 +310,7 @@ int up_rtc_getdatetime(FAR struct tm *tp)
* month, year * month, year
*/ */
msg[1].frequency = CONFIG_DS3231_I2C_FREQUENCY;
msg[1].addr = DS3231_I2C_ADDRESS; msg[1].addr = DS3231_I2C_ADDRESS;
msg[1].flags = I2C_M_READ; msg[1].flags = I2C_M_READ;
msg[1].buffer = buffer; msg[1].buffer = buffer;
@ -316,11 +318,13 @@ int up_rtc_getdatetime(FAR struct tm *tp)
/* Read the seconds register again */ /* Read the seconds register again */
msg[2].frequency = CONFIG_DS3231_I2C_FREQUENCY;
msg[2].addr = DS3231_I2C_ADDRESS; msg[2].addr = DS3231_I2C_ADDRESS;
msg[2].flags = 0; msg[2].flags = 0;
msg[2].buffer = &secaddr; msg[2].buffer = &secaddr;
msg[2].length = 1; msg[2].length = 1;
msg[3].frequency = CONFIG_DS3231_I2C_FREQUENCY;
msg[3].addr = DS3231_I2C_ADDRESS; msg[3].addr = DS3231_I2C_ADDRESS;
msg[3].flags = I2C_M_READ; msg[3].flags = I2C_M_READ;
msg[3].buffer = &seconds; msg[3].buffer = &seconds;
@ -525,6 +529,7 @@ int up_rtc_settime(FAR const struct timespec *tp)
/* Setup the I2C message */ /* Setup the I2C message */
msg[0].frequency = CONFIG_DS3231_I2C_FREQUENCY;
msg[0].addr = DS3231_I2C_ADDRESS; msg[0].addr = DS3231_I2C_ADDRESS;
msg[0].flags = 0; msg[0].flags = 0;
msg[0].buffer = buffer; msg[0].buffer = buffer;
@ -532,11 +537,13 @@ int up_rtc_settime(FAR const struct timespec *tp)
/* Read back the seconds register */ /* Read back the seconds register */
msg[1].frequency = CONFIG_DS3231_I2C_FREQUENCY;
msg[1].addr = DS3231_I2C_ADDRESS; msg[1].addr = DS3231_I2C_ADDRESS;
msg[1].flags = 0; msg[1].flags = 0;
msg[1].buffer = buffer; msg[1].buffer = buffer;
msg[1].length = 1; msg[1].length = 1;
msg[2].frequency = CONFIG_DS3231_I2C_FREQUENCY;
msg[2].addr = DS3231_I2C_ADDRESS; msg[2].addr = DS3231_I2C_ADDRESS;
msg[2].flags = I2C_M_READ; msg[2].flags = I2C_M_READ;
msg[2].buffer = &seconds; msg[2].buffer = &seconds;

View File

@ -299,6 +299,7 @@ int up_rtc_getdatetime(FAR struct tm *tp)
secaddr = PCF85263_RTC_SECONDS; secaddr = PCF85263_RTC_SECONDS;
msg[0].frequency = CONFIG_PCF85263_I2C_FREQUENCY;
msg[0].addr = PCF85263_I2C_ADDRESS; msg[0].addr = PCF85263_I2C_ADDRESS;
msg[0].flags = 0; msg[0].flags = 0;
msg[0].buffer = &secaddr; msg[0].buffer = &secaddr;
@ -308,6 +309,7 @@ int up_rtc_getdatetime(FAR struct tm *tp)
* month, year * month, year
*/ */
msg[1].frequency = CONFIG_PCF85263_I2C_FREQUENCY;
msg[1].addr = PCF85263_I2C_ADDRESS; msg[1].addr = PCF85263_I2C_ADDRESS;
msg[1].flags = I2C_M_READ; msg[1].flags = I2C_M_READ;
msg[1].buffer = buffer; msg[1].buffer = buffer;
@ -315,11 +317,13 @@ int up_rtc_getdatetime(FAR struct tm *tp)
/* Read the seconds register again */ /* Read the seconds register again */
msg[2].frequency = CONFIG_PCF85263_I2C_FREQUENCY;
msg[2].addr = PCF85263_I2C_ADDRESS; msg[2].addr = PCF85263_I2C_ADDRESS;
msg[2].flags = 0; msg[2].flags = 0;
msg[2].buffer = &secaddr; msg[2].buffer = &secaddr;
msg[2].length = 1; msg[2].length = 1;
msg[3].frequency = CONFIG_PCF85263_I2C_FREQUENCY;
msg[3].addr = PCF85263_I2C_ADDRESS; msg[3].addr = PCF85263_I2C_ADDRESS;
msg[3].flags = I2C_M_READ; msg[3].flags = I2C_M_READ;
msg[3].buffer = &seconds; msg[3].buffer = &seconds;
@ -487,6 +491,7 @@ int up_rtc_settime(FAR const struct timespec *tp)
/* Setup the I2C message */ /* Setup the I2C message */
msg[0].frequency = CONFIG_PCF85263_I2C_FREQUENCY;
msg[0].addr = PCF85263_I2C_ADDRESS; msg[0].addr = PCF85263_I2C_ADDRESS;
msg[0].flags = 0; msg[0].flags = 0;
msg[0].buffer = buffer; msg[0].buffer = buffer;
@ -496,11 +501,13 @@ int up_rtc_settime(FAR const struct timespec *tp)
cmd = PCF85263_RTC_SECONDS; cmd = PCF85263_RTC_SECONDS;
msg[1].frequency = CONFIG_PCF85263_I2C_FREQUENCY;
msg[1].addr = PCF85263_I2C_ADDRESS; msg[1].addr = PCF85263_I2C_ADDRESS;
msg[1].flags = 0; msg[1].flags = 0;
msg[1].buffer = &cmd; msg[1].buffer = &cmd;
msg[1].length = 1; msg[1].length = 1;
msg[2].frequency = CONFIG_PCF85263_I2C_FREQUENCY;
msg[2].addr = PCF85263_I2C_ADDRESS; msg[2].addr = PCF85263_I2C_ADDRESS;
msg[2].flags = I2C_M_READ; msg[2].flags = I2C_M_READ;
msg[2].buffer = &seconds; msg[2].buffer = &seconds;

View File

@ -155,10 +155,11 @@ struct i2c_config_s
struct i2c_msg_s struct i2c_msg_s
{ {
uint32_t frequency; /* I2C frequency */
uint16_t addr; /* Slave address (7- or 10-bit) */ uint16_t addr; /* Slave address (7- or 10-bit) */
uint16_t flags; /* See I2C_M_* definitions */ uint16_t flags; /* See I2C_M_* definitions */
uint8_t *buffer; /* Buffer to be transferred */ uint8_t *buffer; /* Buffer to be transferred */
ssize_t length; /* Length of the buffer in byetes */ ssize_t length; /* Length of the buffer in bytes */
}; };
/* I2C private data. This structure only defines the initial fields of the /* I2C private data. This structure only defines the initial fields of the

View File

@ -160,6 +160,7 @@
struct cs2100_config_s struct cs2100_config_s
{ {
FAR struct i2c_master_s *i2c; /* Instance of an I2C interface */ FAR struct i2c_master_s *i2c; /* Instance of an I2C interface */
uint32_t i2cfreq; /* I2C frequency */
uint32_t refclk; /* RefClk/XTAL frequency */ uint32_t refclk; /* RefClk/XTAL frequency */
uint32_t clkin; /* Frequency CLK_IN provided to the CS2100-CP */ uint32_t clkin; /* Frequency CLK_IN provided to the CS2100-CP */
uint32_t clkout; /* Desired CLK_OUT frequency */ uint32_t clkout; /* Desired CLK_OUT frequency */