diff options
Diffstat (limited to 'c/src/lib/libbsp/arm/edb7312/console/uart.c')
-rw-r--r-- | c/src/lib/libbsp/arm/edb7312/console/uart.c | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/arm/edb7312/console/uart.c b/c/src/lib/libbsp/arm/edb7312/console/uart.c new file mode 100644 index 0000000000..fb549d3905 --- /dev/null +++ b/c/src/lib/libbsp/arm/edb7312/console/uart.c @@ -0,0 +1,162 @@ +/* + * Cirrus EP7312 Console Driver + * + * Copyright (c) 2002 by Jay Monkman <jtm@smoothsmoothie.com> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * + * http://www.OARcorp.com/rtems/license.html. + * + * + * $Id$ +*/ +#include <bsp.h> /* Must be before libio.h */ +#include <rtems/libio.h> +#include <termios.h> +#include <rtems/bspIo.h> + +#include <ep7312.h> +#include <libchip/serial.h> +#include <libchip/sersupp.h> + +#define NUM_DEVS 1 +int uart_poll_read(int minor); + +static int uart_first_open(int major, int minor, void *arg); +static int uart_last_close(int major, int minor, void *arg); +static int uart_read(int minor); +static int uart_write(int minor, const char *buf, int len); +static void uart_init(int minor); +static void uart_write_polled(int minor, char c); +static int uart_set_attributes(int minor, const struct termios *t); + +unsigned long Console_Port_Count = NUM_DEVS; +console_data Console_Port_Data[NUM_DEVS]; +rtems_device_minor_number Console_Port_Minor = 0; +console_fns uart_fns = +{ + libchip_serial_default_probe, + uart_first_open, + uart_last_close, + uart_read, + uart_write, + uart_init, + uart_write_polled, + uart_set_attributes, + FALSE +}; +console_tbl Console_Port_Tbl[] = { + { + "/dev/com0", /* sDeviceName */ + SERIAL_CUSTOM, /* deviceType */ + &uart_fns, /* pDeviceFns */ + NULL, /* deviceProbe */ + NULL, /* pDeviceFlow */ + 16, /* ulMargin */ + 8, /* ulHysteresis */ + NULL, /* pDeviceParams */ + (unsigned32)EP7312_UARTCR1, /* ulCtrlPort1 */ + (unsigned32)EP7312_SYSFLG1, /* ulCtrlPort2 */ + (unsigned32)EP7312_UARTDR1, /* ulDataPort */ + 0, /* getRegister */ + 0, /* setRegister */ + 0, /* getData */ + 0, /* setData */ + 0, /* ulClock */ + 0 /* ulIntVector */ + }}; + +static int uart_first_open(int major, int minor, void *arg) {return 0;} +static int uart_last_close(int major, int minor, void *arg) {return 0;} +static int uart_read(int minor) +{ + return uart_poll_read(minor); +} + +static void uart_write_polled(int minor, char c) +{ + uart_write(minor, &c, 1); +} + +static int uart_set_attributes(int minor, const struct termios *t) +{ + return 0; +} + +int uart_poll_read(int minor) +{ + volatile unsigned32 *data_reg; + volatile unsigned32 *ctrl_reg1; + volatile unsigned32 *ctrl_reg2; + char c; + int err; + + data_reg = (unsigned32*)Console_Port_Tbl[minor].ulDataPort; + ctrl_reg1 = (unsigned32*)Console_Port_Tbl[minor].ulCtrlPort1; + ctrl_reg2 = (unsigned32*)Console_Port_Tbl[minor].ulCtrlPort2; + + if ((*ctrl_reg2 & EP7312_UART_URXFE1) != 0) { + return -1; + } + + + + err = *data_reg; + c = err & 0xff; + err &= (EP7312_UART_FRMERR | EP7312_UART_PARERR | EP7312_UART_OVERR); + + return c; +} + +static void _BSP_null_char( char c ) {uart_write_polled(0, c);} +BSP_output_char_function_type BSP_output_char = _BSP_null_char; + +static int uart_write(int minor, const char *buf, int len) +{ + volatile unsigned32 *data_reg; + volatile unsigned32 *ctrl_reg1; + volatile unsigned32 *ctrl_reg2; + int i; + char c; + + data_reg = (unsigned32*)Console_Port_Tbl[minor].ulDataPort; + ctrl_reg1 = (unsigned32*)Console_Port_Tbl[minor].ulCtrlPort1; + ctrl_reg2 = (unsigned32*)Console_Port_Tbl[minor].ulCtrlPort2; + + for (i = 0; i < len; i++) { + /* Wait for fifo to have room */ + while ((*ctrl_reg2 & EP7312_UART_UTXFF1) != 0) { + continue; + } + + c = (char) buf[i]; + *data_reg = c; + } + + return 1; +} + +static void uart_init(int minor) +{ + volatile unsigned32 *data_reg; + volatile unsigned32 *ctrl_reg1; + volatile unsigned32 *ctrl_reg2; + + data_reg = (unsigned32*)Console_Port_Tbl[minor].ulDataPort; + ctrl_reg1 = (unsigned32*)Console_Port_Tbl[minor].ulCtrlPort1; + ctrl_reg2 = (unsigned32*)Console_Port_Tbl[minor].ulCtrlPort2; + + /* *ctrl_reg = (BSP_UART_DATA8 | + BSP_UART_STOP1 | + BSP_UART_PARITY_NONE | + EP7312_UART_FIFOEN | + BSP_UART_BAUD_9600); + */ + *ctrl_reg1 = (EP7312_UART_WRDLEN8 | + EP7312_UART_FIFOEN | + 0x17); /* 9600 baud */ + + +} + |