[ac7d5ef0] | 1 | /* |
---|
| 2 | * This file contains the MVME162 console IO package. |
---|
[c186f2ed] | 3 | */ |
---|
| 4 | |
---|
| 5 | /* |
---|
| 6 | * COPYRIGHT (c) 1989-2013. |
---|
[ac7d5ef0] | 7 | * On-Line Applications Research Corporation (OAR). |
---|
| 8 | * |
---|
[98e4ebf5] | 9 | * The license and distribution terms for this file may be |
---|
| 10 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 11 | * http://www.rtems.org/license/LICENSE. |
---|
[ac7d5ef0] | 12 | * |
---|
| 13 | * Modifications of respective RTEMS file: COPYRIGHT (c) 1994. |
---|
| 14 | * EISCAT Scientific Association. M.Savitski |
---|
| 15 | * |
---|
| 16 | * This material is a part of the MVME162 Board Support Package |
---|
| 17 | * for the RTEMS executive. Its licensing policies are those of the |
---|
| 18 | * RTEMS above. |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #define M162_INIT |
---|
| 22 | |
---|
[aa30e2c] | 23 | #include <rtems/bspIo.h> |
---|
[9c18598d] | 24 | #include <rtems/console.h> |
---|
[3a4ae6c] | 25 | #include <rtems/libio.h> |
---|
[a9a27b5] | 26 | #include <rtems/ringbuf.h> |
---|
[9c18598d] | 27 | #include <bsp.h> |
---|
[ac7d5ef0] | 28 | |
---|
[98100d2] | 29 | Ring_buffer_t Console_Buffer[2]; |
---|
[c6fb8e90] | 30 | |
---|
| 31 | /* |
---|
| 32 | * Interrupt handler for receiver interrupts |
---|
[ac7d5ef0] | 33 | */ |
---|
[c186f2ed] | 34 | static rtems_isr C_Receive_ISR(rtems_vector_number vector) |
---|
[c6fb8e90] | 35 | { |
---|
| 36 | register int ipend, port; |
---|
| 37 | |
---|
| 38 | ZWRITE0(1, 0x38); /* reset highest IUS */ |
---|
| 39 | |
---|
| 40 | ipend = ZREAD(1, 3); /* read int pending from A side */ |
---|
| 41 | |
---|
| 42 | if (ipend == 0x04) port = 0; /* channel B intr pending */ |
---|
| 43 | else if (ipend == 0x20) port = 1; /* channel A intr pending */ |
---|
| 44 | else return; |
---|
[6128a4a] | 45 | |
---|
[98100d2] | 46 | Ring_buffer_Add_character(&Console_Buffer[port], ZREADD(port)); |
---|
[6128a4a] | 47 | |
---|
[c6fb8e90] | 48 | if (ZREAD(port, 1) & 0x70) { /* check error stat */ |
---|
| 49 | ZWRITE0(port, 0x30); /* reset error */ |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
[ac7d5ef0] | 53 | rtems_device_driver console_initialize( |
---|
| 54 | rtems_device_major_number major, |
---|
| 55 | rtems_device_minor_number minor, |
---|
[3a4ae6c] | 56 | void *arg |
---|
[ac7d5ef0] | 57 | ) |
---|
| 58 | { |
---|
[c6fb8e90] | 59 | int i; |
---|
[3a4ae6c] | 60 | rtems_status_code status; |
---|
[6128a4a] | 61 | |
---|
[c6fb8e90] | 62 | /* |
---|
| 63 | * Initialise receiver interrupts on both ports |
---|
| 64 | */ |
---|
| 65 | for (i = 0; i <= 1; i++) { |
---|
[98100d2] | 66 | Ring_buffer_Initialize( &Console_Buffer[i] ); |
---|
[c6fb8e90] | 67 | ZWRITE(i, 2, SCC_VECTOR); |
---|
| 68 | ZWRITE(i, 10, 0); |
---|
| 69 | ZWRITE(i, 1, 0x10); /* int on all Rx chars or special condition */ |
---|
| 70 | ZWRITE(i, 9, 8); /* master interrupt enable */ |
---|
| 71 | } |
---|
[6128a4a] | 72 | |
---|
[c6fb8e90] | 73 | set_vector(C_Receive_ISR, SCC_VECTOR, 1); /* install ISR for ports A and B */ |
---|
| 74 | |
---|
| 75 | mcchip->vector_base = 0; |
---|
| 76 | mcchip->gen_control = 2; /* MIEN */ |
---|
| 77 | mcchip->SCC_int_ctl = 0x13; /* SCC IEN, IPL3 */ |
---|
| 78 | |
---|
[3a4ae6c] | 79 | status = rtems_io_register_name( |
---|
| 80 | "/dev/console", |
---|
| 81 | major, |
---|
[da646dd] | 82 | (rtems_device_minor_number) 1 |
---|
[3a4ae6c] | 83 | ); |
---|
[6128a4a] | 84 | |
---|
[3a4ae6c] | 85 | if (status != RTEMS_SUCCESSFUL) |
---|
| 86 | rtems_fatal_error_occurred(status); |
---|
[6128a4a] | 87 | |
---|
[3a4ae6c] | 88 | status = rtems_io_register_name( |
---|
| 89 | "/dev/tty00", |
---|
| 90 | major, |
---|
| 91 | (rtems_device_minor_number) 0 |
---|
| 92 | ); |
---|
[6128a4a] | 93 | |
---|
[3a4ae6c] | 94 | if (status != RTEMS_SUCCESSFUL) |
---|
| 95 | rtems_fatal_error_occurred(status); |
---|
[6128a4a] | 96 | |
---|
[3a4ae6c] | 97 | status = rtems_io_register_name( |
---|
| 98 | "/dev/tty01", |
---|
| 99 | major, |
---|
[da646dd] | 100 | (rtems_device_minor_number) 1 |
---|
[3a4ae6c] | 101 | ); |
---|
[6128a4a] | 102 | |
---|
[3a4ae6c] | 103 | if (status != RTEMS_SUCCESSFUL) |
---|
| 104 | rtems_fatal_error_occurred(status); |
---|
[6128a4a] | 105 | |
---|
[3a4ae6c] | 106 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 107 | } |
---|
| 108 | |
---|
[c6fb8e90] | 109 | /* |
---|
| 110 | * Non-blocking char input |
---|
[ac7d5ef0] | 111 | */ |
---|
[907bf4b8] | 112 | bool char_ready(int port, char *ch) |
---|
[ac7d5ef0] | 113 | { |
---|
[98100d2] | 114 | if ( Ring_buffer_Is_empty( &Console_Buffer[port] ) ) |
---|
[907bf4b8] | 115 | return false; |
---|
[ac7d5ef0] | 116 | |
---|
[98100d2] | 117 | Ring_buffer_Remove_character( &Console_Buffer[port], *ch ); |
---|
[6128a4a] | 118 | |
---|
[c75430c] | 119 | return true; |
---|
[ac7d5ef0] | 120 | } |
---|
| 121 | |
---|
[c6fb8e90] | 122 | /* |
---|
| 123 | * Block on char input |
---|
[ac7d5ef0] | 124 | */ |
---|
[c186f2ed] | 125 | static char inbyte(int port) |
---|
[ac7d5ef0] | 126 | { |
---|
[39a9f8e] | 127 | char tmp_char; |
---|
[6128a4a] | 128 | |
---|
[c6fb8e90] | 129 | while ( !char_ready(port, &tmp_char) ); |
---|
| 130 | return tmp_char; |
---|
[ac7d5ef0] | 131 | } |
---|
| 132 | |
---|
[6128a4a] | 133 | /* |
---|
[c6fb8e90] | 134 | * This routine transmits a character out the SCC. It no longer supports |
---|
| 135 | * XON/XOFF flow control. |
---|
[ac7d5ef0] | 136 | */ |
---|
[c186f2ed] | 137 | static void outbyte(char ch, int port) |
---|
[ac7d5ef0] | 138 | { |
---|
[c6fb8e90] | 139 | while (1) { |
---|
| 140 | if (ZREAD0(port) & TX_BUFFER_EMPTY) break; |
---|
[ac7d5ef0] | 141 | } |
---|
[c6fb8e90] | 142 | ZWRITED(port, ch); |
---|
[ac7d5ef0] | 143 | } |
---|
| 144 | |
---|
| 145 | /* |
---|
[3a4ae6c] | 146 | * Open entry point |
---|
| 147 | */ |
---|
| 148 | rtems_device_driver console_open( |
---|
| 149 | rtems_device_major_number major, |
---|
| 150 | rtems_device_minor_number minor, |
---|
| 151 | void * arg |
---|
| 152 | ) |
---|
| 153 | { |
---|
| 154 | return RTEMS_SUCCESSFUL; |
---|
| 155 | } |
---|
[6128a4a] | 156 | |
---|
[3a4ae6c] | 157 | /* |
---|
| 158 | * Close entry point |
---|
| 159 | */ |
---|
| 160 | rtems_device_driver console_close( |
---|
| 161 | rtems_device_major_number major, |
---|
| 162 | rtems_device_minor_number minor, |
---|
| 163 | void * arg |
---|
| 164 | ) |
---|
| 165 | { |
---|
| 166 | return RTEMS_SUCCESSFUL; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | /* |
---|
| 170 | * read bytes from the serial port. We only have stdin. |
---|
[ac7d5ef0] | 171 | */ |
---|
[3a4ae6c] | 172 | rtems_device_driver console_read( |
---|
| 173 | rtems_device_major_number major, |
---|
| 174 | rtems_device_minor_number minor, |
---|
| 175 | void * arg |
---|
| 176 | ) |
---|
[ac7d5ef0] | 177 | { |
---|
[3a4ae6c] | 178 | rtems_libio_rw_args_t *rw_args; |
---|
| 179 | char *buffer; |
---|
| 180 | int maximum; |
---|
| 181 | int count = 0; |
---|
[6128a4a] | 182 | |
---|
[3a4ae6c] | 183 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
[c6fb8e90] | 184 | |
---|
[3a4ae6c] | 185 | buffer = rw_args->buffer; |
---|
| 186 | maximum = rw_args->count; |
---|
[ac7d5ef0] | 187 | |
---|
[3a4ae6c] | 188 | if ( minor > 1 ) |
---|
| 189 | return RTEMS_INVALID_NUMBER; |
---|
| 190 | |
---|
| 191 | for (count = 0; count < maximum; count++) { |
---|
| 192 | buffer[ count ] = inbyte( minor ); |
---|
| 193 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 194 | buffer[ count++ ] = '\n'; |
---|
[ac7d5ef0] | 195 | break; |
---|
| 196 | } |
---|
| 197 | } |
---|
[3a4ae6c] | 198 | |
---|
| 199 | rw_args->bytes_moved = count; |
---|
| 200 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
[ac7d5ef0] | 201 | } |
---|
| 202 | |
---|
| 203 | /* |
---|
[6128a4a] | 204 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
[ac7d5ef0] | 205 | */ |
---|
[3a4ae6c] | 206 | rtems_device_driver console_write( |
---|
| 207 | rtems_device_major_number major, |
---|
| 208 | rtems_device_minor_number minor, |
---|
| 209 | void * arg |
---|
| 210 | ) |
---|
[ac7d5ef0] | 211 | { |
---|
[3a4ae6c] | 212 | int count; |
---|
| 213 | int maximum; |
---|
| 214 | rtems_libio_rw_args_t *rw_args; |
---|
| 215 | char *buffer; |
---|
| 216 | |
---|
| 217 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 218 | |
---|
| 219 | buffer = rw_args->buffer; |
---|
| 220 | maximum = rw_args->count; |
---|
| 221 | |
---|
| 222 | if ( minor > 1 ) |
---|
| 223 | return RTEMS_INVALID_NUMBER; |
---|
| 224 | |
---|
| 225 | for (count = 0; count < maximum; count++) { |
---|
| 226 | if ( buffer[ count ] == '\n') { |
---|
| 227 | outbyte('\r', minor ); |
---|
[ac7d5ef0] | 228 | } |
---|
[3a4ae6c] | 229 | outbyte( buffer[ count ], minor ); |
---|
[ac7d5ef0] | 230 | } |
---|
[3652ad35] | 231 | |
---|
| 232 | rw_args->bytes_moved = maximum; |
---|
| 233 | return 0; |
---|
[3a4ae6c] | 234 | } |
---|
| 235 | |
---|
| 236 | /* |
---|
| 237 | * IO Control entry point |
---|
| 238 | */ |
---|
| 239 | rtems_device_driver console_control( |
---|
| 240 | rtems_device_major_number major, |
---|
| 241 | rtems_device_minor_number minor, |
---|
| 242 | void * arg |
---|
| 243 | ) |
---|
| 244 | { |
---|
| 245 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 246 | } |
---|
[c186f2ed] | 247 | |
---|
| 248 | /* |
---|
| 249 | * _162Bug_output_char |
---|
| 250 | * |
---|
| 251 | * Output a single character using the 162Bug functions. The character |
---|
| 252 | * will be written to the default output port. |
---|
| 253 | */ |
---|
| 254 | static void _162Bug_output_char( char c ) |
---|
| 255 | { |
---|
| 256 | asm volatile( "moveb %0, -(%%sp)\n\t" /* char to output */ |
---|
| 257 | "trap #15\n\t" /* Trap to 162Bug */ |
---|
| 258 | ".short 0x20" /* Code for .OUTCHR */ |
---|
| 259 | :: "d" (c) ); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | /* |
---|
| 263 | * _BSP_output_char |
---|
| 264 | * |
---|
| 265 | * printk() function prototyped in bspIo.h. Does not use termios. |
---|
| 266 | * |
---|
| 267 | * If we have initialized the console device then use it, otherwise |
---|
| 268 | * use the 162Bug routines to send it to the default output port. |
---|
| 269 | */ |
---|
| 270 | static void _BSP_output_char(char c) |
---|
| 271 | { |
---|
| 272 | _162Bug_output_char(c); |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | /* Printk function */ |
---|
[a6bf052] | 276 | BSP_output_char_function_type BSP_output_char = _BSP_output_char; |
---|
| 277 | BSP_polling_getchar_function_type BSP_poll_char = NULL; |
---|