This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new bb2454e44f0 drivers/rpmsg/rpmsg_port_spi: never send a zero CRC
bb2454e44f0 is described below

commit bb2454e44f0a1a3b98d96b17061c4e06490435f1
Author: mazhuang <[email protected]>
AuthorDate: Fri Nov 27 17:11:51 2026 +0800

    drivers/rpmsg/rpmsg_port_spi: never send a zero CRC
    
    The receiver skips the CRC check of a frame whose crc field is 0, so a
    frame whose checksum happens to compute to 0 is never validated.
    Send 1 instead in that case, so a crc field of 0 only means the sender
    did not compute one.
    
    Signed-off-by: mazhuang <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rpmsg/rpmsg_port_spi.c       | 24 +++++++++++++++++-------
 drivers/rpmsg/rpmsg_port_spi_slave.c | 24 +++++++++++++++++-------
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/drivers/rpmsg/rpmsg_port_spi.c b/drivers/rpmsg/rpmsg_port_spi.c
index 36cf75d6a61..834ddc350c6 100644
--- a/drivers/rpmsg/rpmsg_port_spi.c
+++ b/drivers/rpmsg/rpmsg_port_spi.c
@@ -44,13 +44,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#ifdef CONFIG_RPMSG_PORT_SPI_CRC
-#  define rpmsg_port_spi_crc16(hdr)     xorsum16(&(hdr)->cmd, \
-                                                 (hdr)->len - 
sizeof((hdr)->crc))
-#else
-#  define rpmsg_port_spi_crc16(hdr)     0
-#endif
-
 #define RPMSG_PORT_SPI_CMD_TIMEOUT      1000
 #define RPMSG_PORT_SPI_BYTES2WORDS(s,b) ((b) / ((s)->nbits >> 3))
 
@@ -148,6 +141,23 @@ static const struct rpmsg_port_ops_s g_rpmsg_port_spi_ops =
  * Private Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: rpmsg_port_spi_crc16
+ ****************************************************************************/
+
+static uint16_t rpmsg_port_spi_crc16(FAR struct rpmsg_port_header_s *hdr)
+{
+#ifdef CONFIG_RPMSG_PORT_SPI_CRC
+  uint16_t crc = xorsum16(&hdr->cmd, hdr->len - sizeof(hdr->crc));
+
+  /* The receiver skips the check of a zero crc, so never send one */
+
+  return crc != 0 ? crc : 1;
+#else
+  return 0;
+#endif
+}
+
 #ifdef CONFIG_PM
 
 /****************************************************************************
diff --git a/drivers/rpmsg/rpmsg_port_spi_slave.c 
b/drivers/rpmsg/rpmsg_port_spi_slave.c
index 0a2d2e7b827..a7550ab2c23 100644
--- a/drivers/rpmsg/rpmsg_port_spi_slave.c
+++ b/drivers/rpmsg/rpmsg_port_spi_slave.c
@@ -45,13 +45,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#ifdef CONFIG_RPMSG_PORT_SPI_CRC
-#  define rpmsg_port_spi_crc16(hdr)     xorsum16(&(hdr)->cmd, \
-                                                 (hdr)->len - 
sizeof((hdr)->crc))
-#else
-#  define rpmsg_port_spi_crc16(hdr)     0
-#endif
-
 #define RPMSG_PORT_SPI_CMD_TIMEOUT      1000
 #define RPMSG_PORT_SPI_BYTES2WORDS(s,b) ((b) / ((s)->nbits >> 3))
 
@@ -176,6 +169,23 @@ static const struct spi_slave_devops_s 
g_rpmsg_port_spi_slave_ops =
  * Private Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: rpmsg_port_spi_crc16
+ ****************************************************************************/
+
+static uint16_t rpmsg_port_spi_crc16(FAR struct rpmsg_port_header_s *hdr)
+{
+#ifdef CONFIG_RPMSG_PORT_SPI_CRC
+  uint16_t crc = xorsum16(&hdr->cmd, hdr->len - sizeof(hdr->crc));
+
+  /* The receiver skips the check of a zero crc, so never send one */
+
+  return crc != 0 ? crc : 1;
+#else
+  return 0;
+#endif
+}
+
 #ifdef CONFIG_PM
 
 /****************************************************************************

Reply via email to