[rtems commit] bsps/sparc: Move polled APBUART functions

Sebastian Huber sebh at rtems.org
Fri Aug 10 05:15:45 UTC 2018


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Aug  9 09:20:33 2018 +0200

bsps/sparc: Move polled APBUART functions

This reduces the link-time dependencies and avoids copy-and-paste.

---

 bsps/sparc/include/bsp/apbuart.h          | 10 ++++++
 bsps/sparc/include/bsp/apbuart_termios.h  | 19 -----------
 bsps/sparc/leon3/console/printk_support.c |  1 -
 bsps/sparc/shared/uart/apbuart_cons.c     | 52 -------------------------------
 bsps/sparc/shared/uart/apbuart_polled.c   | 52 +++++++++++++++++++++++++++++++
 bsps/sparc/shared/uart/apbuart_termios.c  | 52 -------------------------------
 c/src/lib/libbsp/sparc/leon3/Makefile.am  |  5 ++-
 7 files changed, 64 insertions(+), 127 deletions(-)

diff --git a/bsps/sparc/include/bsp/apbuart.h b/bsps/sparc/include/bsp/apbuart.h
index a324805..870e540 100644
--- a/bsps/sparc/include/bsp/apbuart.h
+++ b/bsps/sparc/include/bsp/apbuart.h
@@ -20,6 +20,7 @@
 #define __APBUART_H__
 
 #include <ambapp.h>
+#include <grlib.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -53,6 +54,15 @@ extern "C" {
 #define APBUART_STATUS_TF 0x200
 #define APBUART_STATUS_RF 0x400
 
+void apbuart_outbyte_polled(
+  struct apbuart_regs *regs,
+  unsigned char ch,
+  int do_cr_on_newline,
+  int wait_sent
+);
+
+int apbuart_inbyte_nonblocking(struct apbuart_regs *regs);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/bsps/sparc/include/bsp/apbuart_termios.h b/bsps/sparc/include/bsp/apbuart_termios.h
index 40377c1..58338dd 100644
--- a/bsps/sparc/include/bsp/apbuart_termios.h
+++ b/bsps/sparc/include/bsp/apbuart_termios.h
@@ -34,25 +34,6 @@ const rtems_termios_device_handler apbuart_handler_interrupt;
 
 const rtems_termios_device_handler apbuart_handler_polled;
 
-/*
- *  apbuart_outbyte_polled
- *
- *  This routine transmits a character using polling.
- */
-void apbuart_outbyte_polled(
-  struct apbuart_regs *regs,
-  unsigned char ch,
-  int do_cr_on_newline,
-  int wait_sent
-);
-
-/*
- *  apbuart_inbyte_nonblocking
- *
- *  This routine polls for a character.
- */
-int apbuart_inbyte_nonblocking(struct apbuart_regs *regs);
-
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/bsps/sparc/leon3/console/printk_support.c b/bsps/sparc/leon3/console/printk_support.c
index f7e1fb6..aa9441a 100644
--- a/bsps/sparc/leon3/console/printk_support.c
+++ b/bsps/sparc/leon3/console/printk_support.c
@@ -23,7 +23,6 @@
 #include <assert.h>
 #include <stdio.h>
 #include <bsp/apbuart.h>
-#include <bsp/apbuart_termios.h>
 
 int leon3_debug_uart_index __attribute__((weak)) = 0;
 struct apbuart_regs *leon3_debug_uart = NULL;
diff --git a/bsps/sparc/shared/uart/apbuart_cons.c b/bsps/sparc/shared/uart/apbuart_cons.c
index e406bc0..ac8a436 100644
--- a/bsps/sparc/shared/uart/apbuart_cons.c
+++ b/bsps/sparc/shared/uart/apbuart_cons.c
@@ -42,12 +42,6 @@
 #endif
 
 /* LEON3 Low level transmit/receive functions provided by debug-uart code */
-extern void apbuart_outbyte_polled(
-  struct apbuart_regs *regs,
-  unsigned char ch,
-  int do_cr_on_newline,
-  int wait_sent);
-extern int apbuart_inbyte_nonblocking(struct apbuart_regs *regs);
 #ifdef LEON3
 extern struct apbuart_regs *leon3_debug_uart; /* The debug UART */
 #endif
@@ -385,52 +379,6 @@ static int apbuart_info(
 }
 #endif
 
