Fix handling if STM32 I2C byte count

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4530 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo
2012-03-27 20:44:00 +00:00
parent 7ce2f90034
commit 1e104ed087
+11 -6
View File
@@ -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) */ /* 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++; 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); uint32_t status = stm32_i2c_getstatus(priv);
@@ -1026,15 +1026,16 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv)
/* Was address sent, continue with either sending or reading data */ /* Was address sent, continue with either sending or reading data */
else if ((priv->flags & I2C_M_READ) == 0 && (status & (I2C_SR1_ADDR | I2C_SR1_TXE)) != 0) else if ((priv->flags & I2C_M_READ) == 0 && (status & (I2C_SR1_ADDR | I2C_SR1_TXE)) != 0)
{
if (priv->dcnt > 0)
{ {
stm32_i2c_traceevent(priv, I2CEVENT_READ, priv->dcnt); stm32_i2c_traceevent(priv, I2CEVENT_READ, priv->dcnt);
if (--priv->dcnt >= 0)
{
/* Send a byte */ /* Send a byte */
stm32_i2c_traceevent(priv, I2CEVENT_SENDBYTE, *priv->ptr); stm32_i2c_traceevent(priv, I2CEVENT_SENDBYTE, *priv->ptr);
stm32_i2c_putreg(priv, STM32_I2C_DR_OFFSET, *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 */ /* 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); *priv->ptr++ = stm32_i2c_getreg(priv, STM32_I2C_DR_OFFSET);
/* Disable acknowledge when last byte is to be received */ /* 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); stm32_i2c_modifyreg(priv, STM32_I2C_CR1_OFFSET, I2C_CR1_ACK, 0);
} }
priv->dnct--;
} }
} }