[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> |
---|
[a6f441b] | 26 | #include <libchip/mc68681.h> |
---|
[2d8e51aa] | 27 | #include "sersupp.h" |
---|
[cd58d82] | 28 | #include "mc68681_p.h" |
---|
| 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 | MC68681_STATIC int mc68681_baud_rate( |
---|
[25c3ff91] | 75 | int minor, |
---|
| 76 | int baud, |
---|
| 77 | unsigned int *baud_mask_p, |
---|
[2d8e51aa] | 78 | unsigned int *acr_bit_p, |
---|
| 79 | unsigned int *command |
---|
| 80 | ); |
---|
[25c3ff91] | 81 | |
---|
[beaaf49f] | 82 | /* |
---|
| 83 | * mc68681_set_attributes |
---|
| 84 | * |
---|
| 85 | * This function sets the DUART channel to reflect the requested termios |
---|
| 86 | * port settings. |
---|
| 87 | */ |
---|
| 88 | |
---|
[2d8e51aa] | 89 | MC68681_STATIC int mc68681_set_attributes( |
---|
[25c3ff91] | 90 | int minor, |
---|
| 91 | const struct termios *t |
---|
| 92 | ) |
---|
| 93 | { |
---|
| 94 | unsigned32 pMC68681_port; |
---|
| 95 | unsigned32 pMC68681; |
---|
| 96 | unsigned int mode1; |
---|
| 97 | unsigned int mode2; |
---|
| 98 | unsigned int baud_mask; |
---|
| 99 | unsigned int acr_bit; |
---|
[2d8e51aa] | 100 | unsigned int cmd; |
---|
[25c3ff91] | 101 | setRegister_f setReg; |
---|
| 102 | rtems_interrupt_level Irql; |
---|
[cd58d82] | 103 | |
---|
[4f0ffa57] | 104 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 105 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
[7deeb16] | 106 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 107 | |
---|
| 108 | /* |
---|
[25c3ff91] | 109 | * Set the baud rate |
---|
[7deeb16] | 110 | */ |
---|
| 111 | |
---|
[2d8e51aa] | 112 | if (mc68681_baud_rate( minor, t->c_cflag, &baud_mask, &acr_bit, &cmd ) == -1) |
---|
[25c3ff91] | 113 | return -1; |
---|
| 114 | |
---|
| 115 | baud_mask |= baud_mask << 4; |
---|
| 116 | acr_bit <<= 7; |
---|
[7deeb16] | 117 | |
---|
| 118 | /* |
---|
[25c3ff91] | 119 | * Parity |
---|
[7deeb16] | 120 | */ |
---|
| 121 | |
---|
[25c3ff91] | 122 | mode1 = 0; |
---|
| 123 | mode2 = 0; |
---|
[7deeb16] | 124 | |
---|
[25c3ff91] | 125 | if (t->c_cflag & PARENB) { |
---|
| 126 | if (t->c_cflag & PARODD) |
---|
| 127 | mode1 |= 0x04; |
---|
| 128 | else |
---|
| 129 | mode1 |= 0x04; |
---|
| 130 | } else { |
---|
| 131 | mode1 |= 0x10; |
---|
| 132 | } |
---|
[cd58d82] | 133 | |
---|
[25c3ff91] | 134 | /* |
---|
| 135 | * Character Size |
---|
[cd58d82] | 136 | */ |
---|
| 137 | |
---|
[25c3ff91] | 138 | if (t->c_cflag & CSIZE) { |
---|
| 139 | switch (t->c_cflag & CSIZE) { |
---|
| 140 | case CS5: break; |
---|
| 141 | case CS6: mode1 |= 0x01; break; |
---|
| 142 | case CS7: mode1 |= 0x02; break; |
---|
| 143 | case CS8: mode1 |= 0x03; break; |
---|
| 144 | } |
---|
| 145 | } else { |
---|
| 146 | mode1 |= 0x03; /* default to 9600,8,N,1 */ |
---|
| 147 | } |
---|
[cd58d82] | 148 | |
---|
[25c3ff91] | 149 | /* |
---|
| 150 | * Stop Bits |
---|
| 151 | */ |
---|
| 152 | |
---|
| 153 | if (t->c_cflag & CSTOPB) { |
---|
| 154 | mode2 |= 0x07; /* 2 stop bits */ |
---|
| 155 | } else { |
---|
| 156 | if ((t->c_cflag & CSIZE) == CS5) /* CS5 and 2 stop bits not supported */ |
---|
| 157 | return -1; |
---|
| 158 | mode2 |= 0x0F; /* 1 stop bit */ |
---|
| 159 | } |
---|
[cd58d82] | 160 | |
---|
[25c3ff91] | 161 | rtems_interrupt_disable(Irql); |
---|
| 162 | (*setReg)( pMC68681, MC68681_AUX_CTRL_REG, acr_bit ); |
---|
| 163 | (*setReg)( pMC68681_port, MC68681_CLOCK_SELECT, baud_mask ); |
---|
[2c5ea01] | 164 | if ( cmd ) { |
---|
| 165 | (*setReg)( pMC68681_port, MC68681_COMMAND, cmd ); /* RX */ |
---|
| 166 | (*setReg)( pMC68681_port, MC68681_COMMAND, cmd | 0x20 ); /* TX */ |
---|
| 167 | } |
---|
[25c3ff91] | 168 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_MR_PTR ); |
---|
| 169 | (*setReg)( pMC68681_port, MC68681_MODE, mode1 ); |
---|
| 170 | (*setReg)( pMC68681_port, MC68681_MODE, mode2 ); |
---|
| 171 | rtems_interrupt_enable(Irql); |
---|
| 172 | return 0; |
---|
| 173 | } |
---|
[cd58d82] | 174 | |
---|
[beaaf49f] | 175 | /* |
---|
| 176 | * mc68681_initialize_context |
---|
| 177 | * |
---|
| 178 | * This function sets the default values of the per port context structure. |
---|
| 179 | */ |
---|
| 180 | |
---|
[2d8e51aa] | 181 | MC68681_STATIC void mc68681_initialize_context( |
---|
[a5d0c7c] | 182 | int minor, |
---|
| 183 | mc68681_context *pmc68681Context |
---|
| 184 | ) |
---|
| 185 | { |
---|
| 186 | int port; |
---|
| 187 | unsigned int pMC68681; |
---|
[be8cbbf] | 188 | unsigned int pMC68681_port; |
---|
[a5d0c7c] | 189 | |
---|
[be8cbbf] | 190 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 191 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
[a5d0c7c] | 192 | |
---|
| 193 | pmc68681Context->mate = -1; |
---|
| 194 | |
---|
| 195 | for (port=0 ; port<Console_Port_Count ; port++ ) { |
---|
[be8cbbf] | 196 | if ( Console_Port_Tbl[port].ulCtrlPort1 == pMC68681 && |
---|
| 197 | Console_Port_Tbl[port].ulCtrlPort2 != pMC68681_port ) { |
---|
[a5d0c7c] | 198 | pmc68681Context->mate = port; |
---|
[198d851] | 199 | pmc68681Context->imr = 0; |
---|
[a5d0c7c] | 200 | break; |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | } |
---|
| 205 | |
---|
[beaaf49f] | 206 | /* |
---|
| 207 | * mc68681_init |
---|
| 208 | * |
---|
| 209 | * This function initializes the DUART to a quiecsent state. |
---|
| 210 | */ |
---|
| 211 | |
---|
[2d8e51aa] | 212 | MC68681_STATIC void mc68681_init(int minor) |
---|
[25c3ff91] | 213 | { |
---|
| 214 | unsigned32 pMC68681_port; |
---|
| 215 | unsigned32 pMC68681; |
---|
| 216 | mc68681_context *pmc68681Context; |
---|
| 217 | setRegister_f setReg; |
---|
| 218 | getRegister_f getReg; |
---|
| 219 | |
---|
| 220 | pmc68681Context = (mc68681_context *) malloc(sizeof(mc68681_context)); |
---|
[cd58d82] | 221 | |
---|
[25c3ff91] | 222 | Console_Port_Data[minor].pDeviceContext = (void *)pmc68681Context; |
---|
[a5d0c7c] | 223 | |
---|
| 224 | mc68681_initialize_context( minor, pmc68681Context ); |
---|
[cd58d82] | 225 | |
---|
[4f0ffa57] | 226 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 227 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
[25c3ff91] | 228 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 229 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
[cd58d82] | 230 | |
---|
| 231 | /* |
---|
[25c3ff91] | 232 | * Reset everything and leave this port disabled. |
---|
[cd58d82] | 233 | */ |
---|
| 234 | |
---|
[198d851] | 235 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_RX ); |
---|
| 236 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_TX ); |
---|
| 237 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_ERROR ); |
---|
| 238 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_BREAK ); |
---|
| 239 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_STOP_BREAK ); |
---|
| 240 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_TX ); |
---|
| 241 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_RX ); |
---|
[cd58d82] | 242 | |
---|
[25c3ff91] | 243 | |
---|
[198d851] | 244 | (*setReg)( pMC68681_port, MC68681_MODE_REG_1A, 0x00 ); |
---|
| 245 | (*setReg)( pMC68681_port, MC68681_MODE_REG_2A, 0x02 ); |
---|
[4f0ffa57] | 246 | |
---|
| 247 | /* |
---|
| 248 | * Disable interrupts on RX and TX for this port |
---|
| 249 | */ |
---|
| 250 | |
---|
[198d851] | 251 | mc68681_enable_interrupts( minor, MC68681_IMR_DISABLE_ALL ); |
---|
[cd58d82] | 252 | } |
---|
| 253 | |
---|
[25c3ff91] | 254 | /* |
---|
[beaaf49f] | 255 | * mc68681_open |
---|
| 256 | * |
---|
| 257 | * This function opens a port for communication. |
---|
| 258 | * |
---|
| 259 | * Default state is 9600 baud, 8 bits, No parity, and 1 stop bit. |
---|
[25c3ff91] | 260 | */ |
---|
| 261 | |
---|
[2d8e51aa] | 262 | MC68681_STATIC int mc68681_open( |
---|
[cd58d82] | 263 | int major, |
---|
| 264 | int minor, |
---|
[25c3ff91] | 265 | void *arg |
---|
[cd58d82] | 266 | ) |
---|
| 267 | { |
---|
[25c3ff91] | 268 | unsigned32 pMC68681; |
---|
| 269 | unsigned32 pMC68681_port; |
---|
| 270 | unsigned int baud; |
---|
| 271 | unsigned int acr; |
---|
| 272 | unsigned int vector; |
---|
[2d8e51aa] | 273 | unsigned int command; |
---|
[25c3ff91] | 274 | rtems_interrupt_level Irql; |
---|
| 275 | setRegister_f setReg; |
---|
| 276 | |
---|
| 277 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 278 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 279 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 280 | vector = Console_Port_Tbl[minor].ulIntVector; |
---|
| 281 | |
---|
[e78c474b] | 282 | /* XXX default baud rate should be from configuration table */ |
---|
| 283 | |
---|
[2d8e51aa] | 284 | (void) mc68681_baud_rate( minor, B9600, &baud, &acr, &command ); |
---|
[25c3ff91] | 285 | |
---|
[b7ebcea3] | 286 | /* |
---|
| 287 | * Set the DUART channel to a default useable state |
---|
| 288 | */ |
---|
| 289 | |
---|
[25c3ff91] | 290 | rtems_interrupt_disable(Irql); |
---|
| 291 | (*setReg)( pMC68681, MC68681_AUX_CTRL_REG, acr ); |
---|
| 292 | (*setReg)( pMC68681_port, MC68681_CLOCK_SELECT, baud ); |
---|
[e78c474b] | 293 | if ( command ) { |
---|
| 294 | (*setReg)( pMC68681_port, MC68681_COMMAND, command ); /* RX */ |
---|
| 295 | (*setReg)( pMC68681_port, MC68681_COMMAND, command | 0x20 ); /* TX */ |
---|
| 296 | } |
---|
[25c3ff91] | 297 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_MR_PTR ); |
---|
| 298 | (*setReg)( pMC68681_port, MC68681_MODE, 0x13 ); |
---|
| 299 | (*setReg)( pMC68681_port, MC68681_MODE, 0x07 ); |
---|
| 300 | rtems_interrupt_enable(Irql); |
---|
| 301 | |
---|
| 302 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_ENABLE_TX ); |
---|
| 303 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_ENABLE_RX ); |
---|
| 304 | |
---|
| 305 | (*setReg)( pMC68681, MC68681_INTERRUPT_VECTOR_REG, vector ); |
---|
| 306 | |
---|
[4f0ffa57] | 307 | return RTEMS_SUCCESSFUL; |
---|
[cd58d82] | 308 | } |
---|
| 309 | |
---|
[beaaf49f] | 310 | /* |
---|
| 311 | * mc68681_close |
---|
| 312 | * |
---|
| 313 | * This function shuts down the requested port. |
---|
| 314 | */ |
---|
| 315 | |
---|
[2d8e51aa] | 316 | MC68681_STATIC int mc68681_close( |
---|
[cd58d82] | 317 | int major, |
---|
| 318 | int minor, |
---|
[25c3ff91] | 319 | void *arg |
---|
[cd58d82] | 320 | ) |
---|
| 321 | { |
---|
[b7ebcea3] | 322 | unsigned32 pMC68681; |
---|
| 323 | unsigned32 pMC68681_port; |
---|
| 324 | setRegister_f setReg; |
---|
| 325 | |
---|
| 326 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 327 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 328 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 329 | |
---|
| 330 | /* |
---|
| 331 | * Disable interrupts from this channel and then disable it totally. |
---|
| 332 | */ |
---|
| 333 | |
---|
| 334 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_TX ); |
---|
| 335 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_RX ); |
---|
| 336 | |
---|
[cd58d82] | 337 | return(RTEMS_SUCCESSFUL); |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | /* |
---|
| 341 | * mc68681_write_polled |
---|
[beaaf49f] | 342 | * |
---|
| 343 | * This routine polls out the requested character. |
---|
[cd58d82] | 344 | */ |
---|
[424e23ee] | 345 | |
---|
[2d8e51aa] | 346 | MC68681_STATIC void mc68681_write_polled( |
---|
[cd58d82] | 347 | int minor, |
---|
| 348 | char cChar |
---|
| 349 | ) |
---|
| 350 | { |
---|
[25c3ff91] | 351 | unsigned32 pMC68681_port; |
---|
[cd58d82] | 352 | unsigned char ucLineStatus; |
---|
| 353 | int iTimeout; |
---|
| 354 | getRegister_f getReg; |
---|
[25c3ff91] | 355 | setRegister_f setReg; |
---|
[cd58d82] | 356 | |
---|
[25c3ff91] | 357 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 358 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
| 359 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
[cd58d82] | 360 | |
---|
| 361 | /* |
---|
| 362 | * wait for transmitter holding register to be empty |
---|
| 363 | */ |
---|
[ab2dbd7] | 364 | iTimeout = 1000; |
---|
[25c3ff91] | 365 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
[2c5ea01] | 366 | while ((ucLineStatus & (MC68681_TX_READY|MC68681_TX_EMPTY)) == 0) { |
---|
| 367 | |
---|
| 368 | if ((ucLineStatus & 0xF0)) |
---|
| 369 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_ERROR ); |
---|
[ab2dbd7] | 370 | |
---|
[cd58d82] | 371 | /* |
---|
| 372 | * Yield while we wait |
---|
| 373 | */ |
---|
[ab2dbd7] | 374 | |
---|
[cd58d82] | 375 | if(_System_state_Is_up(_System_state_Get())) { |
---|
| 376 | rtems_task_wake_after(RTEMS_YIELD_PROCESSOR); |
---|
| 377 | } |
---|
[25c3ff91] | 378 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
[cd58d82] | 379 | if(!--iTimeout) { |
---|
| 380 | break; |
---|
| 381 | } |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | /* |
---|
| 385 | * transmit character |
---|
| 386 | */ |
---|
[ab2dbd7] | 387 | |
---|
[25c3ff91] | 388 | (*setReg)(pMC68681_port, MC68681_TX_BUFFER, cChar); |
---|
[cd58d82] | 389 | } |
---|
| 390 | |
---|
[4f0ffa57] | 391 | /* |
---|
| 392 | * mc68681_isr |
---|
| 393 | * |
---|
| 394 | * This is the single interrupt entry point which parcels interrupts |
---|
| 395 | * out to the various ports. |
---|
| 396 | */ |
---|
| 397 | |
---|
[2d8e51aa] | 398 | MC68681_STATIC rtems_isr mc68681_isr( |
---|
[cd58d82] | 399 | rtems_vector_number vector |
---|
| 400 | ) |
---|
| 401 | { |
---|
| 402 | int minor; |
---|
| 403 | |
---|
[ab2dbd7] | 404 | for(minor=0 ; minor<Console_Port_Count ; minor++) { |
---|
[198d851] | 405 | if(Console_Port_Tbl[minor].ulIntVector == vector && |
---|
| 406 | Console_Port_Tbl[minor].deviceType == SERIAL_MC68681 ) { |
---|
[cd58d82] | 407 | mc68681_process(minor); |
---|
| 408 | } |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | |
---|
[beaaf49f] | 412 | /* |
---|
| 413 | * mc68681_initialize_interrupts |
---|
| 414 | * |
---|
| 415 | * This routine initializes the console's receive and transmit |
---|
| 416 | * ring buffers and loads the appropriate vectors to handle the interrupts. |
---|
| 417 | */ |
---|
| 418 | |
---|
[2d8e51aa] | 419 | MC68681_STATIC void mc68681_initialize_interrupts(int minor) |
---|
[cd58d82] | 420 | { |
---|
| 421 | mc68681_init(minor); |
---|
| 422 | |
---|
| 423 | Console_Port_Data[minor].bActive = FALSE; |
---|
| 424 | |
---|
| 425 | set_vector(mc68681_isr, Console_Port_Tbl[minor].ulIntVector, 1); |
---|
| 426 | |
---|
[198d851] | 427 | mc68681_enable_interrupts(minor,MC68681_IMR_ENABLE_ALL_EXCEPT_TX); |
---|
[cd58d82] | 428 | } |
---|
| 429 | |
---|
| 430 | /* |
---|
| 431 | * mc68681_write_support_int |
---|
| 432 | * |
---|
[beaaf49f] | 433 | * Console Termios output entry point when using interrupt driven output. |
---|
[cd58d82] | 434 | */ |
---|
[ab2dbd7] | 435 | |
---|
[2d8e51aa] | 436 | MC68681_STATIC int mc68681_write_support_int( |
---|
[be8cbbf] | 437 | int minor, |
---|
[cd58d82] | 438 | const char *buf, |
---|
[be8cbbf] | 439 | int len |
---|
[cd58d82] | 440 | ) |
---|
| 441 | { |
---|
[198d851] | 442 | unsigned32 Irql; |
---|
| 443 | unsigned32 pMC68681_port; |
---|
| 444 | setRegister_f setReg; |
---|
| 445 | |
---|
| 446 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 447 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
[cd58d82] | 448 | |
---|
| 449 | /* |
---|
[b070d69a] | 450 | * We are using interrupt driven output and termios only sends us |
---|
| 451 | * one character at a time. |
---|
[cd58d82] | 452 | */ |
---|
[ab2dbd7] | 453 | |
---|
[198d851] | 454 | if ( !len ) |
---|
| 455 | return 0; |
---|
[cd58d82] | 456 | |
---|
[198d851] | 457 | /* |
---|
[b070d69a] | 458 | * Put the character out and enable interrupts if necessary. |
---|
[198d851] | 459 | */ |
---|
[b070d69a] | 460 | |
---|
[198d851] | 461 | rtems_interrupt_disable(Irql); |
---|
[c68b990] | 462 | if ( Console_Port_Data[minor].bActive == FALSE ) { |
---|
| 463 | Console_Port_Data[minor].bActive = TRUE; |
---|
| 464 | mc68681_enable_interrupts(minor, MC68681_IMR_ENABLE_ALL); |
---|
| 465 | } |
---|
[198d851] | 466 | (*setReg)(pMC68681_port, MC68681_TX_BUFFER, *buf); |
---|
| 467 | rtems_interrupt_enable(Irql); |
---|
[b070d69a] | 468 | |
---|
[198d851] | 469 | return 1; |
---|
[cd58d82] | 470 | } |
---|
| 471 | |
---|
| 472 | /* |
---|
| 473 | * mc68681_write_support_polled |
---|
| 474 | * |
---|
[beaaf49f] | 475 | * Console Termios output entry point when using polled output. |
---|
[cd58d82] | 476 | * |
---|
| 477 | */ |
---|
[ab2dbd7] | 478 | |
---|
[2d8e51aa] | 479 | MC68681_STATIC int mc68681_write_support_polled( |
---|
[cd58d82] | 480 | int minor, |
---|
| 481 | const char *buf, |
---|
| 482 | int len |
---|
| 483 | ) |
---|
| 484 | { |
---|
| 485 | int nwrite = 0; |
---|
| 486 | |
---|
| 487 | /* |
---|
| 488 | * poll each byte in the string out of the port. |
---|
| 489 | */ |
---|
| 490 | while (nwrite < len) { |
---|
| 491 | /* |
---|
| 492 | * transmit character |
---|
| 493 | */ |
---|
| 494 | mc68681_write_polled(minor, *buf++); |
---|
| 495 | nwrite++; |
---|
| 496 | } |
---|
| 497 | |
---|
| 498 | /* |
---|
| 499 | * return the number of bytes written. |
---|
| 500 | */ |
---|
| 501 | return nwrite; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | /* |
---|
| 505 | * mc68681_inbyte_nonblocking_polled |
---|
| 506 | * |
---|
| 507 | * Console Termios polling input entry point. |
---|
| 508 | */ |
---|
| 509 | |
---|
[2d8e51aa] | 510 | MC68681_STATIC int mc68681_inbyte_nonblocking_polled( |
---|
[cd58d82] | 511 | int minor |
---|
| 512 | ) |
---|
| 513 | { |
---|
[25c3ff91] | 514 | unsigned32 pMC68681_port; |
---|
[cd58d82] | 515 | unsigned char ucLineStatus; |
---|
[2c5ea01] | 516 | unsigned char cChar; |
---|
[cd58d82] | 517 | getRegister_f getReg; |
---|
| 518 | |
---|
[25c3ff91] | 519 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 520 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
[cd58d82] | 521 | |
---|
[25c3ff91] | 522 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
[ab2dbd7] | 523 | if(ucLineStatus & MC68681_RX_READY) { |
---|
[25c3ff91] | 524 | cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER); |
---|
[ab2dbd7] | 525 | return (int)cChar; |
---|
[cd58d82] | 526 | } else { |
---|
[25c3ff91] | 527 | return -1; |
---|
[cd58d82] | 528 | } |
---|
| 529 | } |
---|
[2d8e51aa] | 530 | |
---|
[749c54e] | 531 | /* |
---|
| 532 | * mc68681_baud_rate |
---|
| 533 | */ |
---|
| 534 | |
---|
[2d8e51aa] | 535 | MC68681_STATIC int mc68681_baud_rate( |
---|
| 536 | int minor, |
---|
| 537 | int baud, |
---|
| 538 | unsigned int *baud_mask_p, |
---|
| 539 | unsigned int *acr_bit_p, |
---|
| 540 | unsigned int *command |
---|
| 541 | ) |
---|
| 542 | { |
---|
[dd5d2f04] | 543 | unsigned int baud_mask; |
---|
| 544 | unsigned int acr_bit; |
---|
| 545 | int status; |
---|
| 546 | int is_extended; |
---|
| 547 | int baud_requested; |
---|
[2d8e51aa] | 548 | mc68681_baud_table_t *baud_tbl; |
---|
| 549 | |
---|
| 550 | baud_mask = 0; |
---|
| 551 | acr_bit = 0; |
---|
| 552 | status = 0; |
---|
| 553 | |
---|
| 554 | if ( !(Console_Port_Tbl[minor].ulDataPort & MC68681_DATA_BAUD_RATE_SET_1) ) |
---|
| 555 | acr_bit = 1; |
---|
| 556 | |
---|
| 557 | is_extended = 0; |
---|
| 558 | |
---|
| 559 | switch (Console_Port_Tbl[minor].ulDataPort & MC68681_XBRG_MASK) { |
---|
| 560 | case MC68681_XBRG_IGNORED: |
---|
| 561 | *command = 0x00; |
---|
| 562 | break; |
---|
| 563 | case MC68681_XBRG_ENABLED: |
---|
[2c5ea01] | 564 | *command = 0x80; |
---|
[2d8e51aa] | 565 | is_extended = 1; |
---|
| 566 | break; |
---|
| 567 | case MC68681_XBRG_DISABLED: |
---|
[2c5ea01] | 568 | *command = 0x90; |
---|
[2d8e51aa] | 569 | break; |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | baud_requested = baud & CBAUD; |
---|
| 573 | if (!baud_requested) |
---|
[2c5ea01] | 574 | baud_requested = B9600; /* default to 9600 baud */ |
---|
[2d8e51aa] | 575 | |
---|
| 576 | baud_requested = termios_baud_to_index( baud_requested ); |
---|
| 577 | |
---|
| 578 | baud_tbl = (mc68681_baud_table_t *) Console_Port_Tbl[minor].ulClock; |
---|
| 579 | if (!baud_tbl) |
---|
[a6f441b] | 580 | rtems_fatal_error_occurred(RTEMS_INVALID_ADDRESS); |
---|
[2d8e51aa] | 581 | |
---|
| 582 | if ( is_extended ) |
---|
| 583 | baud_mask = (unsigned int)baud_tbl[ acr_bit + 2 ][ baud_requested ]; |
---|
| 584 | else |
---|
| 585 | baud_mask = baud_tbl[ acr_bit ][ baud_requested ]; |
---|
| 586 | |
---|
| 587 | if ( baud_mask == MC68681_BAUD_NOT_VALID ) |
---|
| 588 | status = -1; |
---|
| 589 | |
---|
[2c5ea01] | 590 | /* |
---|
| 591 | * upper nibble is receiver and lower nibble is transmitter |
---|
| 592 | */ |
---|
| 593 | |
---|
| 594 | *baud_mask_p = (baud_mask << 4) | baud_mask; |
---|
[2d8e51aa] | 595 | *acr_bit_p = acr_bit; |
---|
| 596 | return status; |
---|
| 597 | } |
---|
| 598 | |
---|
[be8cbbf] | 599 | /* |
---|
| 600 | * mc68681_process |
---|
| 601 | * |
---|
| 602 | * This routine is the per port console interrupt handler. |
---|
| 603 | */ |
---|
| 604 | |
---|
| 605 | MC68681_STATIC void mc68681_process( |
---|
| 606 | int minor |
---|
| 607 | ) |
---|
| 608 | { |
---|
| 609 | unsigned32 pMC68681; |
---|
| 610 | unsigned32 pMC68681_port; |
---|
| 611 | volatile unsigned8 ucLineStatus; |
---|
[cb27f05] | 612 | unsigned char cChar; |
---|
[be8cbbf] | 613 | getRegister_f getReg; |
---|
| 614 | setRegister_f setReg; |
---|
| 615 | |
---|
| 616 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 617 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 618 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
| 619 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 620 | |
---|
| 621 | /* |
---|
| 622 | * Deal with any received characters |
---|
| 623 | */ |
---|
| 624 | while(TRUE) { |
---|
| 625 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
| 626 | if(!(ucLineStatus & MC68681_RX_READY)) { |
---|
| 627 | break; |
---|
| 628 | } |
---|
| 629 | /* |
---|
| 630 | * If there is a RX error, then dump all the data. |
---|
| 631 | */ |
---|
| 632 | if ( ucLineStatus & MC68681_RX_ERRORS ) { |
---|
| 633 | do { |
---|
| 634 | cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER); |
---|
| 635 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
| 636 | } while ( ucLineStatus & MC68681_RX_READY ); |
---|
| 637 | continue; |
---|
| 638 | } |
---|
| 639 | cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER); |
---|
| 640 | rtems_termios_enqueue_raw_characters( |
---|
| 641 | Console_Port_Data[minor].termios_data, |
---|
| 642 | &cChar, |
---|
| 643 | 1 |
---|
| 644 | ); |
---|
| 645 | } |
---|
| 646 | |
---|
| 647 | /* |
---|
| 648 | * Deal with the transmitter |
---|
| 649 | */ |
---|
| 650 | |
---|
[198d851] | 651 | ucLineStatus = (*getReg)(pMC68681, MC68681_INTERRUPT_STATUS_REG); |
---|
| 652 | if (pMC68681 != pMC68681_port) |
---|
| 653 | ucLineStatus >>= 4; |
---|
[be8cbbf] | 654 | |
---|
[198d851] | 655 | if(ucLineStatus & MC68681_IR_TX_READY) { |
---|
[c68b990] | 656 | if (!rtems_termios_dequeue_characters( |
---|
| 657 | Console_Port_Data[minor].termios_data, 1)) { |
---|
| 658 | Console_Port_Data[minor].bActive = FALSE; |
---|
| 659 | mc68681_enable_interrupts(minor, MC68681_IMR_ENABLE_ALL_EXCEPT_TX); |
---|
| 660 | } |
---|
[be8cbbf] | 661 | } |
---|
| 662 | |
---|
| 663 | } |
---|
| 664 | |
---|
| 665 | /* |
---|
| 666 | * mc68681_build_imr |
---|
| 667 | * |
---|
| 668 | * This function returns the value for the interrupt mask register for this |
---|
| 669 | * DUART. Since this is a shared register, we must look at the other port |
---|
| 670 | * on this chip to determine whether or not it is using interrupts. |
---|
| 671 | */ |
---|
| 672 | |
---|
| 673 | MC68681_STATIC unsigned int mc68681_build_imr( |
---|
| 674 | int minor, |
---|
| 675 | int enable_flag |
---|
| 676 | ) |
---|
| 677 | { |
---|
| 678 | int mate; |
---|
[198d851] | 679 | int is_a; |
---|
[be8cbbf] | 680 | unsigned int mask; |
---|
| 681 | unsigned int mate_mask; |
---|
| 682 | unsigned int pMC68681; |
---|
| 683 | unsigned int pMC68681_port; |
---|
| 684 | mc68681_context *pmc68681Context; |
---|
[198d851] | 685 | mc68681_context *mateContext; |
---|
[be8cbbf] | 686 | |
---|
| 687 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 688 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
| 689 | pmc68681Context = (mc68681_context *) Console_Port_Data[minor].pDeviceContext; |
---|
| 690 | mate = pmc68681Context->mate; |
---|
| 691 | |
---|
[198d851] | 692 | mask = 0; |
---|
[be8cbbf] | 693 | mate_mask = 0; |
---|
| 694 | |
---|
[198d851] | 695 | is_a = (pMC68681 == pMC68681_port); |
---|
| 696 | |
---|
[be8cbbf] | 697 | /* |
---|
[198d851] | 698 | * If there is a mate for this port, get its IMR mask. |
---|
[be8cbbf] | 699 | */ |
---|
| 700 | |
---|
| 701 | if ( mate != -1 ) { |
---|
[198d851] | 702 | mateContext = Console_Port_Data[mate].pDeviceContext; |
---|
| 703 | |
---|
| 704 | if (mateContext) |
---|
| 705 | mate_mask = mateContext->imr; |
---|
| 706 | } |
---|
[be8cbbf] | 707 | |
---|
[198d851] | 708 | /* |
---|
| 709 | * Calculate this port's IMR mask and save it in the context area. |
---|
| 710 | */ |
---|
[be8cbbf] | 711 | |
---|
[198d851] | 712 | if ( Console_Port_Tbl[minor].pDeviceFns->deviceOutputUsesInterrupts ) |
---|
| 713 | mask = enable_flag; |
---|
| 714 | |
---|
| 715 | pmc68681Context->imr = mask; |
---|
[be8cbbf] | 716 | |
---|
| 717 | /* |
---|
[198d851] | 718 | * Now return the full IMR value |
---|
[be8cbbf] | 719 | */ |
---|
| 720 | |
---|
[198d851] | 721 | if (is_a) |
---|
| 722 | return (mate_mask << 4) | mask; |
---|
| 723 | |
---|
| 724 | return (mask << 4) | mate_mask; |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | /* |
---|
| 728 | * mc68681_enable_interrupts |
---|
| 729 | * |
---|
| 730 | * This function initializes the hardware for this port to use interrupts. |
---|
| 731 | */ |
---|
| 732 | |
---|
| 733 | MC68681_STATIC void mc68681_enable_interrupts( |
---|
| 734 | int minor, |
---|
| 735 | int imr_mask |
---|
| 736 | ) |
---|
| 737 | { |
---|
| 738 | unsigned32 pMC68681; |
---|
| 739 | setRegister_f setReg; |
---|
| 740 | |
---|
| 741 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
| 742 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
| 743 | |
---|
| 744 | /* |
---|
| 745 | * Enable interrupts on RX and TX -- not break |
---|
| 746 | */ |
---|
[be8cbbf] | 747 | |
---|
[198d851] | 748 | (*setReg)( |
---|
| 749 | pMC68681, |
---|
| 750 | MC68681_INTERRUPT_MASK_REG, |
---|
| 751 | mc68681_build_imr(minor, imr_mask) |
---|
| 752 | ); |
---|
[be8cbbf] | 753 | } |
---|
| 754 | |
---|