2003-10-08 23:26:14 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2003, Psyent Corporation <www.psyent.com>
|
|
|
|
* Scott McNutt <smcnutt@psyent.com>
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <common.h>
|
2004-02-23 23:54:43 +00:00
|
|
|
#include <watchdog.h>
|
2003-10-08 23:26:14 +00:00
|
|
|
#include <nios-io.h>
|
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2004-05-19 21:33:14 +00:00
|
|
|
/*------------------------------------------------------------------
|
|
|
|
* 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
|
2003-10-08 23:26:14 +00:00
|
|
|
|
|
|
|
static nios_uart_t *uart = (nios_uart_t *)CFG_NIOS_CONSOLE;
|
|
|
|
|
|
|
|
#if defined(CFG_NIOS_FIXEDBAUD)
|
|
|
|
|
|
|
|
/* Everything's already setup for fixed-baud PTF
|
|
|
|
* assignment
|
|
|
|
*/
|
2004-05-19 21:33:14 +00:00
|
|
|
void serial_setbrg (void){ return; }
|
|
|
|
int serial_init (void) { return (0);}
|
2003-10-08 23:26:14 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2004-05-19 21:33:14 +00:00
|
|
|
void serial_setbrg (void)
|
2003-10-08 23:26:14 +00:00
|
|
|
{
|
|
|
|
unsigned div;
|
|
|
|
|
|
|
|
div = (CONFIG_SYS_CLK_FREQ/gd->baudrate)-1;
|
|
|
|
uart->divisor = div;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-19 21:33:14 +00:00
|
|
|
int serial_init (void)
|
2003-10-08 23:26:14 +00:00
|
|
|
{
|
2004-05-19 21:33:14 +00:00
|
|
|
serial_setbrg ();
|
|
|
|
return (0);
|
2003-10-08 23:26:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CFG_NIOS_FIXEDBAUD */
|
|
|
|
|
|
|
|
|
2004-05-19 21:33:14 +00:00
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
* UART CONSOLE
|
|
|
|
*---------------------------------------------------------------------*/
|
|
|
|
void serial_putc (char c)
|
2003-10-08 23:26:14 +00:00
|
|
|
{
|
|
|
|
if (c == '\n')
|
2004-05-19 21:33:14 +00:00
|
|
|
serial_putc ('\r');
|
|
|
|
while ((uart->status & NIOS_UART_TRDY) == 0)
|
2004-02-23 23:54:43 +00:00
|
|
|
WATCHDOG_RESET ();
|
2003-10-08 23:26:14 +00:00
|
|
|
uart->txdata = (unsigned char)c;
|
|
|
|
}
|
|
|
|
|
2004-05-19 21:33:14 +00:00
|
|
|
void serial_puts (const char *s)
|
2003-10-08 23:26:14 +00:00
|
|
|
{
|
2004-05-19 21:33:14 +00:00
|
|
|
while (*s != 0) {
|
|
|
|
serial_putc (*s++);
|
2003-10-08 23:26:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-19 21:33:14 +00:00
|
|
|
int serial_tstc (void)
|
2003-10-08 23:26:14 +00:00
|
|
|
{
|
2004-05-19 21:33:14 +00:00
|
|
|
return (uart->status & NIOS_UART_RRDY);
|
2003-10-08 23:26:14 +00:00
|
|
|
}
|
|
|
|
|
2004-05-19 21:33:14 +00:00
|
|
|
int serial_getc (void)
|
2003-10-08 23:26:14 +00:00
|
|
|
{
|
2004-05-19 21:33:14 +00:00
|
|
|
while (serial_tstc () == 0)
|
2004-02-23 23:54:43 +00:00
|
|
|
WATCHDOG_RESET ();
|
2003-10-08 23:26:14 +00:00
|
|
|
return( uart->rxdata & 0x00ff );
|
|
|
|
}
|
2004-05-19 21:33:14 +00:00
|
|
|
|
|
|
|
#endif /* CONFIG_JTAG_CONSOLE */
|