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