[ac7d5ef0] | 1 | /* |
---|
[edd1329f] | 2 | * This file contains the TTY driver for the serial ports on the DMV152. |
---|
| 3 | * The serial ports use a Zilog Z8530. |
---|
| 4 | * |
---|
| 5 | * NOTE: This driver uses the termios pseudo driver. |
---|
| 6 | * This driver is polled only. |
---|
[ac7d5ef0] | 7 | * |
---|
[60b791ad] | 8 | * COPYRIGHT (c) 1989-1998. |
---|
[ac7d5ef0] | 9 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 10 | * Copyright assigned to U.S. Government, 1994. |
---|
[ac7d5ef0] | 11 | * |
---|
[98e4ebf5] | 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 14 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 15 | * |
---|
| 16 | * $Id$ |
---|
| 17 | */ |
---|
| 18 | |
---|
[3a4ae6c] | 19 | #include <bsp.h> |
---|
| 20 | #include <rtems/libio.h> |
---|
[edd1329f] | 21 | #include <stdlib.h> |
---|
| 22 | #include <assert.h> |
---|
| 23 | |
---|
| 24 | /* |
---|
| 25 | * console_outbyte_polled |
---|
[ac7d5ef0] | 26 | * |
---|
[edd1329f] | 27 | * This routine transmits a character using polling. |
---|
[ac7d5ef0] | 28 | */ |
---|
[edd1329f] | 29 | |
---|
| 30 | void console_outbyte_polled( |
---|
| 31 | int port, |
---|
| 32 | char ch |
---|
[ac7d5ef0] | 33 | ) |
---|
| 34 | { |
---|
[edd1329f] | 35 | rtems_unsigned32 control; |
---|
| 36 | rtems_unsigned32 data; |
---|
| 37 | rtems_unsigned8 rr_0; |
---|
| 38 | |
---|
| 39 | if ( port == 0 ) { |
---|
| 40 | control = CONSOLE_CONTROL_A; |
---|
| 41 | data = CONSOLE_DATA_A; |
---|
| 42 | } else { |
---|
| 43 | control = CONSOLE_CONTROL_B; |
---|
| 44 | data = CONSOLE_DATA_B; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | for ( ; ; ) { |
---|
| 48 | Z8x30_READ_CONTROL( control, RR_0, rr_0 ); |
---|
| 49 | if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 ) |
---|
| 50 | break; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | Z8x30_WRITE_DATA( control, ch ); |
---|
[ac7d5ef0] | 54 | } |
---|
| 55 | |
---|
[edd1329f] | 56 | /* |
---|
| 57 | * console_inbyte_nonblocking |
---|
[ac7d5ef0] | 58 | * |
---|
[edd1329f] | 59 | * This routine polls for a character. |
---|
[ac7d5ef0] | 60 | */ |
---|
| 61 | |
---|
[aa239a7] | 62 | int console_inbyte_nonblocking(int port) |
---|
[ac7d5ef0] | 63 | { |
---|
[edd1329f] | 64 | rtems_unsigned32 control; |
---|
| 65 | rtems_unsigned32 data; |
---|
| 66 | rtems_unsigned8 rr_0; |
---|
| 67 | char ch; |
---|
| 68 | |
---|
| 69 | if ( port == 0 ) { |
---|
| 70 | control = CONSOLE_CONTROL_A; |
---|
| 71 | data = CONSOLE_DATA_A; |
---|
| 72 | } else { |
---|
| 73 | control = CONSOLE_CONTROL_B; |
---|
| 74 | data = CONSOLE_DATA_B; |
---|
[ac7d5ef0] | 75 | } |
---|
| 76 | |
---|
[edd1329f] | 77 | Z8x30_READ_CONTROL( control, RR_0, rr_0 ); |
---|
| 78 | if ( !(rr_0 & RR_0_RX_DATA_AVAILABLE) ) |
---|
[aa239a7] | 79 | return -1; |
---|
[edd1329f] | 80 | |
---|
| 81 | Z8x30_READ_DATA( data, ch ); |
---|
[aa239a7] | 82 | return (int) ch; |
---|
[ac7d5ef0] | 83 | } |
---|
| 84 | |
---|
[edd1329f] | 85 | /* |
---|
| 86 | * DEBUG_puts |
---|
[ac7d5ef0] | 87 | * |
---|
[edd1329f] | 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. |
---|
[ac7d5ef0] | 91 | * |
---|
| 92 | * Input parameters: |
---|
[edd1329f] | 93 | * string - pointer to debug output string |
---|
[ac7d5ef0] | 94 | * |
---|
| 95 | * Output parameters: NONE |
---|
[edd1329f] | 96 | * |
---|
| 97 | * Return values: NONE |
---|
[ac7d5ef0] | 98 | */ |
---|
| 99 | |
---|
[edd1329f] | 100 | void DEBUG_puts( |
---|
| 101 | char *string |
---|
[ac7d5ef0] | 102 | ) |
---|
| 103 | { |
---|
[edd1329f] | 104 | char *s; |
---|
[ac7d5ef0] | 105 | |
---|
[edd1329f] | 106 | /* should disable interrupts here */ |
---|
| 107 | for ( s = string ; *s ; s++ ) |
---|
| 108 | console_outbyte_polled( 0, *s ); |
---|
[ac7d5ef0] | 109 | |
---|
[edd1329f] | 110 | console_outbyte_polled( 0, '\r' ); |
---|
| 111 | console_outbyte_polled( 0, '\n' ); |
---|
| 112 | /* should enable interrupts here */ |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | /* |
---|
| 117 | * Console Termios Support Entry Points |
---|
| 118 | * |
---|
| 119 | */ |
---|
[ac7d5ef0] | 120 | |
---|
[608641e] | 121 | int console_write_support (int minor, const char *buf, int len) |
---|
[edd1329f] | 122 | { |
---|
| 123 | int nwrite = 0; |
---|
[ac7d5ef0] | 124 | |
---|
[edd1329f] | 125 | while (nwrite < len) { |
---|
| 126 | console_outbyte_polled( minor, *buf++ ); |
---|
| 127 | nwrite++; |
---|
[ac7d5ef0] | 128 | } |
---|
[edd1329f] | 129 | return nwrite; |
---|
| 130 | } |
---|
[ac7d5ef0] | 131 | |
---|
[edd1329f] | 132 | void console_reserve_resources( |
---|
| 133 | rtems_configuration_table *configuration |
---|
| 134 | ) |
---|
| 135 | { |
---|
| 136 | rtems_termios_reserve_resources( configuration, 2 ); |
---|
[ac7d5ef0] | 137 | } |
---|
| 138 | |
---|
| 139 | /* |
---|
[edd1329f] | 140 | * Console Device Driver Entry Points |
---|
| 141 | * |
---|
[ac7d5ef0] | 142 | */ |
---|
[edd1329f] | 143 | |
---|
| 144 | rtems_device_driver console_initialize( |
---|
| 145 | rtems_device_major_number major, |
---|
| 146 | rtems_device_minor_number minor, |
---|
| 147 | void *arg |
---|
| 148 | ) |
---|
| 149 | { |
---|
| 150 | rtems_status_code status; |
---|
| 151 | rtems_device_minor_number console_minor; |
---|
| 152 | |
---|
| 153 | rtems_termios_initialize(); |
---|
| 154 | |
---|
| 155 | /* |
---|
| 156 | * Register Device Names |
---|
| 157 | */ |
---|
| 158 | |
---|
| 159 | #if (USE_CHANNEL_A == 1) |
---|
| 160 | console_minor = 0; |
---|
| 161 | #elif (USE_CHANNEL_B == 1) |
---|
| 162 | console_minor = 1; |
---|
| 163 | #else |
---|
| 164 | #error "DMV152 Console Driver -- no console port configured!!!" |
---|
| 165 | #endif |
---|
| 166 | |
---|
| 167 | status = rtems_io_register_name( "/dev/console", major, console_minor ); |
---|
| 168 | if (status != RTEMS_SUCCESSFUL) |
---|
| 169 | rtems_fatal_error_occurred(status); |
---|
| 170 | |
---|
| 171 | status = rtems_io_register_name( "/dev/console_a", major, 0 ); |
---|
| 172 | if (status != RTEMS_SUCCESSFUL) |
---|
| 173 | rtems_fatal_error_occurred(status); |
---|
| 174 | |
---|
| 175 | status = rtems_io_register_name( "/dev/console_b", major, 1 ); |
---|
| 176 | if (status != RTEMS_SUCCESSFUL) |
---|
| 177 | rtems_fatal_error_occurred(status); |
---|
| 178 | |
---|
| 179 | /* |
---|
| 180 | * Initialize Hardware |
---|
| 181 | */ |
---|
| 182 | |
---|
| 183 | return RTEMS_SUCCESSFUL; |
---|
| 184 | } |
---|
[ac7d5ef0] | 185 | |
---|
[3a4ae6c] | 186 | rtems_device_driver console_open( |
---|
| 187 | rtems_device_major_number major, |
---|
| 188 | rtems_device_minor_number minor, |
---|
| 189 | void * arg |
---|
[ac7d5ef0] | 190 | ) |
---|
| 191 | { |
---|
[55951bc] | 192 | rtems_status_code sc; |
---|
| 193 | static const rtems_termios_callbacks pollCallbacks = { |
---|
| 194 | NULL, /* firstOpen */ |
---|
| 195 | NULL, /* lastClose */ |
---|
| 196 | console_inbyte_nonblocking, /* pollRead */ |
---|
| 197 | console_write_support, /* write */ |
---|
| 198 | NULL, /* setAttributes */ |
---|
| 199 | NULL, /* stopRemoteTx */ |
---|
| 200 | NULL, /* startRemoteTx */ |
---|
| 201 | 0 /* outputUsesInterrupts */ |
---|
| 202 | }; |
---|
| 203 | |
---|
| 204 | assert( minor <= 1 ); |
---|
| 205 | if ( minor > 2 ) |
---|
| 206 | return RTEMS_INVALID_NUMBER; |
---|
| 207 | |
---|
| 208 | sc = rtems_termios_open (major, minor, arg, &pollCallbacks ); |
---|
[edd1329f] | 209 | |
---|
[3a4ae6c] | 210 | return RTEMS_SUCCESSFUL; |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | rtems_device_driver console_close( |
---|
| 214 | rtems_device_major_number major, |
---|
| 215 | rtems_device_minor_number minor, |
---|
| 216 | void * arg |
---|
| 217 | ) |
---|
| 218 | { |
---|
[edd1329f] | 219 | return rtems_termios_close (arg); |
---|
[3a4ae6c] | 220 | } |
---|
[edd1329f] | 221 | |
---|
[3a4ae6c] | 222 | rtems_device_driver console_read( |
---|
| 223 | rtems_device_major_number major, |
---|
| 224 | rtems_device_minor_number minor, |
---|
| 225 | void * arg |
---|
| 226 | ) |
---|
| 227 | { |
---|
[edd1329f] | 228 | return rtems_termios_read (arg); |
---|
[ac7d5ef0] | 229 | } |
---|
[edd1329f] | 230 | |
---|
[3a4ae6c] | 231 | rtems_device_driver console_write( |
---|
| 232 | rtems_device_major_number major, |
---|
| 233 | rtems_device_minor_number minor, |
---|
| 234 | void * arg |
---|
[ac7d5ef0] | 235 | ) |
---|
| 236 | { |
---|
[edd1329f] | 237 | return rtems_termios_write (arg); |
---|
[3a4ae6c] | 238 | } |
---|
[edd1329f] | 239 | |
---|
[3a4ae6c] | 240 | rtems_device_driver console_control( |
---|
| 241 | rtems_device_major_number major, |
---|
| 242 | rtems_device_minor_number minor, |
---|
| 243 | void * arg |
---|
| 244 | ) |
---|
| 245 | { |
---|
[edd1329f] | 246 | return rtems_termios_ioctl (arg); |
---|
[ac7d5ef0] | 247 | } |
---|
[edd1329f] | 248 | |
---|