diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-03-27 20:44:00 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-03-27 20:44:00 +0000 |
commit | 92d2b1784ad67d066b589a7e6923b4f76ca84bb2 (patch) | |
tree | 9663e060f78685eb5a6ed1947a8f5cc700631815 | |
parent | 99075db33f33272ed59617de9d584d29d342c5a9 (diff) | |
download | nuttx-92d2b1784ad67d066b589a7e6923b4f76ca84bb2.tar.gz nuttx-92d2b1784ad67d066b589a7e6923b4f76ca84bb2.tar.bz2 nuttx-92d2b1784ad67d066b589a7e6923b4f76ca84bb2.zip |
Fix handling if STM32 I2C byte count
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4530 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/arch/arm/src/stm32/stm32_i2c.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/nuttx/arch/arm/src/stm32/stm32_i2c.c b/nuttx/arch/arm/src/stm32/stm32_i2c.c index 1a1facdd2..11e6767ae 100644 --- a/nuttx/arch/arm/src/stm32/stm32_i2c.c +++ b/nuttx/arch/arm/src/stm32/stm32_i2c.c @@ -695,7 +695,7 @@ static void stm32_i2c_tracenew(FAR struct stm32_i2c_priv_s *priv, uint32_t statu { /* Yes.. bump up the trace index (unless we are out of trace entries) */ - if (priv->tndx < CONFIG_I2C_NTRACE) + if (priv->tndx < (CONFIG_I2C_NTRACE-1)) { priv->tndx++; } @@ -977,7 +977,7 @@ static inline void stm32_i2c_enablefsmc(uint32_t ahbenr) * ************************************************************************************/ -static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv) +static int stm32_i2c_isr(struct stm32_i2c_priv_s *priv) { uint32_t status = stm32_i2c_getstatus(priv); @@ -1027,14 +1027,15 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv) else if ((priv->flags & I2C_M_READ) == 0 && (status & (I2C_SR1_ADDR | I2C_SR1_TXE)) != 0) { - stm32_i2c_traceevent(priv, I2CEVENT_READ, priv->dcnt); - - if (--priv->dcnt >= 0) + if (priv->dcnt > 0) { + stm32_i2c_traceevent(priv, I2CEVENT_READ, priv->dcnt); + /* Send a byte */ stm32_i2c_traceevent(priv, I2CEVENT_SENDBYTE, *priv->ptr); stm32_i2c_putreg(priv, STM32_I2C_DR_OFFSET, *priv->ptr++); + priv->dcnt--; } } @@ -1054,9 +1055,12 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv) { /* Read a byte, if dcnt goes < 0, then read dummy bytes to ack ISRs */ - stm32_i2c_traceevent(priv, I2CEVENT_RXNE, priv->dcnt); - if (--priv->dcnt >= 0) + if (priv->dcnt > 0) { + stm32_i2c_traceevent(priv, I2CEVENT_RXNE, priv->dcnt); + + /* Receive a byte */ + *priv->ptr++ = stm32_i2c_getreg(priv, STM32_I2C_DR_OFFSET); /* Disable acknowledge when last byte is to be received */ @@ -1065,6 +1069,7 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv) { stm32_i2c_modifyreg(priv, STM32_I2C_CR1_OFFSET, I2C_CR1_ACK, 0); } + priv->dnct--; } } |