-#ifndef LEON3
-/* This routine transmits a character, it will busy-wait until on character
- * fits in the APBUART Transmit FIFO
- */
-void apbuart_outbyte_polled(
-  struct apbuart_regs *regs,
-  unsigned char ch,
-  int do_cr_on_newline,
-  int wait_sent)
-{
-send:
-	while ((regs->status & LEON_REG_UART_STATUS_THE) == 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"::);
-	}
-	regs->data = (unsigned int) ch;
-
-	if ((ch == '\n') && do_cr_on_newline) {
-		ch = '\r';
-		goto send;
-	}
-
-	/* Wait until the character has been sent? */
-	if (wait_sent) {
-		while ((regs->status & LEON_REG_UART_STATUS_THE) == 0)
-			;
-	}
-}
-
-/* This routine polls for one character, return EOF if no character is available */
-int apbuart_inbyte_nonblocking(struct apbuart_regs *regs)
-{
-	if (regs->status & LEON_REG_UART_STATUS_ERR) {
-		regs->status = ~LEON_REG_UART_STATUS_ERR;
-	}
-
-	if ((regs->status & LEON_REG_UART_STATUS_DR) == 0)
-		return EOF;
-
-	return (int)regs->data;
-}
-#endif
-
 static bool first_open(
 	rtems_termios_tty *tty,
 	rtems_termios_device_context *base,
diff --git a/bsps/sparc/shared/uart/apbuart_polled.c b/bsps/sparc/shared/uart/apbuart_polled.c
new file mode 100644
index 0000000..4a44027
--- /dev/null
+++ b/bsps/sparc/shared/uart/apbuart_polled.c
@@ -0,0 +1,52 @@
+/*
+ *  COPYRIGHT (c) 2010.
+ *  Cobham Gaisler AB.
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ */
+
+#include <bsp/apbuart.h>
+
+void apbuart_outbyte_polled(
+  struct apbuart_regs *regs,
+  unsigned char ch,
+  int do_cr_on_newline,
+  int wait_sent
+)
+{
+send:
+  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"::);
+  }
+
+  if ((ch == '\n') && do_cr_on_newline) {
+    regs->data = (unsigned int) '\r';
+    do_cr_on_newline = 0;
+    goto send;
+  }
+  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)
+{
+  /* Clear errors */
+  if (regs->status & APBUART_STATUS_ERR)
+    regs->status = ~APBUART_STATUS_ERR;
+
+  if ((regs->status & APBUART_STATUS_DR) == 0)
+    return -1;
+  else
+    return (int) regs->data;
+}
diff --git a/bsps/sparc/shared/uart/apbuart_termios.c b/bsps/sparc/shared/uart/apbuart_termios.c
index 28ece27..a4ecc74 100644
--- a/bsps/sparc/shared/uart/apbuart_termios.c
+++ b/bsps/sparc/shared/uart/apbuart_termios.c
@@ -242,58 +242,6 @@ static void apbuart_last_close_interrupt(
   rtems_interrupt_handler_remove(uart->irq, apbuart_isr, tty);
 }
 
-/*
- *  apbuart_outbyte_polled
- *
- *  This routine transmits a character using polling.
- */
-void apbuart_outbyte_polled(
-  struct apbuart_regs *regs,
-  unsigned char ch,
-  int do_cr_on_newline,
-  int wait_sent
-)
-{
-send:
-  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"::);
-  }
-
-  if ((ch == '\n') && do_cr_on_newline) {
-    regs->data = (unsigned int) '\r';
-    do_cr_on_newline = 0;
-    goto send;
-  }
-  regs->data = (unsigned int) ch;
-
-  /* Wait until the character has been sent? */
-  if (wait_sent) {
-    while ((regs->status & APBUART_STATUS_TE) == 0)
-      ;
-  }
-}
-
-/*
- *  apbuart_inbyte_nonblocking
- *
- *  This routine polls for a character.
- */
-int apbuart_inbyte_nonblocking(struct apbuart_regs *regs)
-{
-  /* Clear errors */
-  if (regs->status & APBUART_STATUS_ERR)
-    regs->status = ~APBUART_STATUS_ERR;
-
-  if ((regs->status & APBUART_STATUS_DR) == 0)
-    return -1;
-  else
-    return (int) regs->data;
-}
-
 const rtems_termios_device_handler apbuart_handler_interrupt = {
   .first_open = apbuart_first_open_interrupt,
   .last_close = apbuart_last_close_interrupt,
diff --git a/c/src/lib/libbsp/sparc/leon3/Makefile.am b/c/src/lib/libbsp/sparc/leon3/Makefile.am
index 6ab5c8a..9d7d59d 100644
--- a/c/src/lib/libbsp/sparc/leon3/Makefile.am
+++ b/c/src/lib/libbsp/sparc/leon3/Makefile.am
@@ -68,6 +68,8 @@ librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-termio
 librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/leon3/console/console.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/uart/cons.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/uart/apbuart_cons.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/uart/apbuart_polled.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/uart/apbuart_termios.c
 # debugio
 librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/leon3/console/printk_support.c
 
@@ -117,9 +119,6 @@ endif
 librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/spw/grspw_pkt.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/spw/grspw_router.c
 
-# UART
-librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/uart/apbuart_termios.c
-
 # I2CMST
 librtemsbsp_a_SOURCES += ../../../../../../bsps/sparc/shared/i2c/i2cmst.c
 



More information about the vc mailing list