1 | /** |
---|
2 | * @file |
---|
3 | * @ingroup sparc_leon2 |
---|
4 | * @brief TTY driver for the serial ports on the LEON |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * This file contains the TTY driver for the serial ports on the LEON. |
---|
9 | * |
---|
10 | * This driver uses the termios pseudo driver. |
---|
11 | * |
---|
12 | * COPYRIGHT (c) 1989-1999. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.com/license/LICENSE. |
---|
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 ) { |
---|
37 | while ( (LEON_REG.UART_Status_1 & LEON_REG_UART_STATUS_THE) == 0 ); |
---|
38 | LEON_REG.UART_Channel_1 = (unsigned int) ch; |
---|
39 | return; |
---|
40 | } |
---|
41 | |
---|
42 | while ( (LEON_REG.UART_Status_2 & LEON_REG_UART_STATUS_THE) == 0 ); |
---|
43 | LEON_REG.UART_Channel_2 = (unsigned int) ch; |
---|
44 | } |
---|
45 | |
---|
46 | /* |
---|
47 | * console_inbyte_nonblocking |
---|
48 | * |
---|
49 | * This routine polls for a character. |
---|
50 | */ |
---|
51 | |
---|
52 | int console_inbyte_nonblocking( int port ) |
---|
53 | { |
---|
54 | |
---|
55 | switch (port) { |
---|
56 | |
---|
57 | case 0: |
---|
58 | if (LEON_REG.UART_Status_1 & LEON_REG_UART_STATUS_ERR) { |
---|
59 | LEON_REG.UART_Status_1 = ~LEON_REG_UART_STATUS_ERR; |
---|
60 | } |
---|
61 | |
---|
62 | if ((LEON_REG.UART_Status_1 & LEON_REG_UART_STATUS_DR) == 0) |
---|
63 | return -1; |
---|
64 | return (int) LEON_REG.UART_Channel_1; |
---|
65 | return 1; |
---|
66 | |
---|
67 | case 1: |
---|
68 | if (LEON_REG.UART_Status_2 & LEON_REG_UART_STATUS_ERR) { |
---|
69 | LEON_REG.UART_Status_2 = ~LEON_REG_UART_STATUS_ERR; |
---|
70 | } |
---|
71 | |
---|
72 | if ((LEON_REG.UART_Status_2 & LEON_REG_UART_STATUS_DR) == 0) |
---|
73 | return -1; |
---|
74 | return (int) LEON_REG.UART_Channel_2; |
---|
75 | |
---|
76 | default: |
---|
77 | assert( 0 ); |
---|
78 | } |
---|
79 | |
---|
80 | return -1; |
---|
81 | } |
---|