[rtems commit] grlib: Add apbuart_outbyte_wait()

Sebastian Huber sebh at rtems.org
Thu Jun 17 10:59:23 UTC 2021


Module:    rtems
Branch:    master
Commit:    af69a8693b4f4a7f1ea41d2948c3550a46ae6e17
Changeset: http://git.rtems.org/rtems/commit/?id=af69a8693b4f4a7f1ea41d2948c3550a46ae6e17

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Jun 10 15:01:49 2021 +0200

grlib: Add apbuart_outbyte_wait()

---

 bsps/include/grlib/apbuart.h               |  8 +++-----
 bsps/riscv/griscv/console/printk_support.c |  3 ++-
 bsps/shared/grlib/uart/apbuart_cons.c      |  2 +-
 bsps/shared/grlib/uart/apbuart_polled.c    | 30 +++++++++++++++---------------
 bsps/shared/grlib/uart/apbuart_termios.c   |  2 +-
 bsps/sparc/leon3/console/printk_support.c  |  3 ++-
 6 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/bsps/include/grlib/apbuart.h b/bsps/include/grlib/apbuart.h
index 2ca67b2..68bcf1b 100644
--- a/bsps/include/grlib/apbuart.h
+++ b/bsps/include/grlib/apbuart.h
@@ -62,11 +62,9 @@ extern "C" {
 #define APBUART_STATUS_TF 0x200
 #define APBUART_STATUS_RF 0x400
 
-void apbuart_outbyte_polled(
-  struct apbuart_regs *regs,
-  unsigned char ch,
-  int wait_sent
-);
+void apbuart_outbyte_wait(const struct apbuart_regs *regs);
+
+void apbuart_outbyte_polled(struct apbuart_regs *regs, unsigned char ch);
 
 int apbuart_inbyte_nonblocking(struct apbuart_regs *regs);
 
diff --git a/bsps/riscv/griscv/console/printk_support.c b/bsps/riscv/griscv/console/printk_support.c
index 4c8acd5..f232203 100644
--- a/bsps/riscv/griscv/console/printk_support.c
+++ b/bsps/riscv/griscv/console/printk_support.c
@@ -100,7 +100,8 @@ static void bsp_out_char(char c)
     */
   }
 
-  apbuart_outbyte_polled(grlib_debug_uart, c, 1);
+  apbuart_outbyte_polled(grlib_debug_uart, c);
+  apbuart_outbyte_wait(grlib_debug_uart);
 }
 
 /*
diff --git a/bsps/shared/grlib/uart/apbuart_cons.c b/bsps/shared/grlib/uart/apbuart_cons.c
index e7dda50..a0a265a 100644
--- a/bsps/shared/grlib/uart/apbuart_cons.c
+++ b/bsps/shared/grlib/uart/apbuart_cons.c
@@ -641,7 +641,7 @@ static void write_polled(
 	int nwrite = 0;
 
 	while (nwrite < len) {
-		apbuart_outbyte_polled(uart->regs, *buf++, 0);
+		apbuart_outbyte_polled(uart->regs, *buf++);
 		nwrite++;
 	}
 }
diff --git a/bsps/shared/grlib/uart/apbuart_polled.c b/bsps/shared/grlib/uart/apbuart_polled.c
index 948e096..8a59680 100644
--- a/bsps/shared/grlib/uart/apbuart_polled.c
+++ b/bsps/shared/grlib/uart/apbuart_polled.c
@@ -9,27 +9,27 @@
 
 #include <grlib/apbuart.h>
 
-void apbuart_outbyte_polled(
-  struct apbuart_regs *regs,
-  unsigned char ch,
-  int wait_sent
-)
+#include <rtems/score/cpuimpl.h>
+
+void apbuart_outbyte_wait(const struct apbuart_regs *regs)
 {
   while ( (regs->status & APBUART_STATUS_TE) == 0 ) {
     /* Lower bus utilization while waiting for UART */
-    __asm__ volatile ("nop"::); __asm__ volatile ("nop"::);
-    __asm__ volatile ("nop"::); __asm__ volatile ("nop"::);
-    __asm__ volatile ("nop"::); __asm__ volatile ("nop"::);
-    __asm__ volatile ("nop"::); __asm__ volatile ("nop"::);
+    _CPU_Instruction_no_operation();
+    _CPU_Instruction_no_operation();
+    _CPU_Instruction_no_operation();
+    _CPU_Instruction_no_operation();
+    _CPU_Instruction_no_operation();
+    _CPU_Instruction_no_operation();
+    _CPU_Instruction_no_operation();
+    _CPU_Instruction_no_operation();
   }
+}
 
+void apbuart_outbyte_polled(struct apbuart_regs *regs, char ch)
+{
+  apbuart_outbyte_wait(regs);
   regs->data = (unsigned int) ch;
-
-  /* Wait until the character has been sent? */
-  if (wait_sent) {
-    while ((regs->status & APBUART_STATUS_TE) == 0)
-      ;
-  }
 }
 
 int apbuart_inbyte_nonblocking(struct apbuart_regs *regs)
diff --git a/bsps/shared/grlib/uart/apbuart_termios.c b/bsps/shared/grlib/uart/apbuart_termios.c
index 5fb6990..9014a1c 100644
--- a/bsps/shared/grlib/uart/apbuart_termios.c
+++ b/bsps/shared/grlib/uart/apbuart_termios.c
@@ -78,7 +78,7 @@ static void apbuart_write_polled(
   size_t nwrite = 0;
 
   while (nwrite < len) {
-    apbuart_outbyte_polled(uart->regs, *buf++, 0);
+    apbuart_outbyte_polled(uart->regs, *buf++);
     nwrite++;
   }
 }
diff --git a/bsps/sparc/leon3/console/printk_support.c b/bsps/sparc/leon3/console/printk_support.c
index aa05e1c..f9cf0b7 100644
--- a/bsps/sparc/leon3/console/printk_support.c
+++ b/bsps/sparc/leon3/console/printk_support.c
@@ -34,7 +34,8 @@ static void bsp_debug_uart_discard(char c)
 
 static void bsp_debug_uart_output_char(char c)
 {
-  apbuart_outbyte_polled(leon3_debug_uart, c, 1);
+  apbuart_outbyte_polled(leon3_debug_uart, c);
+  apbuart_outbyte_wait(leon3_debug_uart);
 }
 
 static int bsp_debug_uart_poll_char(void)



More information about the vc mailing list