driver/spi: avoid calling QPOLL to change rx_length and cause data loss
When the application calls poll and returns the POLLIN event, QPOLL will be called again during the read operation, causing rx_length to change and data to be lost. Therefore, read only need to actively call qpoll to collect driver data when rx length is 0. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
ade23b92d1
commit
dcb8188f07
@ -326,7 +326,7 @@ static ssize_t spi_slave_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
while (priv->rx_length == 0)
|
||||||
{
|
{
|
||||||
remaining_words = SPIS_CTRLR_QPOLL(priv->ctrlr);
|
remaining_words = SPIS_CTRLR_QPOLL(priv->ctrlr);
|
||||||
if (remaining_words == 0)
|
if (remaining_words == 0)
|
||||||
@ -360,11 +360,11 @@ static ssize_t spi_slave_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (priv->rx_length == 0);
|
|
||||||
|
|
||||||
read_bytes = MIN(buflen, priv->rx_length);
|
read_bytes = MIN(buflen, priv->rx_length);
|
||||||
|
|
||||||
memcpy(buffer, priv->rx_buffer, read_bytes);
|
memcpy(buffer, priv->rx_buffer, read_bytes);
|
||||||
|
priv->rx_length -= read_bytes;
|
||||||
|
|
||||||
nxmutex_unlock(&priv->lock);
|
nxmutex_unlock(&priv->lock);
|
||||||
return (ssize_t)read_bytes;
|
return (ssize_t)read_bytes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user