[PATCH 29] LEON3: console use register pointers instead of UART indexes
Daniel Hellstrom
daniel at gaisler.com
Thu Apr 5 15:23:19 UTC 2012
Signed-off-by: Daniel Hellstrom <daniel at gaisler.com>
---
c/src/lib/libbsp/sparc/leon3/console/console.c | 16 ++++----
c/src/lib/libbsp/sparc/leon3/console/debugputs.c | 50 +++++++++++-----------
2 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/c/src/lib/libbsp/sparc/leon3/console/console.c b/c/src/lib/libbsp/sparc/leon3/console/console.c
index a07fb15..320aa37 100644
--- a/c/src/lib/libbsp/sparc/leon3/console/console.c
+++ b/c/src/lib/libbsp/sparc/leon3/console/console.c
@@ -40,13 +40,13 @@ int syscon_uart_index __attribute__((weak)) = 0;
*/
/*
- * console_outbyte_polled
+ * apbuart_outbyte_polled
*
* This routine transmits a character using polling.
*/
-void console_outbyte_polled(
- int port,
+extern void apbuart_outbyte_polled(
+ ambapp_apb_uart *regs,
char ch
);
@@ -58,7 +58,7 @@ void console_outbyte_polled(
* This routine polls for a character.
*/
-int apbuart_inbyte_nonblocking(int port);
+extern int apbuart_inbyte_nonblocking(ambapp_apb_uart *regs);
/* body is in debugputs.c */
@@ -78,13 +78,13 @@ ssize_t console_write_support (int minor, const char *buf, size_t len)
port = minor - 1;
while (nwrite < len) {
- console_outbyte_polled(port, *buf++);
+ apbuart_outbyte_polled((ambapp_apb_uart*)LEON3_Console_Uart[port], *buf++);
nwrite++;
}
return nwrite;
}
-int console_inbyte_nonblocking(int minor)
+int console_pollRead(int minor)
{
int port;
@@ -93,7 +93,7 @@ int console_inbyte_nonblocking(int minor)
else
port = minor - 1;
- return apbuart_inbyte_nonblocking(port);
+ return apbuart_inbyte_nonblocking((ambapp_apb_uart*)LEON3_Console_Uart[port]);
}
/*
@@ -168,7 +168,7 @@ rtems_device_driver console_open(
static const rtems_termios_callbacks pollCallbacks = {
NULL, /* firstOpen */
NULL, /* lastClose */
- console_inbyte_nonblocking, /* pollRead */
+ console_pollRead, /* pollRead */
console_write_support, /* write */
NULL, /* setAttributes */
NULL, /* stopRemoteTx */
diff --git a/c/src/lib/libbsp/sparc/leon3/console/debugputs.c b/c/src/lib/libbsp/sparc/leon3/console/debugputs.c
index cf3f280..43c6d7d 100644
--- a/c/src/lib/libbsp/sparc/leon3/console/debugputs.c
+++ b/c/src/lib/libbsp/sparc/leon3/console/debugputs.c
@@ -21,6 +21,7 @@
#include <rtems/libio.h>
#include <stdlib.h>
#include <assert.h>
+#include <stdio.h>
/*
* Number of uarts on AMBA bus
@@ -37,6 +38,7 @@ static int isinit = 0;
* ...
*/
int debug_uart_index __attribute__((weak)) = 0;
+ambapp_apb_uart *dbg_uart = NULL;
/*
* Scan for UARTS in configuration
@@ -74,9 +76,9 @@ int scan_uarts(void)
/* initialize debug uart if present for printk */
if (debug_uart_index < uarts) {
- LEON3_Console_Uart[debug_uart_index]->ctrl |= LEON_REG_UART_CTRL_RE |
- LEON_REG_UART_CTRL_TE;
- LEON3_Console_Uart[debug_uart_index]->status = 0;
+ dbg_uart = (ambapp_apb_uart *)LEON3_Console_Uart[debug_uart_index];
+ dbg_uart->ctrl |= LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE;
+ dbg_uart->status = 0;
}
isinit = 1;
}
@@ -85,48 +87,43 @@ int scan_uarts(void)
}
/*
- * console_outbyte_polled
+ * apbuart_outbyte_polled
*
* This routine transmits a character using polling.
*/
-void console_outbyte_polled(
- int port,
+void apbuart_outbyte_polled(
+ ambapp_apb_uart *regs,
unsigned char ch
)
{
- if ((port >= 0) && (port < uarts)) {
- return;
-
- while ( (LEON3_Console_Uart[port]->status & LEON_REG_UART_STATUS_THE) == 0 );
- LEON3_Console_Uart[port]->data = (unsigned int) ch;
+ while ( (regs->status & LEON_REG_UART_STATUS_THE) == 0 );
+ regs->data = (unsigned int) ch;
}
/*
- * console_inbyte_nonblocking
+ * apbuart_inbyte_nonblocking
*
* This routine polls for a character.
*/
-int apbuart_inbyte_nonblocking(int port)
+int apbuart_inbyte_nonblocking(ambapp_apb_uart *regs)
{
- if ((port >= 0) && (port < uarts)) {
- assert( 0 );
- return -1;
- }
-
/* Clear errors */
- if (LEON3_Console_Uart[port]->status & LEON_REG_UART_STATUS_ERR)
- LEON3_Console_Uart[port]->status = ~LEON_REG_UART_STATUS_ERR;
+ if (regs->status & LEON_REG_UART_STATUS_ERR)
+ regs->status = ~LEON_REG_UART_STATUS_ERR;
- if ((LEON3_Console_Uart[port]->status & LEON_REG_UART_STATUS_DR) == 0)
- return -1;
+ if ((regs->status & LEON_REG_UART_STATUS_DR) == 0)
+ return EOF;
else
- return (int) LEON3_Console_Uart[port]->data;
+ return (int) regs->data;
}
/* putchar/getchar for printk */
static void bsp_out_char(char c)
{
- console_outbyte_polled(debug_uart_index, c);
+ if (dbg_uart == NULL)
+ return;
+
+ apbuart_outbyte_polled(dbg_uart, c);
}
/*
@@ -141,7 +138,10 @@ static int bsp_in_char(void)
{
int tmp;
- while ((tmp = apbuart_inbyte_nonblocking(debug_uart_index)) < 0)
+ if (dbg_uart == NULL)
+ return EOF;
+
+ while ((tmp = apbuart_inbyte_nonblocking(dbg_uart)) < 0)
;
return tmp;
}
--
1.7.0.4
More information about the devel
mailing list