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

commit ab5187c16da899cb6b7d049a0063aec09767d32b
Author: Bowen Wang <[email protected]>
AuthorDate: Wed Aug 5 19:18:05 2026 +0800

    drivers/rpmsg/rpmsg_port: keep exchanging while frames await ack
    
    The complete handler and the PM callback used
    rpmsg_port_retx_is_pending() to decide whether the link still had
    work to do, but that helper reports whether fast retransmit has
    triggered (ackdup_count >= 2), not whether any frame is still
    unacknowledged.  When a frame was lost and left ackdup_count at 1
    with an empty tx queue, both ends concluded there was nothing to
    do: neither raised its request line and the link went silent.
    ackdup_count only advances on a received frame, so the dup-ack
    threshold was never reached, the frame was never retransmitted and
    its retry_count stayed at 0, so it was never dropped either.  The
    peer waited for a sequence number that would never arrive until the
    watchdog reset the system.
    
    Add rpmsg_port_retx_is_empty() and use it for those two decisions,
    so an unacknowledged frame keeps the exchange running and holds the
    wakelock.  The exchange path still uses is_pending() to choose the
    frame to send, leaving the dup-ack threshold of 2 - which absorbs
    the one-beat ack latency inherent to full duplex SPI - in place, so
    no frame is retransmitted early.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rpmsg/rpmsg_port.h           | 24 ++++++++++++++++++++++++
 drivers/rpmsg/rpmsg_port_spi.c       |  4 ++--
 drivers/rpmsg/rpmsg_port_spi_slave.c |  4 ++--
 3 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/drivers/rpmsg/rpmsg_port.h b/drivers/rpmsg/rpmsg_port.h
index 624a8dbc112..01b134997cb 100644
--- a/drivers/rpmsg/rpmsg_port.h
+++ b/drivers/rpmsg/rpmsg_port.h
@@ -471,6 +471,29 @@ bool rpmsg_port_retx_is_pending(FAR struct rpmsg_port_s 
*port)
   return atomic_read(&port->retx.ackdup_count) >= 2;
 }
 
+/****************************************************************************
+ * Name: rpmsg_port_retx_is_empty
+ *
+ * Description:
+ *   Check whether all sent frames have been acknowledged. Unlike
+ *   rpmsg_port_retx_is_pending(), which reports whether fast retransmit
+ *   has been triggered, this tells the caller whether the link still has
+ *   unacknowledged frames and must keep exchanging to collect their acks.
+ *
+ ****************************************************************************/
+
+static inline_function
+bool rpmsg_port_retx_is_empty(FAR struct rpmsg_port_s *port)
+{
+  irqstate_t flags;
+  bool ret;
+
+  flags = spin_lock_irqsave(&port->retx.lock);
+  ret = list_is_empty(&port->retx.queue);
+  spin_unlock_irqrestore(&port->retx.lock, flags);
+  return ret;
+}
+
 /****************************************************************************
  * Name: rpmsg_port_retx_tx_fill
  *
@@ -513,6 +536,7 @@ void rpmsg_port_retx_tx_fill(FAR struct rpmsg_port_s *port,
 #  define rpmsg_port_retx_del(port, node)
 #  define rpmsg_port_retx_get(port)                         NULL
 #  define rpmsg_port_retx_is_pending(port)                  false
+#  define rpmsg_port_retx_is_empty(port)                    true
 #  define rpmsg_port_retx_tx_fill(port, txhdr)
 #  define rpmsg_port_retx_process_ack(port, ackno, min_seq)
 #  define rpmsg_port_retx_rx_valid(port, hdr)               true
diff --git a/drivers/rpmsg/rpmsg_port_spi.c b/drivers/rpmsg/rpmsg_port_spi.c
index 0aa74dcb3b8..a64d17d557d 100644
--- a/drivers/rpmsg/rpmsg_port_spi.c
+++ b/drivers/rpmsg/rpmsg_port_spi.c
@@ -182,7 +182,7 @@ static void rpmsg_port_spi_pm_callback(wdparm_t arg)
   if (count > 0 && atomic_read(&rpspi->transferring) == 0 &&
       rpmsg_port_queue_nused(&rpspi->port.txq) == 0 &&
       rpmsg_port_queue_nused(&rpspi->port.rxq) == 0 &&
-      !rpmsg_port_retx_is_pending(&rpspi->port))
+      rpmsg_port_retx_is_empty(&rpspi->port))
     {
       pm_wakelock_relax(&rpspi->wakelock);
     }
@@ -575,7 +575,7 @@ out:
     {
       rpmsg_port_spi_exchange(rpspi);
     }
-  else if (rpmsg_port_retx_is_pending(&rpspi->port) ||
+  else if (!rpmsg_port_retx_is_empty(&rpspi->port) ||
       (rpspi->state == RPMSG_PORT_SPI_STATE_CONNECTED &&
       rpspi->txavail > 0 && rpmsg_port_queue_nused(&rpspi->port.txq) > 0))
     {
diff --git a/drivers/rpmsg/rpmsg_port_spi_slave.c 
b/drivers/rpmsg/rpmsg_port_spi_slave.c
index 4b66bef7a3c..5f1c38aacd9 100644
--- a/drivers/rpmsg/rpmsg_port_spi_slave.c
+++ b/drivers/rpmsg/rpmsg_port_spi_slave.c
@@ -210,7 +210,7 @@ static void rpmsg_port_spi_pm_callback(wdparm_t arg)
   if (count > 0 && atomic_read(&rpspi->transferring) == 0 &&
       rpmsg_port_queue_nused(&rpspi->port.txq) == 0 &&
       rpmsg_port_queue_nused(&rpspi->port.rxq) == 0 &&
-      !rpmsg_port_retx_is_pending(&rpspi->port))
+      rpmsg_port_retx_is_empty(&rpspi->port))
     {
       pm_wakelock_relax(&rpspi->wakelock);
     }
@@ -650,7 +650,7 @@ unlock:
   spin_unlock_irqrestore(&rpspi->lock, flags);
 out:
   if (atomic_xchg(&rpspi->transferring, 0) > 1 ||
-      rpmsg_port_retx_is_pending(&rpspi->port) ||
+      !rpmsg_port_retx_is_empty(&rpspi->port) ||
       (rpspi->txavail > 0 && rpmsg_port_queue_nused(&rpspi->port.txq) > 0))
     {
       rpmsg_port_spi_exchange(rpspi);

Reply via email to