[ac7d5ef0] | 1 | /* |
---|
[3a4ae6c] | 2 | * This file contains the CVME961 console IO package. |
---|
[ac7d5ef0] | 3 | * |
---|
[03f2154e] | 4 | * COPYRIGHT (c) 1989-1997. |
---|
[ac7d5ef0] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 6 | * Copyright assigned to U.S. Government, 1994. |
---|
[ac7d5ef0] | 7 | * |
---|
[98e4ebf5] | 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 10 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define C961_INIT |
---|
| 16 | |
---|
[3a4ae6c] | 17 | #include <bsp.h> |
---|
| 18 | #include <rtems/libio.h> |
---|
[ac7d5ef0] | 19 | |
---|
| 20 | /* console_initialize |
---|
| 21 | * |
---|
| 22 | * This routine initializes the console IO driver. |
---|
| 23 | * |
---|
| 24 | * Input parameters: NONE |
---|
| 25 | * |
---|
| 26 | * Output parameters: NONE |
---|
| 27 | * |
---|
| 28 | * Return values: |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | rtems_device_driver console_initialize( |
---|
| 32 | rtems_device_major_number major, |
---|
| 33 | rtems_device_minor_number minor, |
---|
[3a4ae6c] | 34 | void *arg |
---|
[ac7d5ef0] | 35 | ) |
---|
| 36 | { |
---|
[3a4ae6c] | 37 | rtems_status_code status; |
---|
| 38 | |
---|
| 39 | status = rtems_io_register_name( |
---|
| 40 | "/dev/console", |
---|
| 41 | major, |
---|
| 42 | (rtems_device_minor_number) 0 |
---|
| 43 | ); |
---|
| 44 | |
---|
| 45 | if (status != RTEMS_SUCCESSFUL) |
---|
| 46 | rtems_fatal_error_occurred(status); |
---|
| 47 | |
---|
| 48 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 49 | } |
---|
| 50 | |
---|
| 51 | /* |
---|
| 52 | * NINDY_IO( ... ) |
---|
| 53 | * |
---|
| 54 | * Interface to NINDY. |
---|
| 55 | */ |
---|
| 56 | |
---|
| 57 | #define NINDY_INPUT 0 |
---|
| 58 | #define NINDY_OUTPUT 1 |
---|
| 59 | |
---|
| 60 | void NINDY_IO(); |
---|
| 61 | |
---|
| 62 | void ___NINDY_IO_WRAPPER( void ) /* never called */ |
---|
| 63 | { |
---|
| 64 | asm volatile ( " .text" ); |
---|
| 65 | asm volatile ( " .align 4" ); |
---|
| 66 | asm volatile ( " .globl _NINDY_IO" ); |
---|
| 67 | asm volatile ( "_NINDY_IO:" ); |
---|
| 68 | asm volatile ( " calls 0 /* call console routines */" ); |
---|
| 69 | asm volatile ( " ret" ); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | /* inbyte |
---|
| 73 | * |
---|
| 74 | * This routine reads a character from the console using NINDY. |
---|
| 75 | * |
---|
| 76 | * Input parameters: NONE |
---|
| 77 | * |
---|
| 78 | * Output parameters: NONE |
---|
| 79 | * |
---|
| 80 | * Return values: |
---|
| 81 | * character read from UART |
---|
| 82 | */ |
---|
| 83 | |
---|
| 84 | char inbyte( void ) |
---|
| 85 | { |
---|
| 86 | char ch; |
---|
| 87 | |
---|
| 88 | NINDY_IO( NINDY_INPUT, &ch ); |
---|
| 89 | return ch; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | /* outbyte |
---|
| 94 | * |
---|
| 95 | * This routine transmits a character out the console using NINDY. |
---|
| 96 | * |
---|
| 97 | * Input parameters: |
---|
| 98 | * ch - character to be transmitted |
---|
| 99 | * |
---|
| 100 | * Output parameters: NONE |
---|
| 101 | */ |
---|
| 102 | |
---|
| 103 | void outbyte( |
---|
| 104 | char ch |
---|
| 105 | ) |
---|
| 106 | { |
---|
| 107 | NINDY_IO( NINDY_OUTPUT, ch ); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | /* |
---|
[3a4ae6c] | 111 | * Open entry point |
---|
[ac7d5ef0] | 112 | */ |
---|
[3a4ae6c] | 113 | |
---|
| 114 | rtems_device_driver console_open( |
---|
| 115 | rtems_device_major_number major, |
---|
| 116 | rtems_device_minor_number minor, |
---|
| 117 | void * arg |
---|
[ac7d5ef0] | 118 | ) |
---|
| 119 | { |
---|
[3a4ae6c] | 120 | return RTEMS_SUCCESSFUL; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | /* |
---|
| 124 | * Close entry point |
---|
| 125 | */ |
---|
| 126 | |
---|
| 127 | rtems_device_driver console_close( |
---|
| 128 | rtems_device_major_number major, |
---|
| 129 | rtems_device_minor_number minor, |
---|
| 130 | void * arg |
---|
| 131 | ) |
---|
| 132 | { |
---|
| 133 | return RTEMS_SUCCESSFUL; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | /* |
---|
| 137 | * read bytes from the serial port. We only have stdin. |
---|
| 138 | */ |
---|
| 139 | |
---|
| 140 | rtems_device_driver console_read( |
---|
| 141 | rtems_device_major_number major, |
---|
| 142 | rtems_device_minor_number minor, |
---|
| 143 | void * arg |
---|
| 144 | ) |
---|
| 145 | { |
---|
| 146 | rtems_libio_rw_args_t *rw_args; |
---|
| 147 | char *buffer; |
---|
| 148 | int maximum; |
---|
| 149 | int count = 0; |
---|
| 150 | |
---|
| 151 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 152 | |
---|
| 153 | buffer = rw_args->buffer; |
---|
| 154 | maximum = rw_args->count; |
---|
| 155 | |
---|
| 156 | for (count = 0; count < maximum; count++) { |
---|
| 157 | buffer[ count ] = inbyte(); |
---|
| 158 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 159 | buffer[ count++ ] = '\n'; |
---|
[ac7d5ef0] | 160 | break; |
---|
| 161 | } |
---|
| 162 | } |
---|
[3a4ae6c] | 163 | |
---|
| 164 | rw_args->bytes_moved = count; |
---|
| 165 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
[ac7d5ef0] | 166 | } |
---|
[3a4ae6c] | 167 | |
---|
[ac7d5ef0] | 168 | /* |
---|
[3a4ae6c] | 169 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
[ac7d5ef0] | 170 | */ |
---|
[3a4ae6c] | 171 | |
---|
| 172 | rtems_device_driver console_write( |
---|
| 173 | rtems_device_major_number major, |
---|
| 174 | rtems_device_minor_number minor, |
---|
| 175 | void * arg |
---|
[ac7d5ef0] | 176 | ) |
---|
| 177 | { |
---|
[3a4ae6c] | 178 | int count; |
---|
| 179 | int maximum; |
---|
| 180 | rtems_libio_rw_args_t *rw_args; |
---|
| 181 | char *buffer; |
---|
| 182 | |
---|
| 183 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 184 | |
---|
| 185 | buffer = rw_args->buffer; |
---|
| 186 | maximum = rw_args->count; |
---|
| 187 | |
---|
| 188 | for (count = 0; count < maximum; count++) { |
---|
| 189 | if ( buffer[ count ] == '\n') { |
---|
| 190 | outbyte('\r'); |
---|
[ac7d5ef0] | 191 | } |
---|
[3a4ae6c] | 192 | outbyte( buffer[ count ] ); |
---|
[ac7d5ef0] | 193 | } |
---|
[3652ad35] | 194 | |
---|
| 195 | rw_args->bytes_moved = maximum; |
---|
| 196 | return 0; |
---|
[3a4ae6c] | 197 | } |
---|
| 198 | |
---|
| 199 | /* |
---|
| 200 | * IO Control entry point |
---|
| 201 | */ |
---|
| 202 | |
---|
| 203 | rtems_device_driver console_control( |
---|
| 204 | rtems_device_major_number major, |
---|
| 205 | rtems_device_minor_number minor, |
---|
| 206 | void * arg |
---|
| 207 | ) |
---|
| 208 | { |
---|
| 209 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 210 | } |
---|
[3a4ae6c] | 211 | |
---|