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

xiaoxiang pushed a commit to branch releases/12.7
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit b63826a73681c4b558533fc27c96e546007b4ce8
Author: xuxingliang <[email protected]>
AuthorDate: Tue Jul 23 14:35:16 2024 +0800

    arch/sim: fix uart could lose log
    
    Need to loop to write untill all data written or error happened
    
    Signed-off-by: xuxingliang <[email protected]>
---
 arch/sim/src/sim/sim_uart.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/arch/sim/src/sim/sim_uart.c b/arch/sim/src/sim/sim_uart.c
index deced81576..e329d4a2da 100644
--- a/arch/sim/src/sim/sim_uart.c
+++ b/arch/sim/src/sim/sim_uart.c
@@ -278,6 +278,29 @@ static struct uart_dev_s g_tty3_dev =
  ****************************************************************************/
 
 #if defined(USE_DEVCONSOLE) || CONFIG_SIM_UART_NUMBER > 0
+/****************************************************************************
+ * Name: uart_nputs
+ *
+ * Description:
+ *   Loop to write data to the UART until all the data is sent
+ *
+ ****************************************************************************/
+
+static void uart_nputs(int fd, const char *buf, size_t size)
+{
+  while (size > 0)
+    {
+      int ret = host_uart_puts(fd, buf, size);
+      if (ret < 0)
+        {
+          continue;
+        }
+
+      buf += ret;
+      size -= ret;
+    }
+}
+
 /****************************************************************************
  * Name: tty_setup
  *
@@ -617,7 +640,7 @@ static void tty_send(struct uart_dev_s *dev, int ch)
   struct tty_priv_s *priv = dev->priv;
   char c = ch;
 
-  host_uart_puts(dev->isconsole ? 1 : priv->fd, &c, 1);
+  uart_nputs(dev->isconsole ? 1 : priv->fd, &c, 1);
 }
 
 /****************************************************************************
@@ -757,12 +780,12 @@ void up_nputs(const char *str, size_t len)
 #ifdef USE_DEVCONSOLE
   if (str[len - 1] == '\n')
     {
-      host_uart_puts(1, str, len - 1);
-      host_uart_puts(1, "\r\n", 2);
+      uart_nputs(1, str, len - 1);
+      uart_nputs(1, "\r\n", 2);
     }
   else
     {
-      host_uart_puts(1, str, len);
+      uart_nputs(1, str, len);
     }
 #endif
 }

Reply via email to