acassis commented on code in PR #21643:
URL: https://github.com/apache/nuttx/pull/21643#discussion_r4541939615


##########
drivers/misc/lwl_console.c:
##########
@@ -296,25 +977,40 @@ static ssize_t lwlconsole_write(FAR struct file *filep,
 
 /****************************************************************************
  * Name: up_putc
+ *
+ * Description:
+ *   Low-level, unbuffered console output used by syslog and by the assert
+ *   logic.  It waits for room in the link.
+ *
  ****************************************************************************/
 
 void up_putc(int ch)
 {
-  /* If link not initialize just return */
+  irqstate_t flags;
+  uint8_t c = ch;
+
+  flags = enter_critical_section();
 
-  if (!linkactive())
+  do
     {
-      return;
+      while (!lwl_txready(&g_lwl_dev))
+        {
+        }
     }
+  while (lwl_sendbuf(&g_lwl_dev, &c, 1) == 0);
 
-  write8bits(LWL_PORT_CONSOLE, (uint8_t)ch);
+  leave_critical_section(flags);

Review Comment:
   Could you clarify what you have in mind? The critical section here is 
deliberate:
   
   - up_putc() is used by syslog and the assert path, so it can run in any 
context. The serial upper half itself uses enter_critical_section() to 
serialize uart_write() with up_putc() based syslog channels (see the comment in 
uart_putxmitbuf() pointing to #14662). Using the same lock here keeps syslog 
output from interleaving with the console output or corrupting the shared 
control block.
   - lwl_service() is entered from the doorbell ISR, from the poll watchdog and 
from rxint()/txint() in thread context, so it needs a lock that also masks 
interrupts.
   
   I didn't find a uart-level lock or helper in include/nuttx/serial/serial.h 
that I could use instead. If you mean a driver-private spinlock 
(spin_lock_irqsave()), I can switch lwl_service() to it, but up_putc() would 
then no longer be serialized with the upper half's critical section. If there 
is a framework API I missed, please point me to it and I'll use it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to