LEON3: console use register pointers instead of UART indexes

Signed-off-by: Daniel Hellstrom <daniel@gaisler.com>
This commit is contained in:
Daniel Hellstrom
2012-04-05 10:23:19 -05:00
committed by Joel Sherrill
parent 4b557617fd
commit e60e862c64
2 changed files with 33 additions and 33 deletions

View File

@@ -40,13 +40,13 @@ int syscon_uart_index __attribute__((weak)) = 0;
*/ */
/* /*
* console_outbyte_polled * apbuart_outbyte_polled
* *
* This routine transmits a character using polling. * This routine transmits a character using polling.
*/ */
void console_outbyte_polled( extern void apbuart_outbyte_polled(
int port, ambapp_apb_uart *regs,
char ch char ch
); );
@@ -58,7 +58,7 @@ void console_outbyte_polled(
* This routine polls for a character. * 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 */ /* 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; port = minor - 1;
while (nwrite < len) { while (nwrite < len) {
console_outbyte_polled(port, *buf++); apbuart_outbyte_polled((ambapp_apb_uart*)LEON3_Console_Uart[port], *buf++);
nwrite++; nwrite++;
} }
return nwrite; return nwrite;
} }
int console_inbyte_nonblocking(int minor) int console_pollRead(int minor)
{ {
int port; int port;
@@ -93,7 +93,7 @@ int console_inbyte_nonblocking(int minor)
else else
port = minor - 1; 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 = { static const rtems_termios_callbacks pollCallbacks = {
NULL, /* firstOpen */ NULL, /* firstOpen */
NULL, /* lastClose */ NULL, /* lastClose */
console_inbyte_nonblocking, /* pollRead */ console_pollRead, /* pollRead */
console_write_support, /* write */ console_write_support, /* write */
NULL, /* setAttributes */ NULL, /* setAttributes */
NULL, /* stopRemoteTx */ NULL, /* stopRemoteTx */

View File

@@ -21,6 +21,7 @@
#include <rtems/libio.h> #include <rtems/libio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
/* /*
* Number of uarts on AMBA bus * Number of uarts on AMBA bus
@@ -37,6 +38,7 @@ static int isinit = 0;
* ... * ...
*/ */
int debug_uart_index __attribute__((weak)) = 0; int debug_uart_index __attribute__((weak)) = 0;
ambapp_apb_uart *dbg_uart = NULL;
/* /*
* Scan for UARTS in configuration * Scan for UARTS in configuration
@@ -74,9 +76,9 @@ int scan_uarts(void)
/* initialize debug uart if present for printk */ /* initialize debug uart if present for printk */
if (debug_uart_index < uarts) { if (debug_uart_index < uarts) {
LEON3_Console_Uart[debug_uart_index]->ctrl |= LEON_REG_UART_CTRL_RE | dbg_uart = (ambapp_apb_uart *)LEON3_Console_Uart[debug_uart_index];
LEON_REG_UART_CTRL_TE; dbg_uart->ctrl |= LEON_REG_UART_CTRL_RE | LEON_REG_UART_CTRL_TE;
LEON3_Console_Uart[debug_uart_index]->status = 0; dbg_uart->status = 0;
} }
isinit = 1; isinit = 1;
} }
@@ -85,48 +87,43 @@ int scan_uarts(void)
} }
/* /*
* console_outbyte_polled * apbuart_outbyte_polled
* *
* This routine transmits a character using polling. * This routine transmits a character using polling.
*/ */
void console_outbyte_polled( void apbuart_outbyte_polled(
int port, ambapp_apb_uart *regs,
unsigned char ch unsigned char ch
) )
{ {
if ((port >= 0) && (port < uarts)) { while ( (regs->status & LEON_REG_UART_STATUS_THE) == 0 );
return; regs->data = (unsigned int) ch;
while ( (LEON3_Console_Uart[port]->status & LEON_REG_UART_STATUS_THE) == 0 );
LEON3_Console_Uart[port]->data = (unsigned int) ch;
} }
/* /*
* console_inbyte_nonblocking * apbuart_inbyte_nonblocking
* *
* This routine polls for a character. * 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 */ /* Clear errors */
if (LEON3_Console_Uart[port]->status & LEON_REG_UART_STATUS_ERR) if (regs->status & LEON_REG_UART_STATUS_ERR)
LEON3_Console_Uart[port]->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) if ((regs->status & LEON_REG_UART_STATUS_DR) == 0)
return -1; return EOF;
else else
return (int) LEON3_Console_Uart[port]->data; return (int) regs->data;
} }
/* putchar/getchar for printk */ /* putchar/getchar for printk */
static void bsp_out_char(char c) 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; 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; return tmp;
} }