aboutsummaryrefslogtreecommitdiff
path: root/cpu/nios/serial.c
diff options
context:
space:
mode:
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 34257a2fe..4bdda2500 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 */