[rtems commit] bsp/leon2: Move printk() support

Sebastian Huber sebh at rtems.org
Wed Dec 5 12:06:25 UTC 2018


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Dec  5 13:02:59 2018 +0100

bsp/leon2: Move printk() support

Avoid assert() in console_inbyte_nonblocking().

Do not poll forever in bsp_in_char().  This allows the caller to decide
what to do if no character is available.

This entangles some dependencies and fixes a spconfig02 test failure.

---

 bsps/sparc/leon2/console/console.c   | 42 ---------------------
 bsps/sparc/leon2/console/debugputs.c | 73 +++++++++++++-----------------------
 bsps/sparc/leon2/include/bsp.h       |  4 ++
 3 files changed, 31 insertions(+), 88 deletions(-)

diff --git a/bsps/sparc/leon2/console/console.c b/bsps/sparc/leon2/console/console.c
index 611dbfa..4e8a42a 100644
--- a/bsps/sparc/leon2/console/console.c
+++ b/bsps/sparc/leon2/console/console.c
@@ -20,32 +20,9 @@
 
 #include <rtems/console.h>
 #include <rtems/libio.h>
-#include <rtems/bspIo.h>
 #include <bsp.h>
 
 /*
- *  console_outbyte_polled
- *
- *  This routine transmits a character using polling.
- */
-void console_outbyte_polled(
-  int           port,
-  unsigned char ch
-);
-
-/* body is in debugputs.c */
-
-/*
- *  console_inbyte_nonblocking
- *
- *  This routine polls for a character.
- */
-
-int console_inbyte_nonblocking( int port );
-
-/* body is in debugputs.c */
-
-/*
  *  Interrupt driven console IO
  */
 
@@ -416,22 +393,3 @@ rtems_device_driver console_control(
 {
   return rtems_termios_ioctl (arg);
 }
-
-/* putchar/getchar for printk */
-
-static void bsp_out_char (char c)
-{
-  console_outbyte_polled(0, c);
-}
-
-BSP_output_char_function_type BSP_output_char = bsp_out_char;
-
-static int bsp_in_char(void)
-{
-  int tmp;
-
-  while ((tmp = console_inbyte_nonblocking(0)) < 0);
-  return tmp;
-}
-
-BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char;
diff --git a/bsps/sparc/leon2/console/debugputs.c b/bsps/sparc/leon2/console/debugputs.c
index c5919f2..87567b0 100644
--- a/bsps/sparc/leon2/console/debugputs.c
+++ b/bsps/sparc/leon2/console/debugputs.c
@@ -18,26 +18,9 @@
  */
 
 #include <bsp.h>
-#include <rtems/libio.h>
-#include <stdlib.h>
-#include <assert.h>
+#include <rtems/bspIo.h>
 
-/*
- *  Method is shared with console.c
- */
-void console_outbyte_polled( int port, unsigned char ch );
-int console_inbyte_nonblocking( int port );
-
-/*
- *  console_outbyte_polled
- *
- *  This routine transmits a character using polling.
- */
-
-void console_outbyte_polled(
-  int  port,
-  unsigned char ch
-)
+void console_outbyte_polled( int port, unsigned char ch )
 {
   if ( port == 0 ) {
     while ( (LEON_REG.UART_Status_1 & LEON_REG_UART_STATUS_THE) == 0 );
@@ -49,39 +32,37 @@ void console_outbyte_polled(
   LEON_REG.UART_Channel_2 = (unsigned int) ch;
 }
 
-/*
- *  console_inbyte_nonblocking
- *
- *  This routine polls for a character.
- */
-
 int console_inbyte_nonblocking( int port )
 {
+  if ( port == 0 ) {
+    if (LEON_REG.UART_Status_1 & LEON_REG_UART_STATUS_ERR) {
+      LEON_REG.UART_Status_1 = ~LEON_REG_UART_STATUS_ERR;
+    }
 
-  switch (port) {
-
-    case 0:
-      if (LEON_REG.UART_Status_1 & LEON_REG_UART_STATUS_ERR) {
-        LEON_REG.UART_Status_1 = ~LEON_REG_UART_STATUS_ERR;
-      }
+    if ((LEON_REG.UART_Status_1 & LEON_REG_UART_STATUS_DR) == 0)
+       return -1;
+    return (int) LEON_REG.UART_Channel_1;
+  }
 
-      if ((LEON_REG.UART_Status_1 & LEON_REG_UART_STATUS_DR) == 0)
-         return -1;
-      return (int) LEON_REG.UART_Channel_1;
-      return 1;
+  if (LEON_REG.UART_Status_2 & LEON_REG_UART_STATUS_ERR) {
+    LEON_REG.UART_Status_2 = ~LEON_REG_UART_STATUS_ERR;
+  }
 
-    case 1:
-      if (LEON_REG.UART_Status_2 & LEON_REG_UART_STATUS_ERR) {
-        LEON_REG.UART_Status_2 = ~LEON_REG_UART_STATUS_ERR;
-      }
+  if ((LEON_REG.UART_Status_2 & LEON_REG_UART_STATUS_DR) == 0)
+     return -1;
+  return (int) LEON_REG.UART_Channel_2;
+}
 
-      if ((LEON_REG.UART_Status_2 & LEON_REG_UART_STATUS_DR) == 0)
-         return -1;
-      return (int) LEON_REG.UART_Channel_2;
+static void bsp_out_char( char c )
+{
+  console_outbyte_polled( 0, c );
+}
 
-    default:
-      assert( 0 );
-  }
+BSP_output_char_function_type BSP_output_char = bsp_out_char;
 
-  return -1;
+static int bsp_in_char( void )
+{
+  return console_inbyte_nonblocking( 0 );
 }
+
+BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char;
diff --git a/bsps/sparc/leon2/include/bsp.h b/bsps/sparc/leon2/include/bsp.h
index 2028ba0..e9b9849 100644
--- a/bsps/sparc/leon2/include/bsp.h
+++ b/bsps/sparc/leon2/include/bsp.h
@@ -213,6 +213,10 @@ int cchip1_register(void);
 #define GPTIMER_INFO_AVAIL            /* GPTIMER Timer driver */
 #define GRETH_INFO_AVAIL              /* GRETH Ethernet driver */
 
+void console_outbyte_polled( int port, unsigned char ch );
+
+int console_inbyte_nonblocking( int port );
+
 #ifdef __cplusplus
 }
 #endif




More information about the vc mailing list