[ac7d5ef0] | 1 | /* |
---|
| 2 | * This file contains the MVME136 console IO package. |
---|
| 3 | * |
---|
| 4 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * All rights assigned to U.S. Government, 1994. |
---|
| 7 | * |
---|
| 8 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 9 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 10 | * notice must appear in all copies of this file and its derivatives. |
---|
| 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define C961_INIT |
---|
| 16 | |
---|
| 17 | #include <rtems.h> |
---|
| 18 | #include "console.h" |
---|
| 19 | #include "bsp.h" |
---|
| 20 | |
---|
| 21 | /* console_initialize |
---|
| 22 | * |
---|
| 23 | * This routine initializes the console IO driver. |
---|
| 24 | * |
---|
| 25 | * Input parameters: NONE |
---|
| 26 | * |
---|
| 27 | * Output parameters: NONE |
---|
| 28 | * |
---|
| 29 | * Return values: |
---|
| 30 | */ |
---|
| 31 | |
---|
| 32 | rtems_device_driver console_initialize( |
---|
| 33 | rtems_device_major_number major, |
---|
| 34 | rtems_device_minor_number minor, |
---|
| 35 | void *arg, |
---|
| 36 | rtems_id self, |
---|
| 37 | rtems_unsigned32 *status |
---|
| 38 | ) |
---|
| 39 | { |
---|
| 40 | *status = RTEMS_SUCCESSFUL; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | /* |
---|
| 44 | * NINDY_IO( ... ) |
---|
| 45 | * |
---|
| 46 | * Interface to NINDY. |
---|
| 47 | */ |
---|
| 48 | |
---|
| 49 | #define NINDY_INPUT 0 |
---|
| 50 | #define NINDY_OUTPUT 1 |
---|
| 51 | |
---|
| 52 | void NINDY_IO(); |
---|
| 53 | |
---|
| 54 | void ___NINDY_IO_WRAPPER( void ) /* never called */ |
---|
| 55 | { |
---|
| 56 | asm volatile ( " .text" ); |
---|
| 57 | asm volatile ( " .align 4" ); |
---|
| 58 | asm volatile ( " .globl _NINDY_IO" ); |
---|
| 59 | asm volatile ( "_NINDY_IO:" ); |
---|
| 60 | asm volatile ( " calls 0 /* call console routines */" ); |
---|
| 61 | asm volatile ( " ret" ); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /* inbyte |
---|
| 65 | * |
---|
| 66 | * This routine reads a character from the console using NINDY. |
---|
| 67 | * |
---|
| 68 | * Input parameters: NONE |
---|
| 69 | * |
---|
| 70 | * Output parameters: NONE |
---|
| 71 | * |
---|
| 72 | * Return values: |
---|
| 73 | * character read from UART |
---|
| 74 | */ |
---|
| 75 | |
---|
| 76 | char inbyte( void ) |
---|
| 77 | { |
---|
| 78 | char ch; |
---|
| 79 | |
---|
| 80 | NINDY_IO( NINDY_INPUT, &ch ); |
---|
| 81 | return ch; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | /* outbyte |
---|
| 86 | * |
---|
| 87 | * This routine transmits a character out the console using NINDY. |
---|
| 88 | * |
---|
| 89 | * Input parameters: |
---|
| 90 | * ch - character to be transmitted |
---|
| 91 | * |
---|
| 92 | * Output parameters: NONE |
---|
| 93 | */ |
---|
| 94 | |
---|
| 95 | void outbyte( |
---|
| 96 | char ch |
---|
| 97 | ) |
---|
| 98 | { |
---|
| 99 | NINDY_IO( NINDY_OUTPUT, ch ); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | /* |
---|
| 103 | * __read -- read bytes from the serial port. Ignore fd, since |
---|
| 104 | * we only have stdin. |
---|
| 105 | */ |
---|
| 106 | |
---|
| 107 | int __read( |
---|
| 108 | int fd, |
---|
| 109 | char *buf, |
---|
| 110 | int nbytes |
---|
| 111 | ) |
---|
| 112 | { |
---|
| 113 | int i = 0; |
---|
| 114 | |
---|
| 115 | for (i = 0; i < nbytes; i++) { |
---|
| 116 | *(buf + i) = inbyte(); |
---|
| 117 | if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) { |
---|
| 118 | (*(buf + i++)) = '\n'; |
---|
| 119 | (*(buf + i)) = 0; |
---|
| 120 | break; |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | return (i); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | /* |
---|
| 127 | * __write -- write bytes to the serial port. Ignore fd, since |
---|
| 128 | * stdout and stderr are the same. Since we have no filesystem, |
---|
| 129 | * open will only return an error. |
---|
| 130 | */ |
---|
| 131 | |
---|
| 132 | int __write( |
---|
| 133 | int fd, |
---|
| 134 | char *buf, |
---|
| 135 | int nbytes |
---|
| 136 | ) |
---|
| 137 | { |
---|
| 138 | int i; |
---|
| 139 | |
---|
| 140 | for (i = 0; i < nbytes; i++) { |
---|
| 141 | if (*(buf + i) == '\n') { |
---|
| 142 | outbyte ('\r'); |
---|
| 143 | } |
---|
| 144 | outbyte (*(buf + i)); |
---|
| 145 | } |
---|
| 146 | return (nbytes); |
---|
| 147 | } |
---|