src/mess/machine/msm8251.c
| r12756 | r12757 | |
| 1 | | /********************************************************************* |
| 2 | | |
| 3 | | i8251.c |
| 4 | | |
| 5 | | Intel 8251 Universal Synchronous/Asynchronous Receiver Transmitter code |
| 6 | | |
| 7 | | *********************************************************************/ |
| 8 | | |
| 9 | | #include "emu.h" |
| 10 | | #include "msm8251.h" |
| 11 | | |
| 12 | | |
| 13 | | /*************************************************************************** |
| 14 | | MACROS |
| 15 | | ***************************************************************************/ |
| 16 | | |
| 17 | | #define VERBOSE 0 |
| 18 | | |
| 19 | | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 20 | | |
| 21 | | /*************************************************************************** |
| 22 | | PROTOTYPES |
| 23 | | ***************************************************************************/ |
| 24 | | |
| 25 | | static void i8251_in_callback(running_machine &machine, int id, unsigned long state); |
| 26 | | |
| 27 | | /*************************************************************************** |
| 28 | | GLOBAL VARIABLES |
| 29 | | ***************************************************************************/ |
| 30 | | |
| 31 | | const i8251_interface default_i8251_interface = { DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL }; |
| 32 | | |
| 33 | | |
| 34 | | /*************************************************************************** |
| 35 | | IMPLEMENTATION |
| 36 | | ***************************************************************************/ |
| 37 | | |
| 38 | | /*------------------------------------------------- |
| 39 | | i8251_in_callback |
| 40 | | -------------------------------------------------*/ |
| 41 | | |
| 42 | | static void i8251_in_callback(running_machine &machine, int id, unsigned long state) |
| 43 | | { |
| 44 | | int changed; |
| 45 | | |
| 46 | | /* NPW 29-Nov-2008 - These two lines are a hack and indicate why our "serial" infrastructure needs to be updated */ |
| 47 | | i8251_device *device = machine.device<i8251_device>("uart"); |
| 48 | | |
| 49 | | |
| 50 | | changed = device->get_connection()->input_state^state; |
| 51 | | |
| 52 | | device->get_connection()->input_state = state; |
| 53 | | |
| 54 | | /* did cts change state? */ |
| 55 | | if (changed & SERIAL_STATE_CTS) |
| 56 | | { |
| 57 | | /* yes */ |
| 58 | | /* update tx ready */ |
| 59 | | /* update_tx_ready(); */ |
| 60 | | } |
| 61 | | } |
| 62 | | |
| 63 | | //************************************************************************** |
| 64 | | // DEVICE DEFINITIONS |
| 65 | | //************************************************************************** |
| 66 | | |
| 67 | | const device_type I8251 = &device_creator<i8251_device>; |
| 68 | | |
| 69 | | //------------------------------------------------- |
| 70 | | // i8251_device - constructor |
| 71 | | //------------------------------------------------- |
| 72 | | |
| 73 | | i8251_device::i8251_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 74 | | : device_t(mconfig, I8251, "I8251", tag, owner, clock) |
| 75 | | { |
| 76 | | } |
| 77 | | |
| 78 | | //------------------------------------------------- |
| 79 | | // device_config_complete - perform any |
| 80 | | // operations now that the configuration is |
| 81 | | // complete |
| 82 | | //------------------------------------------------- |
| 83 | | |
| 84 | | void i8251_device::device_config_complete() |
| 85 | | { |
| 86 | | // inherit a copy of the static data |
| 87 | | const i8251_interface *intf = reinterpret_cast<const i8251_interface *>(static_config()); |
| 88 | | if (intf != NULL) |
| 89 | | *static_cast<i8251_interface *>(this) = *intf; |
| 90 | | |
| 91 | | // or initialize to defaults if none provided |
| 92 | | else |
| 93 | | { |
| 94 | | memset(&m_in_rxd_cb, 0, sizeof(m_in_rxd_cb)); |
| 95 | | memset(&m_out_txd_cb, 0, sizeof(m_out_txd_cb)); |
| 96 | | memset(&m_in_dsr_cb, 0, sizeof(m_in_dsr_cb)); |
| 97 | | memset(&m_out_dtr_cb, 0, sizeof(m_out_dtr_cb)); |
| 98 | | memset(&m_out_rts_cb, 0, sizeof(m_out_rts_cb)); |
| 99 | | memset(&m_out_rxrdy_cb, 0, sizeof(m_out_rxrdy_cb)); |
| 100 | | memset(&m_out_txrdy_cb, 0, sizeof(m_out_txrdy_cb)); |
| 101 | | memset(&m_out_txempty_cb, 0, sizeof(m_out_txempty_cb)); |
| 102 | | memset(&m_out_syndet_cb, 0, sizeof(m_out_syndet_cb)); |
| 103 | | } |
| 104 | | } |
| 105 | | |
| 106 | | //------------------------------------------------- |
| 107 | | // device_start - device-specific startup |
| 108 | | //------------------------------------------------- |
| 109 | | |
| 110 | | void i8251_device::device_start() |
| 111 | | { |
| 112 | | serial_helper_setup(); |
| 113 | | |
| 114 | | // resolve callbacks |
| 115 | | m_out_rxrdy_func.resolve(m_out_rxrdy_cb, *this); |
| 116 | | m_out_txrdy_func.resolve(m_out_txrdy_cb, *this); |
| 117 | | m_out_txempty_func.resolve(m_out_txempty_cb, *this); |
| 118 | | |
| 119 | | /* setup this side of the serial connection */ |
| 120 | | serial_connection_init(machine(),&m_connection); |
| 121 | | serial_connection_set_in_callback(machine(),&m_connection, i8251_in_callback); |
| 122 | | m_connection.input_state = 0; |
| 123 | | } |
| 124 | | |
| 125 | | |
| 126 | | |
| 127 | | |
| 128 | | /*------------------------------------------------- |
| 129 | | update_rx_ready |
| 130 | | -------------------------------------------------*/ |
| 131 | | |
| 132 | | void i8251_device::update_rx_ready() |
| 133 | | { |
| 134 | | int state; |
| 135 | | |
| 136 | | state = m_status & I8251_STATUS_RX_READY; |
| 137 | | |
| 138 | | /* masked? */ |
| 139 | | if ((m_command & (1<<2))==0) |
| 140 | | { |
| 141 | | state = 0; |
| 142 | | } |
| 143 | | |
| 144 | | m_out_rxrdy_func(state != 0); |
| 145 | | } |
| 146 | | |
| 147 | | |
| 148 | | |
| 149 | | /*------------------------------------------------- |
| 150 | | receive_clock |
| 151 | | -------------------------------------------------*/ |
| 152 | | |
| 153 | | void i8251_device::receive_clock() |
| 154 | | { |
| 155 | | /* receive enable? */ |
| 156 | | if (m_command & (1<<2)) |
| 157 | | { |
| 158 | | //logerror("I8251\n"); |
| 159 | | /* get bit received from other side and update receive register */ |
| 160 | | receive_register_update_bit(&m_receive_reg, get_in_data_bit(m_connection.input_state)); |
| 161 | | |
| 162 | | if (m_receive_reg.flags & RECEIVE_REGISTER_FULL) |
| 163 | | { |
| 164 | | receive_register_extract(&m_receive_reg, &m_form); |
| 165 | | receive_character(m_receive_reg.byte_received); |
| 166 | | } |
| 167 | | } |
| 168 | | } |
| 169 | | |
| 170 | | |
| 171 | | |
| 172 | | /*------------------------------------------------- |
| 173 | | transmit_clock |
| 174 | | -------------------------------------------------*/ |
| 175 | | |
| 176 | | void i8251_device::transmit_clock() |
| 177 | | { |
| 178 | | /* transmit enable? */ |
| 179 | | if (m_command & (1<<0)) |
| 180 | | { |
| 181 | | |
| 182 | | /* transmit register full? */ |
| 183 | | if ((m_status & I8251_STATUS_TX_READY)==0) |
| 184 | | { |
| 185 | | /* if transmit reg is empty */ |
| 186 | | if ((m_transmit_reg.flags & TRANSMIT_REGISTER_EMPTY)!=0) |
| 187 | | { |
| 188 | | /* set it up */ |
| 189 | | transmit_register_setup(&m_transmit_reg, &m_form, m_data); |
| 190 | | /* i8251 transmit reg now empty */ |
| 191 | | m_status |=I8251_STATUS_TX_EMPTY; |
| 192 | | /* ready for next transmit */ |
| 193 | | m_status |=I8251_STATUS_TX_READY; |
| 194 | | |
| 195 | | update_tx_empty(); |
| 196 | | update_tx_ready(); |
| 197 | | } |
| 198 | | } |
| 199 | | |
| 200 | | /* if transmit is not empty... transmit data */ |
| 201 | | if ((m_transmit_reg.flags & TRANSMIT_REGISTER_EMPTY)==0) |
| 202 | | { |
| 203 | | // logerror("I8251\n"); |
| 204 | | transmit_register_send_bit(machine(),&m_transmit_reg, &m_connection); |
| 205 | | } |
| 206 | | } |
| 207 | | |
| 208 | | #if 0 |
| 209 | | /* hunt mode? */ |
| 210 | | /* after each bit has been shifted in, it is compared against the current sync byte */ |
| 211 | | if (m_command & (1<<7)) |
| 212 | | { |
| 213 | | /* data matches sync byte? */ |
| 214 | | if (m_data == m_sync_bytes[m_sync_byte_offset]) |
| 215 | | { |
| 216 | | /* sync byte matches */ |
| 217 | | /* update for next sync byte? */ |
| 218 | | m_sync_byte_offset++; |
| 219 | | |
| 220 | | /* do all sync bytes match? */ |
| 221 | | if (m_sync_byte_offset == m_sync_byte_count) |
| 222 | | { |
| 223 | | /* ent hunt mode */ |
| 224 | | m_command &=~(1<<7); |
| 225 | | } |
| 226 | | } |
| 227 | | else |
| 228 | | { |
| 229 | | /* if there is no match, reset */ |
| 230 | | m_sync_byte_offset = 0; |
| 231 | | } |
| 232 | | } |
| 233 | | #endif |
| 234 | | } |
| 235 | | |
| 236 | | |
| 237 | | |
| 238 | | /*------------------------------------------------- |
| 239 | | update_tx_ready |
| 240 | | -------------------------------------------------*/ |
| 241 | | |
| 242 | | void i8251_device::update_tx_ready() |
| 243 | | { |
| 244 | | /* clear tx ready state */ |
| 245 | | int tx_ready; |
| 246 | | |
| 247 | | /* tx ready output is set if: |
| 248 | | DB Buffer Empty & |
| 249 | | CTS is set & |
| 250 | | Transmit enable is 1 |
| 251 | | */ |
| 252 | | |
| 253 | | tx_ready = 0; |
| 254 | | |
| 255 | | /* transmit enable? */ |
| 256 | | if ((m_command & (1<<0))!=0) |
| 257 | | { |
| 258 | | /* other side has rts set (comes in as CTS at this side) */ |
| 259 | | if (m_connection.input_state & SERIAL_STATE_CTS) |
| 260 | | { |
| 261 | | if (m_status & I8251_STATUS_TX_EMPTY) |
| 262 | | { |
| 263 | | /* enable transfer */ |
| 264 | | tx_ready = 1; |
| 265 | | } |
| 266 | | } |
| 267 | | } |
| 268 | | |
| 269 | | m_out_txrdy_func(tx_ready); |
| 270 | | } |
| 271 | | |
| 272 | | |
| 273 | | |
| 274 | | /*------------------------------------------------- |
| 275 | | update_tx_empty |
| 276 | | -------------------------------------------------*/ |
| 277 | | |
| 278 | | void i8251_device::update_tx_empty() |
| 279 | | { |
| 280 | | if (m_status & I8251_STATUS_TX_EMPTY) |
| 281 | | { |
| 282 | | /* tx is in marking state (high) when tx empty! */ |
| 283 | | set_out_data_bit(m_connection.State, 1); |
| 284 | | serial_connection_out(machine(),&m_connection); |
| 285 | | } |
| 286 | | |
| 287 | | m_out_txempty_func((m_status & I8251_STATUS_TX_EMPTY) != 0); |
| 288 | | } |
| 289 | | |
| 290 | | |
| 291 | | |
| 292 | | //------------------------------------------------- |
| 293 | | // device_reset - device-specific reset |
| 294 | | //------------------------------------------------- |
| 295 | | |
| 296 | | void i8251_device::device_reset() |
| 297 | | { |
| 298 | | LOG(("I8251: Reset\n")); |
| 299 | | |
| 300 | | /* what is the default setup when the 8251 has been reset??? */ |
| 301 | | |
| 302 | | /* i8251 datasheet explains the state of tx pin at reset */ |
| 303 | | /* tx is set to 1 */ |
| 304 | | set_out_data_bit(m_connection.State,1); |
| 305 | | |
| 306 | | /* assumption, rts is set to 1 */ |
| 307 | | m_connection.State &= ~SERIAL_STATE_RTS; |
| 308 | | serial_connection_out(machine(), &m_connection); |
| 309 | | |
| 310 | | transmit_register_reset(&m_transmit_reg); |
| 311 | | receive_register_reset(&m_receive_reg); |
| 312 | | /* expecting mode byte */ |
| 313 | | m_flags |= I8251_EXPECTING_MODE; |
| 314 | | /* not expecting a sync byte */ |
| 315 | | m_flags &= ~I8251_EXPECTING_SYNC_BYTE; |
| 316 | | |
| 317 | | /* no character to read by cpu */ |
| 318 | | /* transmitter is ready and is empty */ |
| 319 | | m_status = I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY; |
| 320 | | m_mode_byte = 0; |
| 321 | | m_command = 0; |
| 322 | | |
| 323 | | /* update tx empty pin output */ |
| 324 | | update_tx_empty(); |
| 325 | | /* update rx ready pin output */ |
| 326 | | update_rx_ready(); |
| 327 | | /* update tx ready pin output */ |
| 328 | | update_tx_ready(); |
| 329 | | } |
| 330 | | |
| 331 | | |
| 332 | | |
| 333 | | /*------------------------------------------------- |
| 334 | | control_w |
| 335 | | -------------------------------------------------*/ |
| 336 | | |
| 337 | | WRITE8_MEMBER(i8251_device::control_w) |
| 338 | | { |
| 339 | | if (m_flags & I8251_EXPECTING_MODE) |
| 340 | | { |
| 341 | | if (m_flags & I8251_EXPECTING_SYNC_BYTE) |
| 342 | | { |
| 343 | | LOG(("I8251: Sync byte\n")); |
| 344 | | |
| 345 | | LOG(("Sync byte: %02x\n", data)); |
| 346 | | /* store sync byte written */ |
| 347 | | m_sync_bytes[m_sync_byte_offset] = data; |
| 348 | | m_sync_byte_offset++; |
| 349 | | |
| 350 | | if (m_sync_byte_offset == m_sync_byte_count) |
| 351 | | { |
| 352 | | /* finished transfering sync bytes, now expecting command */ |
| 353 | | m_flags &= ~(I8251_EXPECTING_MODE | I8251_EXPECTING_SYNC_BYTE); |
| 354 | | m_sync_byte_offset = 0; |
| 355 | | // m_status = I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY; |
| 356 | | } |
| 357 | | } |
| 358 | | else |
| 359 | | { |
| 360 | | LOG(("I8251: Mode byte\n")); |
| 361 | | |
| 362 | | m_mode_byte = data; |
| 363 | | |
| 364 | | /* Synchronous or Asynchronous? */ |
| 365 | | if ((data & 0x03)!=0) |
| 366 | | { |
| 367 | | /* Asynchronous |
| 368 | | |
| 369 | | bit 7,6: stop bit length |
| 370 | | 0 = inhibit |
| 371 | | 1 = 1 bit |
| 372 | | 2 = 1.5 bits |
| 373 | | 3 = 2 bits |
| 374 | | bit 5: parity type |
| 375 | | 0 = parity odd |
| 376 | | 1 = parity even |
| 377 | | bit 4: parity test enable |
| 378 | | 0 = disable |
| 379 | | 1 = enable |
| 380 | | bit 3,2: character length |
| 381 | | 0 = 5 bits |
| 382 | | 1 = 6 bits |
| 383 | | 2 = 7 bits |
| 384 | | 3 = 8 bits |
| 385 | | bit 1,0: baud rate factor |
| 386 | | 0 = defines command byte for synchronous or asynchronous |
| 387 | | 1 = x1 |
| 388 | | 2 = x16 |
| 389 | | 3 = x64 |
| 390 | | */ |
| 391 | | |
| 392 | | LOG(("I8251: Asynchronous operation\n")); |
| 393 | | |
| 394 | | LOG(("Character length: %d\n", (((data>>2) & 0x03)+5))); |
| 395 | | |
| 396 | | if (data & (1<<4)) |
| 397 | | { |
| 398 | | LOG(("enable parity checking\n")); |
| 399 | | } |
| 400 | | else |
| 401 | | { |
| 402 | | LOG(("parity check disabled\n")); |
| 403 | | } |
| 404 | | |
| 405 | | if (data & (1<<5)) |
| 406 | | { |
| 407 | | LOG(("even parity\n")); |
| 408 | | } |
| 409 | | else |
| 410 | | { |
| 411 | | LOG(("odd parity\n")); |
| 412 | | } |
| 413 | | |
| 414 | | { |
| 415 | | UINT8 stop_bit_length; |
| 416 | | |
| 417 | | stop_bit_length = (data>>6) & 0x03; |
| 418 | | |
| 419 | | switch (stop_bit_length) |
| 420 | | { |
| 421 | | case 0: |
| 422 | | { |
| 423 | | /* inhibit */ |
| 424 | | LOG(("stop bit: inhibit\n")); |
| 425 | | } |
| 426 | | break; |
| 427 | | |
| 428 | | case 1: |
| 429 | | { |
| 430 | | /* 1 */ |
| 431 | | LOG(("stop bit: 1 bit\n")); |
| 432 | | } |
| 433 | | break; |
| 434 | | |
| 435 | | case 2: |
| 436 | | { |
| 437 | | /* 1.5 */ |
| 438 | | LOG(("stop bit: 1.5 bits\n")); |
| 439 | | } |
| 440 | | break; |
| 441 | | |
| 442 | | case 3: |
| 443 | | { |
| 444 | | /* 2 */ |
| 445 | | LOG(("stop bit: 2 bits\n")); |
| 446 | | } |
| 447 | | break; |
| 448 | | } |
| 449 | | } |
| 450 | | |
| 451 | | m_form.word_length = ((data>>2) & 0x03)+5; |
| 452 | | m_form.parity = SERIAL_PARITY_NONE; |
| 453 | | switch ((data>>6) & 0x03) |
| 454 | | { |
| 455 | | case 0: |
| 456 | | case 1: |
| 457 | | m_form.stop_bit_count = 1; |
| 458 | | break; |
| 459 | | case 2: |
| 460 | | case 3: |
| 461 | | m_form.stop_bit_count = 2; |
| 462 | | break; |
| 463 | | } |
| 464 | | receive_register_setup(&m_receive_reg, &m_form); |
| 465 | | |
| 466 | | |
| 467 | | #if 0 |
| 468 | | /* data bits */ |
| 469 | | m_receive_char_length = (((data>>2) & 0x03)+5); |
| 470 | | |
| 471 | | if (data & (1<<4)) |
| 472 | | { |
| 473 | | /* parity */ |
| 474 | | m_receive_char_length++; |
| 475 | | } |
| 476 | | |
| 477 | | /* stop bits */ |
| 478 | | m_receive_char_length++; |
| 479 | | |
| 480 | | m_receive_flags &=~I8251_TRANSFER_RECEIVE_SYNCHRONISED; |
| 481 | | m_receive_flags |= I8251_TRANSFER_RECEIVE_WAITING_FOR_START_BIT; |
| 482 | | #endif |
| 483 | | /* not expecting mode byte now */ |
| 484 | | m_flags &= ~I8251_EXPECTING_MODE; |
| 485 | | // m_status = I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY; |
| 486 | | } |
| 487 | | else |
| 488 | | { |
| 489 | | /* bit 7: Number of sync characters |
| 490 | | 0 = 1 character |
| 491 | | 1 = 2 character |
| 492 | | bit 6: Synchronous mode |
| 493 | | 0 = Internal synchronisation |
| 494 | | 1 = External synchronisation |
| 495 | | bit 5: parity type |
| 496 | | 0 = parity odd |
| 497 | | 1 = parity even |
| 498 | | bit 4: parity test enable |
| 499 | | 0 = disable |
| 500 | | 1 = enable |
| 501 | | bit 3,2: character length |
| 502 | | 0 = 5 bits |
| 503 | | 1 = 6 bits |
| 504 | | 2 = 7 bits |
| 505 | | 3 = 8 bits |
| 506 | | bit 1,0 = 0 |
| 507 | | */ |
| 508 | | LOG(("I8251: Synchronous operation\n")); |
| 509 | | |
| 510 | | /* setup for sync byte(s) */ |
| 511 | | m_flags |= I8251_EXPECTING_SYNC_BYTE; |
| 512 | | m_sync_byte_offset = 0; |
| 513 | | if (data & 0x07) |
| 514 | | { |
| 515 | | m_sync_byte_count = 1; |
| 516 | | } |
| 517 | | else |
| 518 | | { |
| 519 | | m_sync_byte_count = 2; |
| 520 | | } |
| 521 | | |
| 522 | | } |
| 523 | | } |
| 524 | | } |
| 525 | | else |
| 526 | | { |
| 527 | | /* command */ |
| 528 | | LOG(("I8251: Command byte\n")); |
| 529 | | |
| 530 | | m_command = data; |
| 531 | | |
| 532 | | LOG(("Command byte: %02x\n", data)); |
| 533 | | |
| 534 | | if (data & (1<<7)) |
| 535 | | { |
| 536 | | LOG(("hunt mode\n")); |
| 537 | | } |
| 538 | | |
| 539 | | if (data & (1<<5)) |
| 540 | | { |
| 541 | | LOG(("/rts set to 0\n")); |
| 542 | | } |
| 543 | | else |
| 544 | | { |
| 545 | | LOG(("/rts set to 1\n")); |
| 546 | | } |
| 547 | | |
| 548 | | if (data & (1<<2)) |
| 549 | | { |
| 550 | | LOG(("receive enable\n")); |
| 551 | | } |
| 552 | | else |
| 553 | | { |
| 554 | | LOG(("receive disable\n")); |
| 555 | | } |
| 556 | | |
| 557 | | if (data & (1<<1)) |
| 558 | | { |
| 559 | | LOG(("/dtr set to 0\n")); |
| 560 | | } |
| 561 | | else |
| 562 | | { |
| 563 | | LOG(("/dtr set to 1\n")); |
| 564 | | } |
| 565 | | |
| 566 | | if (data & (1<<0)) |
| 567 | | { |
| 568 | | LOG(("transmit enable\n")); |
| 569 | | } |
| 570 | | else |
| 571 | | { |
| 572 | | LOG(("transmit disable\n")); |
| 573 | | } |
| 574 | | |
| 575 | | |
| 576 | | /* bit 7: |
| 577 | | 0 = normal operation |
| 578 | | 1 = hunt mode |
| 579 | | bit 6: |
| 580 | | 0 = normal operation |
| 581 | | 1 = internal reset |
| 582 | | bit 5: |
| 583 | | 0 = /RTS set to 1 |
| 584 | | 1 = /RTS set to 0 |
| 585 | | bit 4: |
| 586 | | 0 = normal operation |
| 587 | | 1 = reset error flag |
| 588 | | bit 3: |
| 589 | | 0 = normal operation |
| 590 | | 1 = send break character |
| 591 | | bit 2: |
| 592 | | 0 = receive disable |
| 593 | | 1 = receive enable |
| 594 | | bit 1: |
| 595 | | 0 = /DTR set to 1 |
| 596 | | 1 = /DTR set to 0 |
| 597 | | bit 0: |
| 598 | | 0 = transmit disable |
| 599 | | 1 = transmit enable |
| 600 | | */ |
| 601 | | |
| 602 | | m_connection.State &=~SERIAL_STATE_RTS; |
| 603 | | if (data & (1<<5)) |
| 604 | | { |
| 605 | | /* rts set to 0 */ |
| 606 | | m_connection.State |= SERIAL_STATE_RTS; |
| 607 | | } |
| 608 | | |
| 609 | | m_connection.State &=~SERIAL_STATE_DTR; |
| 610 | | if (data & (1<<1)) |
| 611 | | { |
| 612 | | m_connection.State |= SERIAL_STATE_DTR; |
| 613 | | } |
| 614 | | |
| 615 | | if ((data & (1<<0))==0) |
| 616 | | { |
| 617 | | /* held in high state when transmit disable */ |
| 618 | | set_out_data_bit(m_connection.State,1); |
| 619 | | } |
| 620 | | |
| 621 | | |
| 622 | | /* refresh outputs */ |
| 623 | | serial_connection_out(machine(), &m_connection); |
| 624 | | |
| 625 | | if (data & (1<<4)) |
| 626 | | { |
| 627 | | m_status &= ~(I8251_STATUS_PARITY_ERROR | I8251_STATUS_OVERRUN_ERROR | I8251_STATUS_FRAMING_ERROR); |
| 628 | | } |
| 629 | | |
| 630 | | if (data & (1<<6)) |
| 631 | | { |
| 632 | | reset(); |
| 633 | | } |
| 634 | | |
| 635 | | update_rx_ready(); |
| 636 | | update_tx_ready(); |
| 637 | | |
| 638 | | } |
| 639 | | } |
| 640 | | |
| 641 | | |
| 642 | | |
| 643 | | /*------------------------------------------------- |
| 644 | | status_r |
| 645 | | -------------------------------------------------*/ |
| 646 | | |
| 647 | | READ8_MEMBER(i8251_device::status_r) |
| 648 | | { |
| 649 | | LOG(("status: %02x\n", m_status)); |
| 650 | | return m_status; |
| 651 | | } |
| 652 | | |
| 653 | | |
| 654 | | |
| 655 | | /*------------------------------------------------- |
| 656 | | data_w |
| 657 | | -------------------------------------------------*/ |
| 658 | | |
| 659 | | WRITE8_MEMBER(i8251_device::data_w) |
| 660 | | { |
| 661 | | m_data = data; |
| 662 | | |
| 663 | | logerror("write data: %02x\n",data); |
| 664 | | |
| 665 | | /* writing clears */ |
| 666 | | m_status &=~I8251_STATUS_TX_READY; |
| 667 | | |
| 668 | | /* if transmitter is active, then tx empty will be signalled */ |
| 669 | | |
| 670 | | update_tx_ready(); |
| 671 | | } |
| 672 | | |
| 673 | | |
| 674 | | |
| 675 | | /*------------------------------------------------- |
| 676 | | receive_character - called when last |
| 677 | | bit of data has been received |
| 678 | | -------------------------------------------------*/ |
| 679 | | |
| 680 | | void i8251_device::receive_character(UINT8 ch) |
| 681 | | { |
| 682 | | logerror("i8251 receive char: %02x\n",ch); |
| 683 | | |
| 684 | | m_data = ch; |
| 685 | | |
| 686 | | /* char has not been read and another has arrived! */ |
| 687 | | if (m_status & I8251_STATUS_RX_READY) |
| 688 | | { |
| 689 | | m_status |= I8251_STATUS_OVERRUN_ERROR; |
| 690 | | } |
| 691 | | m_status |= I8251_STATUS_RX_READY; |
| 692 | | |
| 693 | | update_rx_ready(); |
| 694 | | } |
| 695 | | |
| 696 | | |
| 697 | | |
| 698 | | /*------------------------------------------------- |
| 699 | | data_r - read data |
| 700 | | -------------------------------------------------*/ |
| 701 | | |
| 702 | | READ8_MEMBER(i8251_device::data_r) |
| 703 | | { |
| 704 | | logerror("read data: %02x, STATUS=%02x\n",m_data,m_status); |
| 705 | | /* reading clears */ |
| 706 | | m_status &= ~I8251_STATUS_RX_READY; |
| 707 | | |
| 708 | | update_rx_ready(); |
| 709 | | return m_data; |
| 710 | | } |
| 711 | | |
| 712 | | |
| 713 | | |
| 714 | | /*------------------------------------------------- |
| 715 | | connect_to_serial_device - initialise |
| 716 | | transfer using serial device - set the callback |
| 717 | | which will be called when serial device has |
| 718 | | updated it's state |
| 719 | | -------------------------------------------------*/ |
| 720 | | |
| 721 | | void i8251_device::connect_to_serial_device(device_t *image) |
| 722 | | { |
| 723 | | serial_device_connect(image, &m_connection); |
| 724 | | } |
| 725 | | |
| 726 | | |
| 727 | | |
| 728 | | /*------------------------------------------------- |
| 729 | | connect |
| 730 | | -------------------------------------------------*/ |
| 731 | | |
| 732 | | void i8251_device::connect(serial_connection *other_connection) |
| 733 | | { |
| 734 | | serial_connection_link(machine(), &m_connection, other_connection); |
| 735 | | } |
src/mess/machine/msm8251.h
| r12756 | r12757 | |
| 1 | | /********************************************************************* |
| 2 | | |
| 3 | | i8251.h |
| 4 | | |
| 5 | | Intel 8251 Universal Synchronous/Asynchronous Receiver Transmitter code |
| 6 | | |
| 7 | | *********************************************************************/ |
| 8 | | |
| 9 | | #ifndef __I8251_H__ |
| 10 | | #define __I8251_H__ |
| 11 | | |
| 12 | | #include "machine/serial.h" |
| 13 | | |
| 14 | | |
| 15 | | /*************************************************************************** |
| 16 | | CONSTANTS |
| 17 | | ***************************************************************************/ |
| 18 | | |
| 19 | | #define I8251_EXPECTING_MODE 0x01 |
| 20 | | #define I8251_EXPECTING_SYNC_BYTE 0x02 |
| 21 | | |
| 22 | | #define I8251_STATUS_FRAMING_ERROR 0x020 |
| 23 | | #define I8251_STATUS_OVERRUN_ERROR 0x010 |
| 24 | | #define I8251_STATUS_PARITY_ERROR 0x08 |
| 25 | | #define I8251_STATUS_TX_EMPTY 0x04 |
| 26 | | #define I8251_STATUS_RX_READY 0x02 |
| 27 | | #define I8251_STATUS_TX_READY 0x01 |
| 28 | | |
| 29 | | //************************************************************************** |
| 30 | | // INTERFACE CONFIGURATION MACROS |
| 31 | | //************************************************************************** |
| 32 | | |
| 33 | | #define MCFG_I8251_ADD(_tag, _intrf) \ |
| 34 | | MCFG_DEVICE_ADD(_tag, I8251, 0) \ |
| 35 | | MCFG_DEVICE_CONFIG(_intrf) |
| 36 | | |
| 37 | | #define MCFG_I8251_REMOVE(_tag) \ |
| 38 | | MCFG_DEVICE_REMOVE(_tag) |
| 39 | | |
| 40 | | |
| 41 | | /*************************************************************************** |
| 42 | | TYPE DEFINITIONS |
| 43 | | ***************************************************************************/ |
| 44 | | // ======================> i8251_interface |
| 45 | | |
| 46 | | struct i8251_interface |
| 47 | | { |
| 48 | | devcb_read_line m_in_rxd_cb; |
| 49 | | devcb_write_line m_out_txd_cb; |
| 50 | | devcb_read_line m_in_dsr_cb; |
| 51 | | devcb_write_line m_out_dtr_cb; |
| 52 | | devcb_write_line m_out_rts_cb; |
| 53 | | devcb_write_line m_out_rxrdy_cb; |
| 54 | | devcb_write_line m_out_txrdy_cb; |
| 55 | | devcb_write_line m_out_txempty_cb; |
| 56 | | devcb_write_line m_out_syndet_cb; |
| 57 | | }; |
| 58 | | |
| 59 | | // ======================> i8251_device |
| 60 | | |
| 61 | | class i8251_device : public device_t, |
| 62 | | public i8251_interface |
| 63 | | { |
| 64 | | public: |
| 65 | | // construction/destruction |
| 66 | | i8251_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 67 | | |
| 68 | | /* read data register */ |
| 69 | | DECLARE_READ8_MEMBER(data_r); |
| 70 | | |
| 71 | | /* read status register */ |
| 72 | | DECLARE_READ8_MEMBER(status_r); |
| 73 | | |
| 74 | | /* write data register */ |
| 75 | | DECLARE_WRITE8_MEMBER(data_w); |
| 76 | | |
| 77 | | /* write control word */ |
| 78 | | DECLARE_WRITE8_MEMBER(control_w); |
| 79 | | |
| 80 | | /* The 8251 has seperate transmit and receive clocks */ |
| 81 | | /* use these two functions to update the i8251 for each clock */ |
| 82 | | /* on NC100 system, the clocks are the same */ |
| 83 | | void transmit_clock(); |
| 84 | | void receive_clock(); |
| 85 | | |
| 86 | | /* connecting to serial output */ |
| 87 | | void connect_to_serial_device(device_t *image); |
| 88 | | void connect(serial_connection *other_connection); |
| 89 | | |
| 90 | | void receive_character(UINT8 ch); |
| 91 | | |
| 92 | | serial_connection *get_connection() { return &m_connection; } |
| 93 | | protected: |
| 94 | | // device-level overrides |
| 95 | | virtual void device_start(); |
| 96 | | virtual void device_config_complete(); |
| 97 | | virtual void device_reset(); |
| 98 | | |
| 99 | | void update_rx_ready(); |
| 100 | | void update_tx_ready(); |
| 101 | | void update_tx_empty(); |
| 102 | | private: |
| 103 | | devcb_resolved_read_line m_in_rxd_func; |
| 104 | | devcb_resolved_write_line m_out_txd_func; |
| 105 | | devcb_resolved_read_line m_in_dsr_func; |
| 106 | | devcb_resolved_write_line m_out_dtr_func; |
| 107 | | devcb_resolved_write_line m_out_rts_func; |
| 108 | | devcb_resolved_write_line m_out_rxrdy_func; |
| 109 | | devcb_resolved_write_line m_out_txrdy_func; |
| 110 | | devcb_resolved_write_line m_out_txempty_func; |
| 111 | | devcb_resolved_write_line m_out_syndet_func; |
| 112 | | |
| 113 | | /* flags controlling how i8251_control_w operates */ |
| 114 | | UINT8 m_flags; |
| 115 | | /* offset into sync_bytes used during sync byte transfer */ |
| 116 | | UINT8 m_sync_byte_offset; |
| 117 | | /* number of sync bytes written so far */ |
| 118 | | UINT8 m_sync_byte_count; |
| 119 | | /* the sync bytes written */ |
| 120 | | UINT8 m_sync_bytes[2]; |
| 121 | | /* status of i8251 */ |
| 122 | | UINT8 m_status; |
| 123 | | UINT8 m_command; |
| 124 | | /* mode byte - bit definitions depend on mode - e.g. synchronous, asynchronous */ |
| 125 | | UINT8 m_mode_byte; |
| 126 | | |
| 127 | | /* data being received */ |
| 128 | | UINT8 m_data; |
| 129 | | |
| 130 | | /* receive reg */ |
| 131 | | serial_receive_register m_receive_reg; |
| 132 | | /* transmit reg */ |
| 133 | | serial_transmit_register m_transmit_reg; |
| 134 | | |
| 135 | | data_form m_form; |
| 136 | | |
| 137 | | /* the serial connection that data is transfered over */ |
| 138 | | /* this is usually connected to the serial device */ |
| 139 | | serial_connection m_connection; |
| 140 | | }; |
| 141 | | |
| 142 | | |
| 143 | | |
| 144 | | // device type definition |
| 145 | | extern const device_type I8251; |
| 146 | | |
| 147 | | /*************************************************************************** |
| 148 | | PROTOTYPES |
| 149 | | ***************************************************************************/ |
| 150 | | |
| 151 | | extern const i8251_interface default_i8251_interface; |
| 152 | | |
| 153 | | #endif /* __I8251_H__ */ |
src/mess/machine/i8251.c
| r0 | r12757 | |
| 1 | /********************************************************************* |
| 2 | |
| 3 | i8251.c |
| 4 | |
| 5 | Intel 8251 Universal Synchronous/Asynchronous Receiver Transmitter code |
| 6 | |
| 7 | *********************************************************************/ |
| 8 | |
| 9 | #include "emu.h" |
| 10 | #include "i8251.h" |
| 11 | |
| 12 | |
| 13 | /*************************************************************************** |
| 14 | MACROS |
| 15 | ***************************************************************************/ |
| 16 | |
| 17 | #define VERBOSE 0 |
| 18 | |
| 19 | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 20 | |
| 21 | /*************************************************************************** |
| 22 | PROTOTYPES |
| 23 | ***************************************************************************/ |
| 24 | |
| 25 | static void i8251_in_callback(running_machine &machine, int id, unsigned long state); |
| 26 | |
| 27 | /*************************************************************************** |
| 28 | GLOBAL VARIABLES |
| 29 | ***************************************************************************/ |
| 30 | |
| 31 | const i8251_interface default_i8251_interface = { DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL }; |
| 32 | |
| 33 | |
| 34 | /*************************************************************************** |
| 35 | IMPLEMENTATION |
| 36 | ***************************************************************************/ |
| 37 | |
| 38 | /*------------------------------------------------- |
| 39 | i8251_in_callback |
| 40 | -------------------------------------------------*/ |
| 41 | |
| 42 | static void i8251_in_callback(running_machine &machine, int id, unsigned long state) |
| 43 | { |
| 44 | int changed; |
| 45 | |
| 46 | /* NPW 29-Nov-2008 - These two lines are a hack and indicate why our "serial" infrastructure needs to be updated */ |
| 47 | i8251_device *device = machine.device<i8251_device>("uart"); |
| 48 | |
| 49 | |
| 50 | changed = device->get_connection()->input_state^state; |
| 51 | |
| 52 | device->get_connection()->input_state = state; |
| 53 | |
| 54 | /* did cts change state? */ |
| 55 | if (changed & SERIAL_STATE_CTS) |
| 56 | { |
| 57 | /* yes */ |
| 58 | /* update tx ready */ |
| 59 | /* update_tx_ready(); */ |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | //************************************************************************** |
| 64 | // DEVICE DEFINITIONS |
| 65 | //************************************************************************** |
| 66 | |
| 67 | const device_type I8251 = &device_creator<i8251_device>; |
| 68 | |
| 69 | //------------------------------------------------- |
| 70 | // i8251_device - constructor |
| 71 | //------------------------------------------------- |
| 72 | |
| 73 | i8251_device::i8251_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 74 | : device_t(mconfig, I8251, "I8251", tag, owner, clock) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | //------------------------------------------------- |
| 79 | // device_config_complete - perform any |
| 80 | // operations now that the configuration is |
| 81 | // complete |
| 82 | //------------------------------------------------- |
| 83 | |
| 84 | void i8251_device::device_config_complete() |
| 85 | { |
| 86 | // inherit a copy of the static data |
| 87 | const i8251_interface *intf = reinterpret_cast<const i8251_interface *>(static_config()); |
| 88 | if (intf != NULL) |
| 89 | *static_cast<i8251_interface *>(this) = *intf; |
| 90 | |
| 91 | // or initialize to defaults if none provided |
| 92 | else |
| 93 | { |
| 94 | memset(&m_in_rxd_cb, 0, sizeof(m_in_rxd_cb)); |
| 95 | memset(&m_out_txd_cb, 0, sizeof(m_out_txd_cb)); |
| 96 | memset(&m_in_dsr_cb, 0, sizeof(m_in_dsr_cb)); |
| 97 | memset(&m_out_dtr_cb, 0, sizeof(m_out_dtr_cb)); |
| 98 | memset(&m_out_rts_cb, 0, sizeof(m_out_rts_cb)); |
| 99 | memset(&m_out_rxrdy_cb, 0, sizeof(m_out_rxrdy_cb)); |
| 100 | memset(&m_out_txrdy_cb, 0, sizeof(m_out_txrdy_cb)); |
| 101 | memset(&m_out_txempty_cb, 0, sizeof(m_out_txempty_cb)); |
| 102 | memset(&m_out_syndet_cb, 0, sizeof(m_out_syndet_cb)); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | //------------------------------------------------- |
| 107 | // device_start - device-specific startup |
| 108 | //------------------------------------------------- |
| 109 | |
| 110 | void i8251_device::device_start() |
| 111 | { |
| 112 | serial_helper_setup(); |
| 113 | |
| 114 | // resolve callbacks |
| 115 | m_out_rxrdy_func.resolve(m_out_rxrdy_cb, *this); |
| 116 | m_out_txrdy_func.resolve(m_out_txrdy_cb, *this); |
| 117 | m_out_txempty_func.resolve(m_out_txempty_cb, *this); |
| 118 | |
| 119 | /* setup this side of the serial connection */ |
| 120 | serial_connection_init(machine(),&m_connection); |
| 121 | serial_connection_set_in_callback(machine(),&m_connection, i8251_in_callback); |
| 122 | m_connection.input_state = 0; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | /*------------------------------------------------- |
| 129 | update_rx_ready |
| 130 | -------------------------------------------------*/ |
| 131 | |
| 132 | void i8251_device::update_rx_ready() |
| 133 | { |
| 134 | int state; |
| 135 | |
| 136 | state = m_status & I8251_STATUS_RX_READY; |
| 137 | |
| 138 | /* masked? */ |
| 139 | if ((m_command & (1<<2))==0) |
| 140 | { |
| 141 | state = 0; |
| 142 | } |
| 143 | |
| 144 | m_out_rxrdy_func(state != 0); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | |
| 149 | /*------------------------------------------------- |
| 150 | receive_clock |
| 151 | -------------------------------------------------*/ |
| 152 | |
| 153 | void i8251_device::receive_clock() |
| 154 | { |
| 155 | /* receive enable? */ |
| 156 | if (m_command & (1<<2)) |
| 157 | { |
| 158 | //logerror("I8251\n"); |
| 159 | /* get bit received from other side and update receive register */ |
| 160 | receive_register_update_bit(&m_receive_reg, get_in_data_bit(m_connection.input_state)); |
| 161 | |
| 162 | if (m_receive_reg.flags & RECEIVE_REGISTER_FULL) |
| 163 | { |
| 164 | receive_register_extract(&m_receive_reg, &m_form); |
| 165 | receive_character(m_receive_reg.byte_received); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | |
| 171 | |
| 172 | /*------------------------------------------------- |
| 173 | transmit_clock |
| 174 | -------------------------------------------------*/ |
| 175 | |
| 176 | void i8251_device::transmit_clock() |
| 177 | { |
| 178 | /* transmit enable? */ |
| 179 | if (m_command & (1<<0)) |
| 180 | { |
| 181 | |
| 182 | /* transmit register full? */ |
| 183 | if ((m_status & I8251_STATUS_TX_READY)==0) |
| 184 | { |
| 185 | /* if transmit reg is empty */ |
| 186 | if ((m_transmit_reg.flags & TRANSMIT_REGISTER_EMPTY)!=0) |
| 187 | { |
| 188 | /* set it up */ |
| 189 | transmit_register_setup(&m_transmit_reg, &m_form, m_data); |
| 190 | /* i8251 transmit reg now empty */ |
| 191 | m_status |=I8251_STATUS_TX_EMPTY; |
| 192 | /* ready for next transmit */ |
| 193 | m_status |=I8251_STATUS_TX_READY; |
| 194 | |
| 195 | update_tx_empty(); |
| 196 | update_tx_ready(); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | /* if transmit is not empty... transmit data */ |
| 201 | if ((m_transmit_reg.flags & TRANSMIT_REGISTER_EMPTY)==0) |
| 202 | { |
| 203 | // logerror("I8251\n"); |
| 204 | transmit_register_send_bit(machine(),&m_transmit_reg, &m_connection); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | #if 0 |
| 209 | /* hunt mode? */ |
| 210 | /* after each bit has been shifted in, it is compared against the current sync byte */ |
| 211 | if (m_command & (1<<7)) |
| 212 | { |
| 213 | /* data matches sync byte? */ |
| 214 | if (m_data == m_sync_bytes[m_sync_byte_offset]) |
| 215 | { |
| 216 | /* sync byte matches */ |
| 217 | /* update for next sync byte? */ |
| 218 | m_sync_byte_offset++; |
| 219 | |
| 220 | /* do all sync bytes match? */ |
| 221 | if (m_sync_byte_offset == m_sync_byte_count) |
| 222 | { |
| 223 | /* ent hunt mode */ |
| 224 | m_command &=~(1<<7); |
| 225 | } |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | /* if there is no match, reset */ |
| 230 | m_sync_byte_offset = 0; |
| 231 | } |
| 232 | } |
| 233 | #endif |
| 234 | } |
| 235 | |
| 236 | |
| 237 | |
| 238 | /*------------------------------------------------- |
| 239 | update_tx_ready |
| 240 | -------------------------------------------------*/ |
| 241 | |
| 242 | void i8251_device::update_tx_ready() |
| 243 | { |
| 244 | /* clear tx ready state */ |
| 245 | int tx_ready; |
| 246 | |
| 247 | /* tx ready output is set if: |
| 248 | DB Buffer Empty & |
| 249 | CTS is set & |
| 250 | Transmit enable is 1 |
| 251 | */ |
| 252 | |
| 253 | tx_ready = 0; |
| 254 | |
| 255 | /* transmit enable? */ |
| 256 | if ((m_command & (1<<0))!=0) |
| 257 | { |
| 258 | /* other side has rts set (comes in as CTS at this side) */ |
| 259 | if (m_connection.input_state & SERIAL_STATE_CTS) |
| 260 | { |
| 261 | if (m_status & I8251_STATUS_TX_EMPTY) |
| 262 | { |
| 263 | /* enable transfer */ |
| 264 | tx_ready = 1; |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | m_out_txrdy_func(tx_ready); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | |
| 274 | /*------------------------------------------------- |
| 275 | update_tx_empty |
| 276 | -------------------------------------------------*/ |
| 277 | |
| 278 | void i8251_device::update_tx_empty() |
| 279 | { |
| 280 | if (m_status & I8251_STATUS_TX_EMPTY) |
| 281 | { |
| 282 | /* tx is in marking state (high) when tx empty! */ |
| 283 | set_out_data_bit(m_connection.State, 1); |
| 284 | serial_connection_out(machine(),&m_connection); |
| 285 | } |
| 286 | |
| 287 | m_out_txempty_func((m_status & I8251_STATUS_TX_EMPTY) != 0); |
| 288 | } |
| 289 | |
| 290 | |
| 291 | |
| 292 | //------------------------------------------------- |
| 293 | // device_reset - device-specific reset |
| 294 | //------------------------------------------------- |
| 295 | |
| 296 | void i8251_device::device_reset() |
| 297 | { |
| 298 | LOG(("I8251: Reset\n")); |
| 299 | |
| 300 | /* what is the default setup when the 8251 has been reset??? */ |
| 301 | |
| 302 | /* i8251 datasheet explains the state of tx pin at reset */ |
| 303 | /* tx is set to 1 */ |
| 304 | set_out_data_bit(m_connection.State,1); |
| 305 | |
| 306 | /* assumption, rts is set to 1 */ |
| 307 | m_connection.State &= ~SERIAL_STATE_RTS; |
| 308 | serial_connection_out(machine(), &m_connection); |
| 309 | |
| 310 | transmit_register_reset(&m_transmit_reg); |
| 311 | receive_register_reset(&m_receive_reg); |
| 312 | /* expecting mode byte */ |
| 313 | m_flags |= I8251_EXPECTING_MODE; |
| 314 | /* not expecting a sync byte */ |
| 315 | m_flags &= ~I8251_EXPECTING_SYNC_BYTE; |
| 316 | |
| 317 | /* no character to read by cpu */ |
| 318 | /* transmitter is ready and is empty */ |
| 319 | m_status = I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY; |
| 320 | m_mode_byte = 0; |
| 321 | m_command = 0; |
| 322 | |
| 323 | /* update tx empty pin output */ |
| 324 | update_tx_empty(); |
| 325 | /* update rx ready pin output */ |
| 326 | update_rx_ready(); |
| 327 | /* update tx ready pin output */ |
| 328 | update_tx_ready(); |
| 329 | } |
| 330 | |
| 331 | |
| 332 | |
| 333 | /*------------------------------------------------- |
| 334 | control_w |
| 335 | -------------------------------------------------*/ |
| 336 | |
| 337 | WRITE8_MEMBER(i8251_device::control_w) |
| 338 | { |
| 339 | if (m_flags & I8251_EXPECTING_MODE) |
| 340 | { |
| 341 | if (m_flags & I8251_EXPECTING_SYNC_BYTE) |
| 342 | { |
| 343 | LOG(("I8251: Sync byte\n")); |
| 344 | |
| 345 | LOG(("Sync byte: %02x\n", data)); |
| 346 | /* store sync byte written */ |
| 347 | m_sync_bytes[m_sync_byte_offset] = data; |
| 348 | m_sync_byte_offset++; |
| 349 | |
| 350 | if (m_sync_byte_offset == m_sync_byte_count) |
| 351 | { |
| 352 | /* finished transfering sync bytes, now expecting command */ |
| 353 | m_flags &= ~(I8251_EXPECTING_MODE | I8251_EXPECTING_SYNC_BYTE); |
| 354 | m_sync_byte_offset = 0; |
| 355 | // m_status = I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY; |
| 356 | } |
| 357 | } |
| 358 | else |
| 359 | { |
| 360 | LOG(("I8251: Mode byte\n")); |
| 361 | |
| 362 | m_mode_byte = data; |
| 363 | |
| 364 | /* Synchronous or Asynchronous? */ |
| 365 | if ((data & 0x03)!=0) |
| 366 | { |
| 367 | /* Asynchronous |
| 368 | |
| 369 | bit 7,6: stop bit length |
| 370 | 0 = inhibit |
| 371 | 1 = 1 bit |
| 372 | 2 = 1.5 bits |
| 373 | 3 = 2 bits |
| 374 | bit 5: parity type |
| 375 | 0 = parity odd |
| 376 | 1 = parity even |
| 377 | bit 4: parity test enable |
| 378 | 0 = disable |
| 379 | 1 = enable |
| 380 | bit 3,2: character length |
| 381 | 0 = 5 bits |
| 382 | 1 = 6 bits |
| 383 | 2 = 7 bits |
| 384 | 3 = 8 bits |
| 385 | bit 1,0: baud rate factor |
| 386 | 0 = defines command byte for synchronous or asynchronous |
| 387 | 1 = x1 |
| 388 | 2 = x16 |
| 389 | 3 = x64 |
| 390 | */ |
| 391 | |
| 392 | LOG(("I8251: Asynchronous operation\n")); |
| 393 | |
| 394 | LOG(("Character length: %d\n", (((data>>2) & 0x03)+5))); |
| 395 | |
| 396 | if (data & (1<<4)) |
| 397 | { |
| 398 | LOG(("enable parity checking\n")); |
| 399 | } |
| 400 | else |
| 401 | { |
| 402 | LOG(("parity check disabled\n")); |
| 403 | } |
| 404 | |
| 405 | if (data & (1<<5)) |
| 406 | { |
| 407 | LOG(("even parity\n")); |
| 408 | } |
| 409 | else |
| 410 | { |
| 411 | LOG(("odd parity\n")); |
| 412 | } |
| 413 | |
| 414 | { |
| 415 | UINT8 stop_bit_length; |
| 416 | |
| 417 | stop_bit_length = (data>>6) & 0x03; |
| 418 | |
| 419 | switch (stop_bit_length) |
| 420 | { |
| 421 | case 0: |
| 422 | { |
| 423 | /* inhibit */ |
| 424 | LOG(("stop bit: inhibit\n")); |
| 425 | } |
| 426 | break; |
| 427 | |
| 428 | case 1: |
| 429 | { |
| 430 | /* 1 */ |
| 431 | LOG(("stop bit: 1 bit\n")); |
| 432 | } |
| 433 | break; |
| 434 | |
| 435 | case 2: |
| 436 | { |
| 437 | /* 1.5 */ |
| 438 | LOG(("stop bit: 1.5 bits\n")); |
| 439 | } |
| 440 | break; |
| 441 | |
| 442 | case 3: |
| 443 | { |
| 444 | /* 2 */ |
| 445 | LOG(("stop bit: 2 bits\n")); |
| 446 | } |
| 447 | break; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | m_form.word_length = ((data>>2) & 0x03)+5; |
| 452 | m_form.parity = SERIAL_PARITY_NONE; |
| 453 | switch ((data>>6) & 0x03) |
| 454 | { |
| 455 | case 0: |
| 456 | case 1: |
| 457 | m_form.stop_bit_count = 1; |
| 458 | break; |
| 459 | case 2: |
| 460 | case 3: |
| 461 | m_form.stop_bit_count = 2; |
| 462 | break; |
| 463 | } |
| 464 | receive_register_setup(&m_receive_reg, &m_form); |
| 465 | |
| 466 | |
| 467 | #if 0 |
| 468 | /* data bits */ |
| 469 | m_receive_char_length = (((data>>2) & 0x03)+5); |
| 470 | |
| 471 | if (data & (1<<4)) |
| 472 | { |
| 473 | /* parity */ |
| 474 | m_receive_char_length++; |
| 475 | } |
| 476 | |
| 477 | /* stop bits */ |
| 478 | m_receive_char_length++; |
| 479 | |
| 480 | m_receive_flags &=~I8251_TRANSFER_RECEIVE_SYNCHRONISED; |
| 481 | m_receive_flags |= I8251_TRANSFER_RECEIVE_WAITING_FOR_START_BIT; |
| 482 | #endif |
| 483 | /* not expecting mode byte now */ |
| 484 | m_flags &= ~I8251_EXPECTING_MODE; |
| 485 | // m_status = I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY; |
| 486 | } |
| 487 | else |
| 488 | { |
| 489 | /* bit 7: Number of sync characters |
| 490 | 0 = 1 character |
| 491 | 1 = 2 character |
| 492 | bit 6: Synchronous mode |
| 493 | 0 = Internal synchronisation |
| 494 | 1 = External synchronisation |
| 495 | bit 5: parity type |
| 496 | 0 = parity odd |
| 497 | 1 = parity even |
| 498 | bit 4: parity test enable |
| 499 | 0 = disable |
| 500 | 1 = enable |
| 501 | bit 3,2: character length |
| 502 | 0 = 5 bits |
| 503 | 1 = 6 bits |
| 504 | 2 = 7 bits |
| 505 | 3 = 8 bits |
| 506 | bit 1,0 = 0 |
| 507 | */ |
| 508 | LOG(("I8251: Synchronous operation\n")); |
| 509 | |
| 510 | /* setup for sync byte(s) */ |
| 511 | m_flags |= I8251_EXPECTING_SYNC_BYTE; |
| 512 | m_sync_byte_offset = 0; |
| 513 | if (data & 0x07) |
| 514 | { |
| 515 | m_sync_byte_count = 1; |
| 516 | } |
| 517 | else |
| 518 | { |
| 519 | m_sync_byte_count = 2; |
| 520 | } |
| 521 | |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | else |
| 526 | { |
| 527 | /* command */ |
| 528 | LOG(("I8251: Command byte\n")); |
| 529 | |
| 530 | m_command = data; |
| 531 | |
| 532 | LOG(("Command byte: %02x\n", data)); |
| 533 | |
| 534 | if (data & (1<<7)) |
| 535 | { |
| 536 | LOG(("hunt mode\n")); |
| 537 | } |
| 538 | |
| 539 | if (data & (1<<5)) |
| 540 | { |
| 541 | LOG(("/rts set to 0\n")); |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | LOG(("/rts set to 1\n")); |
| 546 | } |
| 547 | |
| 548 | if (data & (1<<2)) |
| 549 | { |
| 550 | LOG(("receive enable\n")); |
| 551 | } |
| 552 | else |
| 553 | { |
| 554 | LOG(("receive disable\n")); |
| 555 | } |
| 556 | |
| 557 | if (data & (1<<1)) |
| 558 | { |
| 559 | LOG(("/dtr set to 0\n")); |
| 560 | } |
| 561 | else |
| 562 | { |
| 563 | LOG(("/dtr set to 1\n")); |
| 564 | } |
| 565 | |
| 566 | if (data & (1<<0)) |
| 567 | { |
| 568 | LOG(("transmit enable\n")); |
| 569 | } |
| 570 | else |
| 571 | { |
| 572 | LOG(("transmit disable\n")); |
| 573 | } |
| 574 | |
| 575 | |
| 576 | /* bit 7: |
| 577 | 0 = normal operation |
| 578 | 1 = hunt mode |
| 579 | bit 6: |
| 580 | 0 = normal operation |
| 581 | 1 = internal reset |
| 582 | bit 5: |
| 583 | 0 = /RTS set to 1 |
| 584 | 1 = /RTS set to 0 |
| 585 | bit 4: |
| 586 | 0 = normal operation |
| 587 | 1 = reset error flag |
| 588 | bit 3: |
| 589 | 0 = normal operation |
| 590 | 1 = send break character |
| 591 | bit 2: |
| 592 | 0 = receive disable |
| 593 | 1 = receive enable |
| 594 | bit 1: |
| 595 | 0 = /DTR set to 1 |
| 596 | 1 = /DTR set to 0 |
| 597 | bit 0: |
| 598 | 0 = transmit disable |
| 599 | 1 = transmit enable |
| 600 | */ |
| 601 | |
| 602 | m_connection.State &=~SERIAL_STATE_RTS; |
| 603 | if (data & (1<<5)) |
| 604 | { |
| 605 | /* rts set to 0 */ |
| 606 | m_connection.State |= SERIAL_STATE_RTS; |
| 607 | } |
| 608 | |
| 609 | m_connection.State &=~SERIAL_STATE_DTR; |
| 610 | if (data & (1<<1)) |
| 611 | { |
| 612 | m_connection.State |= SERIAL_STATE_DTR; |
| 613 | } |
| 614 | |
| 615 | if ((data & (1<<0))==0) |
| 616 | { |
| 617 | /* held in high state when transmit disable */ |
| 618 | set_out_data_bit(m_connection.State,1); |
| 619 | } |
| 620 | |
| 621 | |
| 622 | /* refresh outputs */ |
| 623 | serial_connection_out(machine(), &m_connection); |
| 624 | |
| 625 | if (data & (1<<4)) |
| 626 | { |
| 627 | m_status &= ~(I8251_STATUS_PARITY_ERROR | I8251_STATUS_OVERRUN_ERROR | I8251_STATUS_FRAMING_ERROR); |
| 628 | } |
| 629 | |
| 630 | if (data & (1<<6)) |
| 631 | { |
| 632 | reset(); |
| 633 | } |
| 634 | |
| 635 | update_rx_ready(); |
| 636 | update_tx_ready(); |
| 637 | |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | |
| 642 | |
| 643 | /*------------------------------------------------- |
| 644 | status_r |
| 645 | -------------------------------------------------*/ |
| 646 | |
| 647 | READ8_MEMBER(i8251_device::status_r) |
| 648 | { |
| 649 | LOG(("status: %02x\n", m_status)); |
| 650 | return m_status; |
| 651 | } |
| 652 | |
| 653 | |
| 654 | |
| 655 | /*------------------------------------------------- |
| 656 | data_w |
| 657 | -------------------------------------------------*/ |
| 658 | |
| 659 | WRITE8_MEMBER(i8251_device::data_w) |
| 660 | { |
| 661 | m_data = data; |
| 662 | |
| 663 | logerror("write data: %02x\n",data); |
| 664 | |
| 665 | /* writing clears */ |
| 666 | m_status &=~I8251_STATUS_TX_READY; |
| 667 | |
| 668 | /* if transmitter is active, then tx empty will be signalled */ |
| 669 | |
| 670 | update_tx_ready(); |
| 671 | } |
| 672 | |
| 673 | |
| 674 | |
| 675 | /*------------------------------------------------- |
| 676 | receive_character - called when last |
| 677 | bit of data has been received |
| 678 | -------------------------------------------------*/ |
| 679 | |
| 680 | void i8251_device::receive_character(UINT8 ch) |
| 681 | { |
| 682 | logerror("i8251 receive char: %02x\n",ch); |
| 683 | |
| 684 | m_data = ch; |
| 685 | |
| 686 | /* char has not been read and another has arrived! */ |
| 687 | if (m_status & I8251_STATUS_RX_READY) |
| 688 | { |
| 689 | m_status |= I8251_STATUS_OVERRUN_ERROR; |
| 690 | } |
| 691 | m_status |= I8251_STATUS_RX_READY; |
| 692 | |
| 693 | update_rx_ready(); |
| 694 | } |
| 695 | |
| 696 | |
| 697 | |
| 698 | /*------------------------------------------------- |
| 699 | data_r - read data |
| 700 | -------------------------------------------------*/ |
| 701 | |
| 702 | READ8_MEMBER(i8251_device::data_r) |
| 703 | { |
| 704 | logerror("read data: %02x, STATUS=%02x\n",m_data,m_status); |
| 705 | /* reading clears */ |
| 706 | m_status &= ~I8251_STATUS_RX_READY; |
| 707 | |
| 708 | update_rx_ready(); |
| 709 | return m_data; |
| 710 | } |
| 711 | |
| 712 | |
| 713 | |
| 714 | /*------------------------------------------------- |
| 715 | connect_to_serial_device - initialise |
| 716 | transfer using serial device - set the callback |
| 717 | which will be called when serial device has |
| 718 | updated it's state |
| 719 | -------------------------------------------------*/ |
| 720 | |
| 721 | void i8251_device::connect_to_serial_device(device_t *image) |
| 722 | { |
| 723 | serial_device_connect(image, &m_connection); |
| 724 | } |
| 725 | |
| 726 | |
| 727 | |
| 728 | /*------------------------------------------------- |
| 729 | connect |
| 730 | -------------------------------------------------*/ |
| 731 | |
| 732 | void i8251_device::connect(serial_connection *other_connection) |
| 733 | { |
| 734 | serial_connection_link(machine(), &m_connection, other_connection); |
| 735 | } |
src/mess/machine/i8251.h
| r0 | r12757 | |
| 1 | /********************************************************************* |
| 2 | |
| 3 | i8251.h |
| 4 | |
| 5 | Intel 8251 Universal Synchronous/Asynchronous Receiver Transmitter code |
| 6 | |
| 7 | *********************************************************************/ |
| 8 | |
| 9 | #ifndef __I8251_H__ |
| 10 | #define __I8251_H__ |
| 11 | |
| 12 | #include "machine/serial.h" |
| 13 | |
| 14 | |
| 15 | /*************************************************************************** |
| 16 | CONSTANTS |
| 17 | ***************************************************************************/ |
| 18 | |
| 19 | #define I8251_EXPECTING_MODE 0x01 |
| 20 | #define I8251_EXPECTING_SYNC_BYTE 0x02 |
| 21 | |
| 22 | #define I8251_STATUS_FRAMING_ERROR 0x20 |
| 23 | #define I8251_STATUS_OVERRUN_ERROR 0x10 |
| 24 | #define I8251_STATUS_PARITY_ERROR 0x08 |
| 25 | #define I8251_STATUS_TX_EMPTY 0x04 |
| 26 | #define I8251_STATUS_RX_READY 0x02 |
| 27 | #define I8251_STATUS_TX_READY 0x01 |
| 28 | |
| 29 | //************************************************************************** |
| 30 | // INTERFACE CONFIGURATION MACROS |
| 31 | //************************************************************************** |
| 32 | |
| 33 | #define MCFG_I8251_ADD(_tag, _intrf) \ |
| 34 | MCFG_DEVICE_ADD(_tag, I8251, 0) \ |
| 35 | MCFG_DEVICE_CONFIG(_intrf) |
| 36 | |
| 37 | #define MCFG_I8251_REMOVE(_tag) \ |
| 38 | MCFG_DEVICE_REMOVE(_tag) |
| 39 | |
| 40 | |
| 41 | /*************************************************************************** |
| 42 | TYPE DEFINITIONS |
| 43 | ***************************************************************************/ |
| 44 | // ======================> i8251_interface |
| 45 | |
| 46 | struct i8251_interface |
| 47 | { |
| 48 | devcb_read_line m_in_rxd_cb; |
| 49 | devcb_write_line m_out_txd_cb; |
| 50 | devcb_read_line m_in_dsr_cb; |
| 51 | devcb_write_line m_out_dtr_cb; |
| 52 | devcb_write_line m_out_rts_cb; |
| 53 | devcb_write_line m_out_rxrdy_cb; |
| 54 | devcb_write_line m_out_txrdy_cb; |
| 55 | devcb_write_line m_out_txempty_cb; |
| 56 | devcb_write_line m_out_syndet_cb; |
| 57 | }; |
| 58 | |
| 59 | // ======================> i8251_device |
| 60 | |
| 61 | class i8251_device : public device_t, |
| 62 | public i8251_interface |
| 63 | { |
| 64 | public: |
| 65 | // construction/destruction |
| 66 | i8251_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 67 | |
| 68 | /* read data register */ |
| 69 | DECLARE_READ8_MEMBER(data_r); |
| 70 | |
| 71 | /* read status register */ |
| 72 | DECLARE_READ8_MEMBER(status_r); |
| 73 | |
| 74 | /* write data register */ |
| 75 | DECLARE_WRITE8_MEMBER(data_w); |
| 76 | |
| 77 | /* write control word */ |
| 78 | DECLARE_WRITE8_MEMBER(control_w); |
| 79 | |
| 80 | /* The 8251 has seperate transmit and receive clocks */ |
| 81 | /* use these two functions to update the i8251 for each clock */ |
| 82 | /* on NC100 system, the clocks are the same */ |
| 83 | void transmit_clock(); |
| 84 | void receive_clock(); |
| 85 | |
| 86 | /* connecting to serial output */ |
| 87 | void connect_to_serial_device(device_t *image); |
| 88 | void connect(serial_connection *other_connection); |
| 89 | |
| 90 | void receive_character(UINT8 ch); |
| 91 | |
| 92 | serial_connection *get_connection() { return &m_connection; } |
| 93 | protected: |
| 94 | // device-level overrides |
| 95 | virtual void device_start(); |
| 96 | virtual void device_config_complete(); |
| 97 | virtual void device_reset(); |
| 98 | |
| 99 | void update_rx_ready(); |
| 100 | void update_tx_ready(); |
| 101 | void update_tx_empty(); |
| 102 | private: |
| 103 | devcb_resolved_read_line m_in_rxd_func; |
| 104 | devcb_resolved_write_line m_out_txd_func; |
| 105 | devcb_resolved_read_line m_in_dsr_func; |
| 106 | devcb_resolved_write_line m_out_dtr_func; |
| 107 | devcb_resolved_write_line m_out_rts_func; |
| 108 | devcb_resolved_write_line m_out_rxrdy_func; |
| 109 | devcb_resolved_write_line m_out_txrdy_func; |
| 110 | devcb_resolved_write_line m_out_txempty_func; |
| 111 | devcb_resolved_write_line m_out_syndet_func; |
| 112 | |
| 113 | /* flags controlling how i8251_control_w operates */ |
| 114 | UINT8 m_flags; |
| 115 | /* offset into sync_bytes used during sync byte transfer */ |
| 116 | UINT8 m_sync_byte_offset; |
| 117 | /* number of sync bytes written so far */ |
| 118 | UINT8 m_sync_byte_count; |
| 119 | /* the sync bytes written */ |
| 120 | UINT8 m_sync_bytes[2]; |
| 121 | /* status of i8251 */ |
| 122 | UINT8 m_status; |
| 123 | UINT8 m_command; |
| 124 | /* mode byte - bit definitions depend on mode - e.g. synchronous, asynchronous */ |
| 125 | UINT8 m_mode_byte; |
| 126 | |
| 127 | /* data being received */ |
| 128 | UINT8 m_data; |
| 129 | |
| 130 | /* receive reg */ |
| 131 | serial_receive_register m_receive_reg; |
| 132 | /* transmit reg */ |
| 133 | serial_transmit_register m_transmit_reg; |
| 134 | |
| 135 | data_form m_form; |
| 136 | |
| 137 | /* the serial connection that data is transfered over */ |
| 138 | /* this is usually connected to the serial device */ |
| 139 | serial_connection m_connection; |
| 140 | }; |
| 141 | |
| 142 | |
| 143 | |
| 144 | // device type definition |
| 145 | extern const device_type I8251; |
| 146 | |
| 147 | extern const i8251_interface default_i8251_interface; |
| 148 | |
| 149 | #endif /* __I8251_H__ */ |