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