Copy I2C_M_NOSTART support from sam7v/sam_twihs.c driver
This commit is contained in:
parent
c4c2b14623
commit
5ca9adbe61
@ -474,6 +474,14 @@ static int twi_interrupt(int irq, void *context, void *arg)
|
|||||||
/* Check for transfer complete */
|
/* Check for transfer complete */
|
||||||
|
|
||||||
if (priv->xfrd >= msg->length)
|
if (priv->xfrd >= msg->length)
|
||||||
|
{
|
||||||
|
struct i2c_msg_s *next = (msg + 1);
|
||||||
|
|
||||||
|
/* Is there another message to after this one? Does it require a
|
||||||
|
* restart?
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (priv->msgc <= 1 || (next->flags & I2C_M_NOSTART) == 0)
|
||||||
{
|
{
|
||||||
/* The transfer is complete. Disable the RXRDY interrupt and
|
/* The transfer is complete. Disable the RXRDY interrupt and
|
||||||
* enable the TXCOMP interrupt
|
* enable the TXCOMP interrupt
|
||||||
@ -482,16 +490,40 @@ static int twi_interrupt(int irq, void *context, void *arg)
|
|||||||
twi_putrel(priv, SAM_TWI_IDR_OFFSET, TWI_INT_RXRDY);
|
twi_putrel(priv, SAM_TWI_IDR_OFFSET, TWI_INT_RXRDY);
|
||||||
twi_putrel(priv, SAM_TWI_IER_OFFSET, TWI_INT_TXCOMP);
|
twi_putrel(priv, SAM_TWI_IER_OFFSET, TWI_INT_TXCOMP);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* No.. just switch to the next message and continue
|
||||||
|
* receiving. On the next RXRDY, we will continue with the
|
||||||
|
* first byte of the next message.
|
||||||
|
*/
|
||||||
|
|
||||||
|
DEBUGASSERT((next->flags & I2C_M_READ) != 0);
|
||||||
|
priv->msg = next;
|
||||||
|
priv->msgc--;
|
||||||
|
priv->xfrd = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Not yet complete, but will the next be the last byte? */
|
/* Not yet complete, but will the next be the last byte? */
|
||||||
|
|
||||||
else if (priv->xfrd == (msg->length - 1))
|
else if (priv->xfrd == (msg->length - 1))
|
||||||
{
|
{
|
||||||
/* Yes, set the stop signal */
|
struct i2c_msg_s *next = (msg + 1);
|
||||||
|
|
||||||
|
/* Is there another message to after this one? Does it require a
|
||||||
|
* restart?
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (priv->msgc <= 1 || (next->flags & I2C_M_NOSTART) == 0)
|
||||||
|
{
|
||||||
|
/* This is the last message OR a restart is required before
|
||||||
|
* the next message. Send the stop signal.
|
||||||
|
*/
|
||||||
|
|
||||||
twi_putrel(priv, SAM_TWI_CR_OFFSET, TWI_CR_STOP);
|
twi_putrel(priv, SAM_TWI_CR_OFFSET, TWI_CR_STOP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Byte sent */
|
/* Byte sent */
|
||||||
|
|
||||||
@ -500,6 +532,14 @@ static int twi_interrupt(int irq, void *context, void *arg)
|
|||||||
/* Transfer finished? */
|
/* Transfer finished? */
|
||||||
|
|
||||||
if (priv->xfrd >= msg->length)
|
if (priv->xfrd >= msg->length)
|
||||||
|
{
|
||||||
|
struct i2c_msg_s *next = (msg + 1);
|
||||||
|
|
||||||
|
/* Is there another message to after this one? Does it require a
|
||||||
|
* restart?
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (priv->msgc <= 1 || (next->flags & I2C_M_NOSTART) == 0)
|
||||||
{
|
{
|
||||||
/* The transfer is complete. Disable the TXRDY interrupt and
|
/* The transfer is complete. Disable the TXRDY interrupt and
|
||||||
* enable the TXCOMP interrupt
|
* enable the TXCOMP interrupt
|
||||||
@ -514,6 +554,20 @@ static int twi_interrupt(int irq, void *context, void *arg)
|
|||||||
regval |= TWI_CR_STOP;
|
regval |= TWI_CR_STOP;
|
||||||
twi_putrel(priv, SAM_TWI_CR_OFFSET, regval);
|
twi_putrel(priv, SAM_TWI_CR_OFFSET, regval);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* No.. just switch to the next message and continue
|
||||||
|
* sending.
|
||||||
|
*/
|
||||||
|
|
||||||
|
DEBUGASSERT((next->flags & I2C_M_READ) == 0);
|
||||||
|
priv->msg = next;
|
||||||
|
priv->msgc--;
|
||||||
|
|
||||||
|
twi_putrel(priv, SAM_TWI_THR_OFFSET, next->buffer[0]);
|
||||||
|
priv->xfrd = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* No, there are more bytes remaining to be sent */
|
/* No, there are more bytes remaining to be sent */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user