drivers/ctucanfd_pci.c: fix frame reception

Fix frame reception when CANFD is not enabled and there are many message in
the RX buffer.

The previous implementation assumed that the size of the data in the RX buffer
is constant, which is not true. Fortunately, the amount of
data in the buffer can be easily read from frame->fmt.rwcnt.

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
This commit is contained in:
p-szafonimateusz
2025-05-21 14:52:32 +02:00
committed by Alan C. Assis
parent 7d9412e325
commit 49ad027c60
+16 -8
View File
@@ -766,11 +766,15 @@ static void ctucanfd_chardev_receive(FAR struct ctucanfd_can_s *priv)
frame = (struct ctucanfd_frame_s *)&buff;
for (i = 0; i < sizeof(struct ctucanfd_frame_s) / 4; i++)
{
/* RX buffer in automatic mode */
/* RX buffer in automatic mode */
buff[i] = ctucanfd_getreg(priv, CTUCANFD_RXDATA);
buff[0] = ctucanfd_getreg(priv, CTUCANFD_RXDATA);
/* Read the rest of data */
for (i = 0; i < frame->fmt.rwcnt; i++)
{
buff[i + 1] = ctucanfd_getreg(priv, CTUCANFD_RXDATA);
}
/* Get the DLC */
@@ -1369,11 +1373,15 @@ static void ctucanfd_sock_receive(FAR struct ctucanfd_can_s *priv)
rxframe = (struct ctucanfd_frame_s *)&buff;
for (i = 0; i < sizeof(struct ctucanfd_frame_s) / 4; i++)
{
/* RX buffer in automatic mode */
/* RX buffer in automatic mode */
buff[i] = ctucanfd_getreg(priv, CTUCANFD_RXDATA);
buff[0] = ctucanfd_getreg(priv, CTUCANFD_RXDATA);
/* Read the rest of data */
for (i = 0; i < rxframe->fmt.rwcnt; i++)
{
buff[i + 1] = ctucanfd_getreg(priv, CTUCANFD_RXDATA);
}
/* CAN 2.0 or CAN FD */