[1d1b1507] | 1 | /* |
---|
| 2 | * This file contains the TTY driver for the serial ports on the erc32. |
---|
| 3 | * |
---|
| 4 | * This driver uses the termios pseudo driver. |
---|
| 5 | * |
---|
[08311cc3] | 6 | * COPYRIGHT (c) 1989-1999. |
---|
[1d1b1507] | 7 | * On-Line Applications Research Corporation (OAR). |
---|
| 8 | * |
---|
| 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
[98965056] | 11 | * http://www.rtems.com/license/LICENSE. |
---|
[1d1b1507] | 12 | * |
---|
| 13 | * $Id$ |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include <bsp.h> |
---|
| 17 | #include <rtems/libio.h> |
---|
| 18 | #include <stdlib.h> |
---|
| 19 | #include <assert.h> |
---|
[73c2d23] | 20 | #include <stdarg.h> |
---|
[1d1b1507] | 21 | |
---|
| 22 | /* |
---|
| 23 | * console_outbyte_polled |
---|
| 24 | * |
---|
| 25 | * This routine transmits a character using polling. |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | void console_outbyte_polled( |
---|
| 29 | int port, |
---|
[6de4727f] | 30 | unsigned char ch |
---|
[1d1b1507] | 31 | ) |
---|
| 32 | { |
---|
| 33 | if ( port == 0 ) { |
---|
| 34 | while ( (ERC32_MEC.UART_Status & ERC32_MEC_UART_STATUS_THEA) == 0 ); |
---|
[6de4727f] | 35 | ERC32_MEC.UART_Channel_A = (unsigned int) ch; |
---|
[1d1b1507] | 36 | return; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | while ( (ERC32_MEC.UART_Status & ERC32_MEC_UART_STATUS_THEB) == 0 ); |
---|
[6de4727f] | 40 | ERC32_MEC.UART_Channel_B = (unsigned int) ch; |
---|
[1d1b1507] | 41 | } |
---|
| 42 | |
---|
| 43 | /* |
---|
| 44 | * console_inbyte_nonblocking |
---|
| 45 | * |
---|
| 46 | * This routine polls for a character. |
---|
| 47 | */ |
---|
| 48 | |
---|
| 49 | int console_inbyte_nonblocking( int port ) |
---|
| 50 | { |
---|
| 51 | int UStat; |
---|
| 52 | |
---|
| 53 | UStat = ERC32_MEC.UART_Status; |
---|
| 54 | |
---|
| 55 | switch (port) { |
---|
| 56 | |
---|
| 57 | case 0: |
---|
| 58 | if (UStat & ERC32_MEC_UART_STATUS_ERRA) { |
---|
| 59 | ERC32_MEC.UART_Status = ERC32_MEC_UART_STATUS_CLRA; |
---|
| 60 | ERC32_MEC.Control = ERC32_MEC.Control; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | if ((UStat & ERC32_MEC_UART_STATUS_DRA) == 0) |
---|
| 64 | return -1; |
---|
| 65 | return (int) ERC32_MEC.UART_Channel_A; |
---|
| 66 | return 1; |
---|
| 67 | |
---|
| 68 | case 1: |
---|
| 69 | if (UStat & ERC32_MEC_UART_STATUS_ERRB) { |
---|
| 70 | ERC32_MEC.UART_Status = ERC32_MEC_UART_STATUS_CLRB; |
---|
| 71 | ERC32_MEC.Control = ERC32_MEC.Control; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | if ((UStat & ERC32_MEC_UART_STATUS_DRB) == 0) |
---|
| 75 | return -1; |
---|
| 76 | return (int) ERC32_MEC.UART_Channel_B; |
---|
| 77 | |
---|
| 78 | default: |
---|
| 79 | assert( 0 ); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | return -1; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | /* |
---|
| 86 | * DEBUG_puts |
---|
| 87 | * |
---|
| 88 | * This should be safe in the event of an error. It attempts to insure |
---|
| 89 | * that no TX empty interrupts occur while it is doing polled IO. Then |
---|
| 90 | * it restores the state of that external interrupt. |
---|
| 91 | * |
---|
| 92 | * Input parameters: |
---|
| 93 | * string - pointer to debug output string |
---|
| 94 | * |
---|
| 95 | * Output parameters: NONE |
---|
| 96 | * |
---|
| 97 | * Return values: NONE |
---|
| 98 | */ |
---|
| 99 | |
---|
| 100 | void DEBUG_puts( |
---|
| 101 | char *string |
---|
| 102 | ) |
---|
| 103 | { |
---|
| 104 | char *s; |
---|
| 105 | unsigned32 old_level; |
---|
| 106 | |
---|
| 107 | ERC32_Disable_interrupt( ERC32_INTERRUPT_UART_A_RX_TX, old_level ); |
---|
| 108 | for ( s = string ; *s ; s++ ) |
---|
| 109 | console_outbyte_polled( 0, *s ); |
---|
| 110 | |
---|
| 111 | console_outbyte_polled( 0, '\r' ); |
---|
| 112 | console_outbyte_polled( 0, '\n' ); |
---|
| 113 | ERC32_Restore_interrupt( ERC32_INTERRUPT_UART_A_RX_TX, old_level ); |
---|
| 114 | } |
---|