[41c9282] | 1 | /* |
---|
| 2 | * This file contains the TTY driver for the serial ports on the LEON. |
---|
| 3 | * |
---|
| 4 | * This driver uses the termios pseudo driver. |
---|
| 5 | * |
---|
| 6 | * COPYRIGHT (c) 1989-1999. |
---|
| 7 | * On-Line Applications Research Corporation (OAR). |
---|
| 8 | * |
---|
| 9 | * Modified for LEON3 BSP. |
---|
| 10 | * COPYRIGHT (c) 2004. |
---|
| 11 | * Gaisler Research. |
---|
| 12 | * |
---|
| 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
| 15 | * http://www.rtems.com/license/LICENSE. |
---|
| 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #include <bsp.h> |
---|
| 21 | #include <rtems/libio.h> |
---|
| 22 | #include <stdlib.h> |
---|
| 23 | #include <assert.h> |
---|
| 24 | |
---|
| 25 | /* |
---|
| 26 | * console_outbyte_polled |
---|
| 27 | * |
---|
| 28 | * This routine transmits a character using polling. |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | void console_outbyte_polled( |
---|
| 32 | int port, |
---|
| 33 | unsigned char ch |
---|
| 34 | ) |
---|
| 35 | { |
---|
| 36 | if ((port >= 0) && (port <= CONFIGURE_NUMBER_OF_TERMIOS_PORTS)) |
---|
| 37 | { |
---|
[28f3f511] | 38 | while ( (LEON3_Console_Uart[LEON3_Cpu_Index+port]->status & |
---|
| 39 | LEON_REG_UART_STATUS_THE) == 0 ); |
---|
| 40 | LEON3_Console_Uart[LEON3_Cpu_Index+port]->data = (unsigned int) ch; |
---|
[41c9282] | 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | /* |
---|
| 45 | * console_inbyte_nonblocking |
---|
| 46 | * |
---|
| 47 | * This routine polls for a character. |
---|
| 48 | */ |
---|
| 49 | |
---|
| 50 | int console_inbyte_nonblocking( int port ) |
---|
| 51 | { |
---|
| 52 | |
---|
| 53 | if ((port >=0) && (port < CONFIGURE_NUMBER_OF_TERMIOS_PORTS)) |
---|
| 54 | { |
---|
| 55 | |
---|
[28f3f511] | 56 | if (LEON3_Console_Uart[LEON3_Cpu_Index+port]->status & LEON_REG_UART_STATUS_ERR) { |
---|
| 57 | LEON3_Console_Uart[LEON3_Cpu_Index+port]->status = ~LEON_REG_UART_STATUS_ERR; |
---|
[41c9282] | 58 | } |
---|
| 59 | |
---|
[28f3f511] | 60 | if ((LEON3_Console_Uart[LEON3_Cpu_Index+port]->status & LEON_REG_UART_STATUS_DR) == 0) |
---|
[41c9282] | 61 | return -1; |
---|
[28f3f511] | 62 | return (int) LEON3_Console_Uart[LEON3_Cpu_Index+port]->data; |
---|
[41c9282] | 63 | } |
---|
| 64 | |
---|
| 65 | else |
---|
| 66 | { |
---|
| 67 | assert( 0 ); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | return -1; |
---|
| 71 | } |
---|
[344ba65a] | 72 | |
---|
| 73 | /* putchar/getchar for printk */ |
---|
| 74 | |
---|
| 75 | static void bsp_out_char(char c) |
---|
| 76 | { |
---|
| 77 | console_outbyte_polled(0, c); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | BSP_output_char_function_type BSP_output_char = bsp_out_char; |
---|
| 81 | |
---|
| 82 | static char bsp_in_char(void) |
---|
| 83 | { |
---|
| 84 | int tmp; |
---|
| 85 | |
---|
| 86 | while ((tmp = console_inbyte_nonblocking(0)) < 0); |
---|
| 87 | return (char) tmp; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char; |
---|