summaryrefslogtreecommitdiff
path: root/cpu/nios/serial.c
diff options
context:
space:
mode:
authorwdenk <wdenk>2004-05-19 21:33:14 +0000
committerwdenk <wdenk>2004-05-19 21:33:14 +0000
commite4cc71aa4403c82f0b3e89087024f83832ece9ec (patch)
tree48c8295c714dfbfe7be70796c87b41c2065f166f /cpu/nios/serial.c
parent10767ccb86e0413633e7d89fbbb354014288b036 (diff)
downloadu-boot-imx-e4cc71aa4403c82f0b3e89087024f83832ece9ec.zip
u-boot-imx-e4cc71aa4403c82f0b3e89087024f83832ece9ec.tar.gz
u-boot-imx-e4cc71aa4403c82f0b3e89087024f83832ece9ec.tar.bz2
Patch by Scott McNutt, 25 Apr 2004:
Add Nios GDB/JTAG Console support: - Add stubs to support gdb via JTAG. - Add support for console over JTAG. - Minor cleanup.
Diffstat (limited to 'cpu/nios/serial.c')
-rw-r--r--cpu/nios/serial.c79
1 files changed, 63 insertions, 16 deletions
diff --git a/cpu/nios/serial.c b/cpu/nios/serial.c
index 34257a2..4bdda25 100644
--- a/cpu/nios/serial.c
+++ b/cpu/nios/serial.c
@@ -26,6 +26,48 @@
#include <watchdog.h>
#include <nios-io.h>
+/*------------------------------------------------------------------
+ * JTAG acts as the serial port
+ *-----------------------------------------------------------------*/
+#if defined(CONFIG_CONSOLE_JTAG)
+
+static nios_jtag_t *jtag = (nios_jtag_t *)CFG_NIOS_CONSOLE;
+
+void serial_setbrg( void ){ return; }
+int serial_init( void ) { return(0);}
+
+void serial_putc (char c)
+{
+ while ((jtag->txcntl & NIOS_JTAG_TRDY) != 0)
+ WATCHDOG_RESET ();
+ jtag->txcntl = NIOS_JTAG_TRDY | (unsigned char)c;
+}
+
+void serial_puts (const char *s)
+{
+ while (*s != 0)
+ serial_putc (*s++);
+}
+
+int serial_tstc (void)
+{
+ return (jtag->rxcntl & NIOS_JTAG_RRDY);
+}
+
+int serial_getc (void)
+{
+ int c;
+ while (serial_tstc() == 0)
+ WATCHDOG_RESET ();
+ c = jtag->rxcntl & 0x0ff;
+ jtag->rxcntl = 0;
+ return (c);
+}
+
+/*------------------------------------------------------------------
+ * UART the serial port
+ *-----------------------------------------------------------------*/
+#else
static nios_uart_t *uart = (nios_uart_t *)CFG_NIOS_CONSOLE;
@@ -34,12 +76,12 @@ static nios_uart_t *uart = (nios_uart_t *)CFG_NIOS_CONSOLE;
/* Everything's already setup for fixed-baud PTF
* assignment
*/
-void serial_setbrg( void ){ return; }
-int serial_init( void ) { return(0);}
+void serial_setbrg (void){ return; }
+int serial_init (void) { return (0);}
#else
-void serial_setbrg( void )
+void serial_setbrg (void)
{
DECLARE_GLOBAL_DATA_PTR;
unsigned div;
@@ -49,39 +91,44 @@ void serial_setbrg( void )
return;
}
-int serial_init( void )
+int serial_init (void)
{
- serial_setbrg();
- return(0);
+ serial_setbrg ();
+ return (0);
}
#endif /* CFG_NIOS_FIXEDBAUD */
-void serial_putc( char c )
+/*-----------------------------------------------------------------------
+ * UART CONSOLE
+ *---------------------------------------------------------------------*/
+void serial_putc (char c)
{
if (c == '\n')
- serial_putc('\r');
- while( (uart->status & NIOS_UART_TRDY) == 0 )
+ serial_putc ('\r');
+ while ((uart->status & NIOS_UART_TRDY) == 0)
WATCHDOG_RESET ();
uart->txdata = (unsigned char)c;
}
-void serial_puts( const char *s )
+void serial_puts (const char *s)
{
- while( *s != 0 ) {
- serial_putc( *s++ );
+ while (*s != 0) {
+ serial_putc (*s++);
}
}
-int serial_tstc( void )
+int serial_tstc (void)
{
- return( uart->status & NIOS_UART_RRDY);
+ return (uart->status & NIOS_UART_RRDY);
}
-int serial_getc( void )
+int serial_getc (void)
{
- while( serial_tstc() == 0 )
+ while (serial_tstc () == 0)
WATCHDOG_RESET ();
return( uart->rxdata & 0x00ff );
}
+
+#endif /* CONFIG_JTAG_CONSOLE */