[cd58d82] | 1 | /* |
---|
| 2 | * This file contains the termios TTY driver for the Motorola MC68681. |
---|
| 3 | * |
---|
| 4 | * This part is available from a number of secondary sources. |
---|
| 5 | * In particular, we know about the following: |
---|
| 6 | * |
---|
| 7 | * + Exar 88c681 and 68c681 |
---|
| 8 | * |
---|
| 9 | * COPYRIGHT (c) 1989-1998. |
---|
| 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * Copyright assigned to U.S. Government, 1994. |
---|
| 12 | * |
---|
| 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
| 15 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #include <rtems.h> |
---|
| 21 | #include <rtems/libio.h> |
---|
| 22 | #include <stdlib.h> |
---|
| 23 | #include <ringbuf.h> |
---|
| 24 | |
---|
| 25 | #include <libchip/serial.h> |
---|
[2d8e51aa] | 26 | #include "sersupp.h" |
---|
[cd58d82] | 27 | #include "mc68681_p.h" |
---|
[ab2dbd7] | 28 | #include "mc68681.h" |
---|
[cd58d82] | 29 | |
---|
| 30 | /* |
---|
| 31 | * Flow control is only supported when using interrupts |
---|
| 32 | */ |
---|
[424e23ee] | 33 | |
---|
[cd58d82] | 34 | console_fns mc68681_fns = |
---|
| 35 | { |
---|
[693b5b88] | 36 | libchip_serial_default_probe, /* deviceProbe */ |
---|
[cd58d82] | 37 | mc68681_open, /* deviceFirstOpen */ |
---|
[198d851] | 38 | NULL, /* deviceLastClose */ |
---|
[cd58d82] | 39 | NULL, /* deviceRead */ |
---|
| 40 | mc68681_write_support_int, /* deviceWrite */ |
---|
| 41 | mc68681_initialize_interrupts, /* deviceInitialize */ |
---|
| 42 | mc68681_write_polled, /* deviceWritePolled */ |
---|
[25c3ff91] | 43 | mc68681_set_attributes, /* deviceSetAttributes */ |
---|
[be8cbbf] | 44 | TRUE /* deviceOutputUsesInterrupts */ |
---|
[cd58d82] | 45 | }; |
---|
| 46 | |
---|
| 47 | console_fns mc68681_fns_polled = |
---|
| 48 | { |
---|
[693b5b88] | 49 | libchip_serial_default_probe, /* deviceProbe */ |
---|
[cd58d82] | 50 | mc68681_open, /* deviceFirstOpen */ |
---|
| 51 | mc68681_close, /* deviceLastClose */ |
---|
| 52 | mc68681_inbyte_nonblocking_polled, /* deviceRead */ |
---|
| 53 | mc68681_write_support_polled, /* deviceWrite */ |
---|
| 54 | mc68681_init, /* deviceInitialize */ |
---|
| 55 | mc68681_write_polled, /* deviceWritePolled */ |
---|
[25c3ff91] | 56 | mc68681_set_attributes, /* deviceSetAttributes */ |
---|
[cd58d82] | 57 | FALSE, /* deviceOutputUsesInterrupts */ |
---|
| 58 | }; |
---|
| 59 | |
---|
| 60 | extern void set_vector( rtems_isr_entry, rtems_vector_number, int ); |
---|
| 61 | |
---|
| 62 | /* |
---|
| 63 | * Console Device Driver Entry Points |
---|
| 64 | */ |
---|
[424e23ee] | 65 | |
---|
[beaaf49f] | 66 | /* |
---|
| 67 | * mc68681_baud_rate |
---|
| 68 | * |
---|
| 69 | * This routine returns the proper ACR bit and baud rate field values |
---|
| 70 | * based on the requested baud rate. The baud rate set to be used |
---|
| 71 | * must be configured by the user. |
---|
| 72 | */ |
---|
| 73 | |
---|
[2d8e51aa] | 74 | /* major index of 0 : ACR[7] = 0, X = 0 -- 68c681 only has these */ |
---|
| 75 | /* major index of 1 : ACR[7] = 1, X = 0 -- 68c681 only has these */ |
---|
| 76 | /* major index of 2 : ACR[7] = 0, X = 1 */ |
---|
| 77 | /* major index of 3 : ACR[7] = 1, X = 1 */ |
---|
| 78 | |
---|
| 79 | /* mc68681_baud_table_t mc68681_baud_rate_table[4] = { */ |
---|
| 80 | mc68681_baud_t mc68681_baud_rate_table[4][RTEMS_TERMIOS_NUMBER_BAUD_RATES] = { |
---|
| 81 | { /* ACR[7] = 0, X = 0 */ |
---|
| 82 | MC68681_BAUD_NOT_VALID, /* B0 */ |
---|
| 83 | 0x00, /* B50 */ |
---|
| 84 | MC68681_BAUD_NOT_VALID, /* B75 */ |
---|
| 85 | 0x01, /* B110 */ |
---|
| 86 | 0x02, /* B134 */ |
---|
| 87 | MC68681_BAUD_NOT_VALID, /* B150 */ |
---|
| 88 | 0x03, /* B200 */ |
---|
| 89 | 0x04, /* B300 */ |
---|
| 90 | 0x05, /* B600 */ |
---|
| 91 | 0x06, /* B1200 */ |
---|
| 92 | MC68681_BAUD_NOT_VALID, /* B1800 */ |
---|
| 93 | 0x08, /* B2400 */ |
---|
| 94 | 0x09, /* B4800 */ |
---|
| 95 | 0x0B, /* B9600 */ |
---|
| 96 | MC68681_BAUD_NOT_VALID, /* B19200 */ |
---|
| 97 | 0x0C, /* B38400 */ |
---|
| 98 | MC68681_BAUD_NOT_VALID, /* B57600 */ |
---|
| 99 | MC68681_BAUD_NOT_VALID, /* B115200 */ |
---|
| 100 | MC68681_BAUD_NOT_VALID, /* B230400 */ |
---|
| 101 | MC68681_BAUD_NOT_VALID /* B460800 */ |
---|
| 102 | }, |
---|
| 103 | { /* ACR[7] = 1, X = 0 */ |
---|
| 104 | MC68681_BAUD_NOT_VALID, /* B0 */ |
---|
| 105 | MC68681_BAUD_NOT_VALID, /* B50 */ |
---|
| 106 | 0x00, /* B75 */ |
---|
| 107 | 0x01, /* B110 */ |
---|
| 108 | 0x02, /* B134 */ |
---|
| 109 | 0x03, /* B150 */ |
---|
| 110 | MC68681_BAUD_NOT_VALID, /* B200 */ |
---|
| 111 | 0x04, /* B300 */ |
---|
| 112 | 0x05, /* B600 */ |
---|
| 113 | 0x06, /* B1200 */ |
---|
| 114 | 0x0A, /* B1800 */ |
---|
| 115 | 0x08, /* B2400 */ |
---|
| 116 | 0x09, /* B4800 */ |
---|
| 117 | 0x0B, /* B9600 */ |
---|
| 118 | 0x0C, /* B19200 */ |
---|
| 119 | MC68681_BAUD_NOT_VALID, /* B38400 */ |
---|
| 120 | MC68681_BAUD_NOT_VALID, /* B57600 */ |
---|
| 121 | MC68681_BAUD_NOT_VALID, /* B115200 */ |
---|
| 122 | MC68681_BAUD_NOT_VALID, /* B230400 */ |
---|
| 123 | MC68681_BAUD_NOT_VALID /* B460800 */ |
---|
| 124 | }, |
---|
| 125 | { /* ACR[7] = 0, X = 1 */ |
---|
| 126 | MC68681_BAUD_NOT_VALID, /* B0 */ |
---|
| 127 | MC68681_BAUD_NOT_VALID, /* B50 */ |
---|
| 128 | 0x00, /* B75 */ |
---|
| 129 | 0x01, /* B110 */ |
---|
| 130 | 0x02, /* B134 */ |
---|
| 131 | 0x03, /* B150 */ |
---|
| 132 | MC68681_BAUD_NOT_VALID, /* B200 */ |
---|
| 133 | MC68681_BAUD_NOT_VALID, /* B300 */ |
---|
| 134 | MC68681_BAUD_NOT_VALID, /* B600 */ |
---|
| 135 | MC68681_BAUD_NOT_VALID, /* B1200 */ |
---|
| 136 | 0x0A, /* B1800 */ |
---|
| 137 | MC68681_BAUD_NOT_VALID, /* B2400 */ |
---|
| 138 | 0x08, /* B4800 */ |
---|
| 139 | 0x0B, /* B9600 */ |
---|
| 140 | 0x0C, /* B19200 */ |
---|
| 141 | MC68681_BAUD_NOT_VALID, /* B38400 */ |
---|
| 142 | 0x07, /* B57600 */ |
---|
| 143 | 0x08, /* B115200 */ |
---|
| 144 | MC68681_BAUD_NOT_VALID, /* B230400 */ |
---|
| 145 | MC68681_BAUD_NOT_VALID /* B460800 */ |
---|
| 146 | }, |
---|
| 147 | { /* ACR[7] = 1, X = 1 */ |
---|
| 148 | MC68681_BAUD_NOT_VALID, /* B0 */ |
---|
| 149 | 0x00, /* B50 */ |
---|
| 150 | MC68681_BAUD_NOT_VALID, /* B75 */ |
---|
| 151 | 0x01, /* B110 */ |
---|
| 152 | 0x02, /* B134 */ |
---|
| 153 | MC68681_BAUD_NOT_VALID, /* B150 */ |
---|
| 154 | 0x03, /* B200 */ |
---|
| 155 | MC68681_BAUD_NOT_VALID, /* B300 */ |
---|
| 156 | MC68681_BAUD_NOT_VALID, /* B600 */ |
---|
| 157 | MC68681_BAUD_NOT_VALID, /* B1200 */ |
---|
| 158 | MC68681_BAUD_NOT_VALID, /* B1800 */ |
---|
| 159 | MC68681_BAUD_NOT_VALID, /* B2400 */ |
---|
| 160 | 0x09, /* B4800 */ |
---|
| 161 | 0x0B, /* B9600 */ |
---|
| 162 | MC68681_BAUD_NOT_VALID, /* B19200 */ |
---|
| 163 | 0x0C, /* B38400 */ |
---|
| 164 | 0x07, /* B57600 */ |
---|
| 165 | 0x08, /* B115200 */ |
---|
| 166 | MC68681_BAUD_NOT_VALID, /* B230400 */ |
---|
| 167 | MC68681_BAUD_NOT_VALID /* B460800 */ |
---|
| 168 | }, |
---|
| 169 | }; |
---|
| 170 | |
---|
| 171 | MC68681_STATIC int mc68681_baud_rate( |
---|
[25c3ff91] | 172 | int minor, |
---|
| 173 | int baud, |
---|
| 174 | unsigned int *baud_mask_p, |
---|
[2d8e51aa] | 175 | unsigned int *acr_bit_p, |
---|
| 176 | unsigned int *command |
---|
| 177 | ); |
---|
[25c3ff91] | 178 | |
---|
[beaaf49f] | 179 | /* |
---|
| 180 | * mc68681_set_attributes |
---|
| 181 | * |
---|
| 182 | * This function sets the DUART channel to reflect the requested termios |
---|
| 183 | * port settings. |
---|
| 184 | */ |
---|
| 185 | |
---|
[2d8e51aa] | 186 | MC68681_STATIC int mc68681_set_attributes( |
---|
[25c3ff91] | 187 | int minor, |
---|
| 188 | const struct termios *t |
---|
| 189 | ) |
---|
| 190 | { |
---|
| 191 | unsigned32 pMC68681_port; |
---|
| 192 | unsigned32 pMC68681; |
---|
| 193 | unsigned int mode1; |
---|
| 194 | unsigned int mode2; |
---|
| 195 | unsigned int baud_mask; |
---|
| 196 | unsigned int acr_bit; |
---|
[2d8e51aa] | 197 | unsigned int cmd; |
---|
[25c3ff91] | 198 | setRegister_f setReg; |
---|
| 199 | rtems_interrupt_level Irql; |
---|
[cd58d82] | 200 | |
---|
[4f0ffa57] | 201 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 202 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
[7deeb16] | 203 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 204 | |
---|
| 205 | /* |
---|
[25c3ff91] | 206 | * Set the baud rate |
---|
[7deeb16] | 207 | */ |
---|
| 208 | |
---|
[2d8e51aa] | 209 | if (mc68681_baud_rate( minor, t->c_cflag, &baud_mask, &acr_bit, &cmd ) == -1) |
---|
[25c3ff91] | 210 | return -1; |
---|
| 211 | |
---|
| 212 | baud_mask |= baud_mask << 4; |
---|
| 213 | acr_bit <<= 7; |
---|
[7deeb16] | 214 | |
---|
| 215 | /* |
---|
[25c3ff91] | 216 | * Parity |
---|
[7deeb16] | 217 | */ |
---|
| 218 | |
---|
[25c3ff91] | 219 | mode1 = 0; |
---|
| 220 | mode2 = 0; |
---|
[7deeb16] | 221 | |
---|
[25c3ff91] | 222 | if (t->c_cflag & PARENB) { |
---|
| 223 | if (t->c_cflag & PARODD) |
---|
| 224 | mode1 |= 0x04; |
---|
| 225 | else |
---|
| 226 | mode1 |= 0x04; |
---|
| 227 | } else { |
---|
| 228 | mode1 |= 0x10; |
---|
| 229 | } |
---|
[cd58d82] | 230 | |
---|
[25c3ff91] | 231 | /* |
---|
| 232 | * Character Size |
---|
[cd58d82] | 233 | */ |
---|
| 234 | |
---|
[25c3ff91] | 235 | if (t->c_cflag & CSIZE) { |
---|
| 236 | switch (t->c_cflag & CSIZE) { |
---|
| 237 | case CS5: break; |
---|
| 238 | case CS6: mode1 |= 0x01; break; |
---|
| 239 | case CS7: mode1 |= 0x02; break; |
---|
| 240 | case CS8: mode1 |= 0x03; break; |
---|
| 241 | } |
---|
| 242 | } else { |
---|
| 243 | mode1 |= 0x03; /* default to 9600,8,N,1 */ |
---|
| 244 | } |
---|
[cd58d82] | 245 | |
---|
[25c3ff91] | 246 | /* |
---|
| 247 | * Stop Bits |
---|
| 248 | */ |
---|
| 249 | |
---|
| 250 | if (t->c_cflag & CSTOPB) { |
---|
| 251 | mode2 |= 0x07; /* 2 stop bits */ |
---|
| 252 | } else { |
---|
| 253 | if ((t->c_cflag & CSIZE) == CS5) /* CS5 and 2 stop bits not supported */ |
---|
| 254 | return -1; |
---|
| 255 | mode2 |= 0x0F; /* 1 stop bit */ |
---|
| 256 | } |
---|
[cd58d82] | 257 | |
---|
[25c3ff91] | 258 | rtems_interrupt_disable(Irql); |
---|
| 259 | (*setReg)( pMC68681, MC68681_AUX_CTRL_REG, acr_bit ); |
---|
| 260 | (*setReg)( pMC68681_port, MC68681_CLOCK_SELECT, baud_mask ); |
---|
[2c5ea01] | 261 | if ( cmd ) { |
---|
| 262 | (*setReg)( pMC68681_port, MC68681_COMMAND, cmd ); /* RX */ |
---|
| 263 | (*setReg)( pMC68681_port, MC68681_COMMAND, cmd | 0x20 ); /* TX */ |
---|
| 264 | } |
---|
[25c3ff91] | 265 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_MR_PTR ); |
---|
| 266 | (*setReg)( pMC68681_port, MC68681_MODE, mode1 ); |
---|
| 267 | (*setReg)( pMC68681_port, MC68681_MODE, mode2 ); |
---|
| 268 | rtems_interrupt_enable(Irql); |
---|
| 269 | return 0; |
---|
| 270 | } |
---|
[cd58d82] | 271 | |
---|
[beaaf49f] | 272 | /* |
---|
| 273 | * mc68681_initialize_context |
---|
| 274 | * |
---|
| 275 | * This function sets the default values of the per port context structure. |
---|
| 276 | */ |
---|
| 277 | |
---|
[2d8e51aa] | 278 | MC68681_STATIC void mc68681_initialize_context( |
---|
[a5d0c7c] | 279 | int minor, |
---|
| 280 | mc68681_context *pmc68681Context |
---|
| 281 | ) |
---|
| 282 | { |
---|
| 283 | int port; |
---|
| 284 | unsigned int pMC68681; |
---|
[be8cbbf] | 285 | unsigned int pMC68681_port; |
---|
[a5d0c7c] | 286 | |
---|
[be8cbbf] | 287 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 288 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
[a5d0c7c] | 289 | |
---|
| 290 | pmc68681Context->mate = -1; |
---|
| 291 | |
---|
| 292 | for (port=0 ; port<Console_Port_Count ; port++ ) { |
---|
[be8cbbf] | 293 | if ( Console_Port_Tbl[port].ulCtrlPort1 == pMC68681 && |
---|
| 294 | Console_Port_Tbl[port].ulCtrlPort2 != pMC68681_port ) { |
---|
[a5d0c7c] | 295 | pmc68681Context->mate = port; |
---|
[198d851] | 296 | pmc68681Context->imr = 0; |
---|
[a5d0c7c] | 297 | break; |
---|
| 298 | } |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | } |
---|
| 302 | |
---|
[beaaf49f] | 303 | /* |
---|
| 304 | * mc68681_init |
---|
| 305 | * |
---|
| 306 | * This function initializes the DUART to a quiecsent state. |
---|
| 307 | */ |
---|
| 308 | |
---|
[2d8e51aa] | 309 | MC68681_STATIC void mc68681_init(int minor) |
---|
[25c3ff91] | 310 | { |
---|
| 311 | unsigned32 pMC68681_port; |
---|
| 312 | unsigned32 pMC68681; |
---|
| 313 | mc68681_context *pmc68681Context; |
---|
| 314 | setRegister_f setReg; |
---|
| 315 | getRegister_f getReg; |
---|
| 316 | |
---|
| 317 | pmc68681Context = (mc68681_context *) malloc(sizeof(mc68681_context)); |
---|
[cd58d82] | 318 | |
---|
[25c3ff91] | 319 | Console_Port_Data[minor].pDeviceContext = (void *)pmc68681Context; |
---|
[a5d0c7c] | 320 | |
---|
| 321 | mc68681_initialize_context( minor, pmc68681Context ); |
---|
[cd58d82] | 322 | |
---|
[4f0ffa57] | 323 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 324 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
[25c3ff91] | 325 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 326 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
[cd58d82] | 327 | |
---|
| 328 | /* |
---|
[25c3ff91] | 329 | * Reset everything and leave this port disabled. |
---|
[cd58d82] | 330 | */ |
---|
| 331 | |
---|
[198d851] | 332 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_RX ); |
---|
| 333 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_TX ); |
---|
| 334 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_ERROR ); |
---|
| 335 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_BREAK ); |
---|
| 336 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_STOP_BREAK ); |
---|
| 337 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_TX ); |
---|
| 338 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_RX ); |
---|
[cd58d82] | 339 | |
---|
[25c3ff91] | 340 | |
---|
[198d851] | 341 | (*setReg)( pMC68681_port, MC68681_MODE_REG_1A, 0x00 ); |
---|
| 342 | (*setReg)( pMC68681_port, MC68681_MODE_REG_2A, 0x02 ); |
---|
[4f0ffa57] | 343 | |
---|
| 344 | /* |
---|
| 345 | * Disable interrupts on RX and TX for this port |
---|
| 346 | */ |
---|
| 347 | |
---|
[198d851] | 348 | mc68681_enable_interrupts( minor, MC68681_IMR_DISABLE_ALL ); |
---|
[cd58d82] | 349 | } |
---|
| 350 | |
---|
[25c3ff91] | 351 | /* |
---|
[beaaf49f] | 352 | * mc68681_open |
---|
| 353 | * |
---|
| 354 | * This function opens a port for communication. |
---|
| 355 | * |
---|
| 356 | * Default state is 9600 baud, 8 bits, No parity, and 1 stop bit. |
---|
[25c3ff91] | 357 | */ |
---|
| 358 | |
---|
[2d8e51aa] | 359 | MC68681_STATIC int mc68681_open( |
---|
[cd58d82] | 360 | int major, |
---|
| 361 | int minor, |
---|
[25c3ff91] | 362 | void *arg |
---|
[cd58d82] | 363 | ) |
---|
| 364 | { |
---|
[25c3ff91] | 365 | unsigned32 pMC68681; |
---|
| 366 | unsigned32 pMC68681_port; |
---|
| 367 | unsigned int baud; |
---|
| 368 | unsigned int acr; |
---|
| 369 | unsigned int vector; |
---|
[2d8e51aa] | 370 | unsigned int command; |
---|
[25c3ff91] | 371 | rtems_interrupt_level Irql; |
---|
| 372 | setRegister_f setReg; |
---|
| 373 | |
---|
| 374 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 375 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 376 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 377 | vector = Console_Port_Tbl[minor].ulIntVector; |
---|
| 378 | |
---|
[e78c474b] | 379 | /* XXX default baud rate should be from configuration table */ |
---|
| 380 | |
---|
[2d8e51aa] | 381 | (void) mc68681_baud_rate( minor, B9600, &baud, &acr, &command ); |
---|
[25c3ff91] | 382 | |
---|
[b7ebcea3] | 383 | /* |
---|
| 384 | * Set the DUART channel to a default useable state |
---|
| 385 | */ |
---|
| 386 | |
---|
[25c3ff91] | 387 | rtems_interrupt_disable(Irql); |
---|
| 388 | (*setReg)( pMC68681, MC68681_AUX_CTRL_REG, acr ); |
---|
| 389 | (*setReg)( pMC68681_port, MC68681_CLOCK_SELECT, baud ); |
---|
[e78c474b] | 390 | if ( command ) { |
---|
| 391 | (*setReg)( pMC68681_port, MC68681_COMMAND, command ); /* RX */ |
---|
| 392 | (*setReg)( pMC68681_port, MC68681_COMMAND, command | 0x20 ); /* TX */ |
---|
| 393 | } |
---|
[25c3ff91] | 394 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_MR_PTR ); |
---|
| 395 | (*setReg)( pMC68681_port, MC68681_MODE, 0x13 ); |
---|
| 396 | (*setReg)( pMC68681_port, MC68681_MODE, 0x07 ); |
---|
| 397 | rtems_interrupt_enable(Irql); |
---|
| 398 | |
---|
| 399 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_ENABLE_TX ); |
---|
| 400 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_ENABLE_RX ); |
---|
| 401 | |
---|
| 402 | (*setReg)( pMC68681, MC68681_INTERRUPT_VECTOR_REG, vector ); |
---|
| 403 | |
---|
[4f0ffa57] | 404 | return RTEMS_SUCCESSFUL; |
---|
[cd58d82] | 405 | } |
---|
| 406 | |
---|
[beaaf49f] | 407 | /* |
---|
| 408 | * mc68681_close |
---|
| 409 | * |
---|
| 410 | * This function shuts down the requested port. |
---|
| 411 | */ |
---|
| 412 | |
---|
[2d8e51aa] | 413 | MC68681_STATIC int mc68681_close( |
---|
[cd58d82] | 414 | int major, |
---|
| 415 | int minor, |
---|
[25c3ff91] | 416 | void *arg |
---|
[cd58d82] | 417 | ) |
---|
| 418 | { |
---|
[b7ebcea3] | 419 | unsigned32 pMC68681; |
---|
| 420 | unsigned32 pMC68681_port; |
---|
| 421 | setRegister_f setReg; |
---|
| 422 | |
---|
| 423 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 424 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 425 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 426 | |
---|
| 427 | /* |
---|
| 428 | * Disable interrupts from this channel and then disable it totally. |
---|
| 429 | */ |
---|
| 430 | |
---|
| 431 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_TX ); |
---|
| 432 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_RX ); |
---|
| 433 | |
---|
[cd58d82] | 434 | return(RTEMS_SUCCESSFUL); |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | /* |
---|
| 438 | * mc68681_write_polled |
---|
[beaaf49f] | 439 | * |
---|
| 440 | * This routine polls out the requested character. |
---|
[cd58d82] | 441 | */ |
---|
[424e23ee] | 442 | |
---|
[2d8e51aa] | 443 | MC68681_STATIC void mc68681_write_polled( |
---|
[cd58d82] | 444 | int minor, |
---|
| 445 | char cChar |
---|
| 446 | ) |
---|
| 447 | { |
---|
[25c3ff91] | 448 | unsigned32 pMC68681_port; |
---|
[cd58d82] | 449 | unsigned char ucLineStatus; |
---|
| 450 | int iTimeout; |
---|
| 451 | getRegister_f getReg; |
---|
[25c3ff91] | 452 | setRegister_f setReg; |
---|
[cd58d82] | 453 | |
---|
[25c3ff91] | 454 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 455 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
| 456 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
[cd58d82] | 457 | |
---|
| 458 | /* |
---|
| 459 | * wait for transmitter holding register to be empty |
---|
| 460 | */ |
---|
[ab2dbd7] | 461 | iTimeout = 1000; |
---|
[25c3ff91] | 462 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
[2c5ea01] | 463 | while ((ucLineStatus & (MC68681_TX_READY|MC68681_TX_EMPTY)) == 0) { |
---|
| 464 | |
---|
| 465 | if ((ucLineStatus & 0xF0)) |
---|
| 466 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_ERROR ); |
---|
[ab2dbd7] | 467 | |
---|
[cd58d82] | 468 | /* |
---|
| 469 | * Yield while we wait |
---|
| 470 | */ |
---|
[ab2dbd7] | 471 | |
---|
[cd58d82] | 472 | if(_System_state_Is_up(_System_state_Get())) { |
---|
| 473 | rtems_task_wake_after(RTEMS_YIELD_PROCESSOR); |
---|
| 474 | } |
---|
[25c3ff91] | 475 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
[cd58d82] | 476 | if(!--iTimeout) { |
---|
| 477 | break; |
---|
| 478 | } |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | /* |
---|
| 482 | * transmit character |
---|
| 483 | */ |
---|
[ab2dbd7] | 484 | |
---|
[25c3ff91] | 485 | (*setReg)(pMC68681_port, MC68681_TX_BUFFER, cChar); |
---|
[cd58d82] | 486 | } |
---|
| 487 | |
---|
[4f0ffa57] | 488 | /* |
---|
| 489 | * mc68681_isr |
---|
| 490 | * |
---|
| 491 | * This is the single interrupt entry point which parcels interrupts |
---|
| 492 | * out to the various ports. |
---|
| 493 | */ |
---|
| 494 | |
---|
[2d8e51aa] | 495 | MC68681_STATIC rtems_isr mc68681_isr( |
---|
[cd58d82] | 496 | rtems_vector_number vector |
---|
| 497 | ) |
---|
| 498 | { |
---|
| 499 | int minor; |
---|
| 500 | |
---|
[ab2dbd7] | 501 | for(minor=0 ; minor<Console_Port_Count ; minor++) { |
---|
[198d851] | 502 | if(Console_Port_Tbl[minor].ulIntVector == vector && |
---|
| 503 | Console_Port_Tbl[minor].deviceType == SERIAL_MC68681 ) { |
---|
[cd58d82] | 504 | mc68681_process(minor); |
---|
| 505 | } |
---|
| 506 | } |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | /* |
---|
| 510 | * mc68681_flush |
---|
[beaaf49f] | 511 | * |
---|
| 512 | * This routine waits before all output is completed before closing |
---|
| 513 | * the requested port. |
---|
| 514 | * |
---|
| 515 | * NOTE: This is the "interrupt mode" close entry point. |
---|
[cd58d82] | 516 | */ |
---|
[ab2dbd7] | 517 | |
---|
[198d851] | 518 | /* XXX remove me */ |
---|
[2d8e51aa] | 519 | MC68681_STATIC int mc68681_flush(int major, int minor, void *arg) |
---|
[cd58d82] | 520 | { |
---|
[198d851] | 521 | #if 0 |
---|
[cd58d82] | 522 | while(!Ring_buffer_Is_empty(&Console_Port_Data[minor].TxBuffer)) { |
---|
| 523 | /* |
---|
| 524 | * Yield while we wait |
---|
| 525 | */ |
---|
| 526 | if(_System_state_Is_up(_System_state_Get())) { |
---|
| 527 | rtems_task_wake_after(RTEMS_YIELD_PROCESSOR); |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | mc68681_close(major, minor, arg); |
---|
| 532 | |
---|
[198d851] | 533 | #endif |
---|
[cd58d82] | 534 | return(RTEMS_SUCCESSFUL); |
---|
| 535 | } |
---|
| 536 | |
---|
[beaaf49f] | 537 | /* |
---|
| 538 | * mc68681_initialize_interrupts |
---|
| 539 | * |
---|
| 540 | * This routine initializes the console's receive and transmit |
---|
| 541 | * ring buffers and loads the appropriate vectors to handle the interrupts. |
---|
| 542 | */ |
---|
| 543 | |
---|
[2d8e51aa] | 544 | MC68681_STATIC void mc68681_initialize_interrupts(int minor) |
---|
[cd58d82] | 545 | { |
---|
| 546 | mc68681_init(minor); |
---|
| 547 | |
---|
| 548 | Console_Port_Data[minor].bActive = FALSE; |
---|
| 549 | |
---|
| 550 | set_vector(mc68681_isr, Console_Port_Tbl[minor].ulIntVector, 1); |
---|
| 551 | |
---|
[198d851] | 552 | mc68681_enable_interrupts(minor,MC68681_IMR_ENABLE_ALL_EXCEPT_TX); |
---|
[cd58d82] | 553 | } |
---|
| 554 | |
---|
| 555 | /* |
---|
| 556 | * mc68681_write_support_int |
---|
| 557 | * |
---|
[beaaf49f] | 558 | * Console Termios output entry point when using interrupt driven output. |
---|
[cd58d82] | 559 | */ |
---|
[ab2dbd7] | 560 | |
---|
[2d8e51aa] | 561 | MC68681_STATIC int mc68681_write_support_int( |
---|
[be8cbbf] | 562 | int minor, |
---|
[cd58d82] | 563 | const char *buf, |
---|
[be8cbbf] | 564 | int len |
---|
[cd58d82] | 565 | ) |
---|
| 566 | { |
---|
[198d851] | 567 | unsigned32 Irql; |
---|
| 568 | unsigned32 pMC68681_port; |
---|
| 569 | setRegister_f setReg; |
---|
| 570 | |
---|
| 571 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 572 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
[cd58d82] | 573 | |
---|
| 574 | /* |
---|
[198d851] | 575 | * We are using interrupt driven output and termios only sends us one character |
---|
| 576 | * at a time. |
---|
[cd58d82] | 577 | */ |
---|
[ab2dbd7] | 578 | |
---|
[198d851] | 579 | if ( !len ) |
---|
| 580 | return 0; |
---|
[cd58d82] | 581 | |
---|
[198d851] | 582 | /* |
---|
| 583 | * Wake up the device |
---|
| 584 | */ |
---|
| 585 | rtems_interrupt_disable(Irql); |
---|
| 586 | Console_Port_Data[minor].bActive = TRUE; |
---|
| 587 | (*setReg)(pMC68681_port, MC68681_TX_BUFFER, *buf); |
---|
| 588 | mc68681_enable_interrupts(minor, MC68681_IMR_ENABLE_ALL); |
---|
| 589 | rtems_interrupt_enable(Irql); |
---|
| 590 | return 1; |
---|
[cd58d82] | 591 | } |
---|
| 592 | |
---|
| 593 | /* |
---|
| 594 | * mc68681_write_support_polled |
---|
| 595 | * |
---|
[beaaf49f] | 596 | * Console Termios output entry point when using polled output. |
---|
[cd58d82] | 597 | * |
---|
| 598 | */ |
---|
[ab2dbd7] | 599 | |
---|
[2d8e51aa] | 600 | MC68681_STATIC int mc68681_write_support_polled( |
---|
[cd58d82] | 601 | int minor, |
---|
| 602 | const char *buf, |
---|
| 603 | int len |
---|
| 604 | ) |
---|
| 605 | { |
---|
| 606 | int nwrite = 0; |
---|
| 607 | |
---|
| 608 | /* |
---|
| 609 | * poll each byte in the string out of the port. |
---|
| 610 | */ |
---|
| 611 | while (nwrite < len) { |
---|
| 612 | /* |
---|
| 613 | * transmit character |
---|
| 614 | */ |
---|
| 615 | mc68681_write_polled(minor, *buf++); |
---|
| 616 | nwrite++; |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | /* |
---|
| 620 | * return the number of bytes written. |
---|
| 621 | */ |
---|
| 622 | return nwrite; |
---|
| 623 | } |
---|
| 624 | |
---|
| 625 | /* |
---|
| 626 | * mc68681_inbyte_nonblocking_polled |
---|
| 627 | * |
---|
| 628 | * Console Termios polling input entry point. |
---|
| 629 | */ |
---|
| 630 | |
---|
[2d8e51aa] | 631 | MC68681_STATIC int mc68681_inbyte_nonblocking_polled( |
---|
[cd58d82] | 632 | int minor |
---|
| 633 | ) |
---|
| 634 | { |
---|
[25c3ff91] | 635 | unsigned32 pMC68681_port; |
---|
[cd58d82] | 636 | unsigned char ucLineStatus; |
---|
[2c5ea01] | 637 | unsigned char cChar; |
---|
[cd58d82] | 638 | getRegister_f getReg; |
---|
| 639 | |
---|
[25c3ff91] | 640 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 641 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
[cd58d82] | 642 | |
---|
[25c3ff91] | 643 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
[ab2dbd7] | 644 | if(ucLineStatus & MC68681_RX_READY) { |
---|
[25c3ff91] | 645 | cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER); |
---|
[ab2dbd7] | 646 | return (int)cChar; |
---|
[cd58d82] | 647 | } else { |
---|
[25c3ff91] | 648 | return -1; |
---|
[cd58d82] | 649 | } |
---|
| 650 | } |
---|
[2d8e51aa] | 651 | |
---|
| 652 | MC68681_STATIC int mc68681_baud_rate( |
---|
| 653 | int minor, |
---|
| 654 | int baud, |
---|
| 655 | unsigned int *baud_mask_p, |
---|
| 656 | unsigned int *acr_bit_p, |
---|
| 657 | unsigned int *command |
---|
| 658 | ) |
---|
| 659 | { |
---|
| 660 | unsigned int baud_mask; |
---|
| 661 | unsigned int acr_bit; |
---|
| 662 | int status; |
---|
| 663 | int is_extended; |
---|
| 664 | int baud_requested; |
---|
| 665 | mc68681_baud_table_t *baud_tbl; |
---|
| 666 | |
---|
| 667 | baud_mask = 0; |
---|
| 668 | acr_bit = 0; |
---|
| 669 | status = 0; |
---|
| 670 | |
---|
| 671 | if ( !(Console_Port_Tbl[minor].ulDataPort & MC68681_DATA_BAUD_RATE_SET_1) ) |
---|
| 672 | acr_bit = 1; |
---|
| 673 | |
---|
| 674 | is_extended = 0; |
---|
| 675 | |
---|
| 676 | switch (Console_Port_Tbl[minor].ulDataPort & MC68681_XBRG_MASK) { |
---|
| 677 | case MC68681_XBRG_IGNORED: |
---|
| 678 | *command = 0x00; |
---|
| 679 | break; |
---|
| 680 | case MC68681_XBRG_ENABLED: |
---|
[2c5ea01] | 681 | *command = 0x80; |
---|
[2d8e51aa] | 682 | is_extended = 1; |
---|
| 683 | break; |
---|
| 684 | case MC68681_XBRG_DISABLED: |
---|
[2c5ea01] | 685 | *command = 0x90; |
---|
[2d8e51aa] | 686 | break; |
---|
| 687 | } |
---|
| 688 | |
---|
| 689 | baud_requested = baud & CBAUD; |
---|
| 690 | if (!baud_requested) |
---|
[2c5ea01] | 691 | baud_requested = B9600; /* default to 9600 baud */ |
---|
[2d8e51aa] | 692 | |
---|
| 693 | baud_requested = termios_baud_to_index( baud_requested ); |
---|
| 694 | |
---|
| 695 | baud_tbl = (mc68681_baud_table_t *) Console_Port_Tbl[minor].ulClock; |
---|
| 696 | if (!baud_tbl) |
---|
| 697 | baud_tbl = (mc68681_baud_table_t *)mc68681_baud_rate_table; |
---|
| 698 | |
---|
| 699 | if ( is_extended ) |
---|
| 700 | baud_mask = (unsigned int)baud_tbl[ acr_bit + 2 ][ baud_requested ]; |
---|
| 701 | else |
---|
| 702 | baud_mask = baud_tbl[ acr_bit ][ baud_requested ]; |
---|
| 703 | |
---|
| 704 | if ( baud_mask == MC68681_BAUD_NOT_VALID ) |
---|
| 705 | status = -1; |
---|
| 706 | |
---|
[2c5ea01] | 707 | /* |
---|
| 708 | * upper nibble is receiver and lower nibble is transmitter |
---|
| 709 | */ |
---|
| 710 | |
---|
| 711 | *baud_mask_p = (baud_mask << 4) | baud_mask; |
---|
[2d8e51aa] | 712 | *acr_bit_p = acr_bit; |
---|
| 713 | return status; |
---|
| 714 | } |
---|
| 715 | |
---|
[be8cbbf] | 716 | /* |
---|
| 717 | * mc68681_process |
---|
| 718 | * |
---|
| 719 | * This routine is the per port console interrupt handler. |
---|
| 720 | */ |
---|
| 721 | |
---|
| 722 | MC68681_STATIC void mc68681_process( |
---|
| 723 | int minor |
---|
| 724 | ) |
---|
| 725 | { |
---|
| 726 | unsigned32 pMC68681; |
---|
| 727 | unsigned32 pMC68681_port; |
---|
| 728 | volatile unsigned8 ucLineStatus; |
---|
| 729 | char cChar; |
---|
| 730 | getRegister_f getReg; |
---|
| 731 | setRegister_f setReg; |
---|
| 732 | |
---|
| 733 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 734 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 735 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
| 736 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 737 | |
---|
| 738 | /* |
---|
| 739 | * Deal with any received characters |
---|
| 740 | */ |
---|
| 741 | while(TRUE) { |
---|
| 742 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
| 743 | if(!(ucLineStatus & MC68681_RX_READY)) { |
---|
| 744 | break; |
---|
| 745 | } |
---|
| 746 | /* |
---|
| 747 | * If there is a RX error, then dump all the data. |
---|
| 748 | */ |
---|
| 749 | if ( ucLineStatus & MC68681_RX_ERRORS ) { |
---|
| 750 | do { |
---|
| 751 | cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER); |
---|
| 752 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
| 753 | } while ( ucLineStatus & MC68681_RX_READY ); |
---|
| 754 | continue; |
---|
| 755 | } |
---|
| 756 | cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER); |
---|
| 757 | rtems_termios_enqueue_raw_characters( |
---|
| 758 | Console_Port_Data[minor].termios_data, |
---|
| 759 | &cChar, |
---|
| 760 | 1 |
---|
| 761 | ); |
---|
| 762 | } |
---|
| 763 | |
---|
| 764 | /* |
---|
| 765 | * Deal with the transmitter |
---|
| 766 | */ |
---|
| 767 | |
---|
[198d851] | 768 | ucLineStatus = (*getReg)(pMC68681, MC68681_INTERRUPT_STATUS_REG); |
---|
| 769 | if (pMC68681 != pMC68681_port) |
---|
| 770 | ucLineStatus >>= 4; |
---|
[be8cbbf] | 771 | |
---|
[198d851] | 772 | if(ucLineStatus & MC68681_IR_TX_READY) { |
---|
| 773 | mc68681_enable_interrupts(minor, MC68681_IMR_ENABLE_ALL_EXCEPT_TX); |
---|
| 774 | rtems_termios_dequeue_characters(Console_Port_Data[minor].termios_data, 1); |
---|
[be8cbbf] | 775 | } |
---|
| 776 | |
---|
| 777 | } |
---|
| 778 | |
---|
| 779 | /* |
---|
| 780 | * mc68681_build_imr |
---|
| 781 | * |
---|
| 782 | * This function returns the value for the interrupt mask register for this |
---|
| 783 | * DUART. Since this is a shared register, we must look at the other port |
---|
| 784 | * on this chip to determine whether or not it is using interrupts. |
---|
| 785 | */ |
---|
| 786 | |
---|
| 787 | MC68681_STATIC unsigned int mc68681_build_imr( |
---|
| 788 | int minor, |
---|
| 789 | int enable_flag |
---|
| 790 | ) |
---|
| 791 | { |
---|
| 792 | int mate; |
---|
[198d851] | 793 | int is_a; |
---|
[be8cbbf] | 794 | unsigned int mask; |
---|
| 795 | unsigned int mate_mask; |
---|
| 796 | unsigned int pMC68681; |
---|
| 797 | unsigned int pMC68681_port; |
---|
| 798 | mc68681_context *pmc68681Context; |
---|
[198d851] | 799 | mc68681_context *mateContext; |
---|
[be8cbbf] | 800 | |
---|
| 801 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 802 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 803 | pmc68681Context = (mc68681_context *) Console_Port_Data[minor].pDeviceContext; |
---|
| 804 | mate = pmc68681Context->mate; |
---|
| 805 | |
---|
[198d851] | 806 | mask = 0; |
---|
[be8cbbf] | 807 | mate_mask = 0; |
---|
| 808 | |
---|
[198d851] | 809 | is_a = (pMC68681 == pMC68681_port); |
---|
| 810 | |
---|
[be8cbbf] | 811 | /* |
---|
[198d851] | 812 | * If there is a mate for this port, get its IMR mask. |
---|
[be8cbbf] | 813 | */ |
---|
| 814 | |
---|
| 815 | if ( mate != -1 ) { |
---|
[198d851] | 816 | mateContext = Console_Port_Data[mate].pDeviceContext; |
---|
| 817 | |
---|
| 818 | if (mateContext) |
---|
| 819 | mate_mask = mateContext->imr; |
---|
| 820 | } |
---|
[be8cbbf] | 821 | |
---|
[198d851] | 822 | /* |
---|
| 823 | * Calculate this port's IMR mask and save it in the context area. |
---|
| 824 | */ |
---|
[be8cbbf] | 825 | |
---|
[198d851] | 826 | if ( Console_Port_Tbl[minor].pDeviceFns->deviceOutputUsesInterrupts ) |
---|
| 827 | mask = enable_flag; |
---|
| 828 | |
---|
| 829 | pmc68681Context->imr = mask; |
---|
[be8cbbf] | 830 | |
---|
| 831 | /* |
---|
[198d851] | 832 | * Now return the full IMR value |
---|
[be8cbbf] | 833 | */ |
---|
| 834 | |
---|
[198d851] | 835 | if (is_a) |
---|
| 836 | return (mate_mask << 4) | mask; |
---|
| 837 | |
---|
| 838 | return (mask << 4) | mate_mask; |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | /* |
---|
| 842 | * mc68681_enable_interrupts |
---|
| 843 | * |
---|
| 844 | * This function initializes the hardware for this port to use interrupts. |
---|
| 845 | */ |
---|
| 846 | |
---|
| 847 | MC68681_STATIC void mc68681_enable_interrupts( |
---|
| 848 | int minor, |
---|
| 849 | int imr_mask |
---|
| 850 | ) |
---|
| 851 | { |
---|
| 852 | unsigned32 pMC68681; |
---|
| 853 | setRegister_f setReg; |
---|
| 854 | |
---|
| 855 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 856 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 857 | |
---|
| 858 | /* |
---|
| 859 | * Enable interrupts on RX and TX -- not break |
---|
| 860 | */ |
---|
[be8cbbf] | 861 | |
---|
[198d851] | 862 | (*setReg)( |
---|
| 863 | pMC68681, |
---|
| 864 | MC68681_INTERRUPT_MASK_REG, |
---|
| 865 | mc68681_build_imr(minor, imr_mask) |
---|
| 866 | ); |
---|
[be8cbbf] | 867 | } |
---|
| 868 | |
---|