src/mess/machine/msm8251.c
| r3714 | r3715 | |
| 1 | | /* MSM 8251/INTEL 8251 UART */ |
| 1 | /********************************************************************* |
| 2 | 2 | |
| 3 | msm8251.c |
| 4 | |
| 5 | MSM/Intel 8251 Universal Synchronous/Asynchronous Receiver Transmitter code |
| 6 | |
| 7 | *********************************************************************/ |
| 8 | |
| 3 | 9 | #include "driver.h" |
| 10 | #include "deprecat.h" |
| 4 | 11 | #include "msm8251.h" |
| 5 | 12 | #include "includes/serial.h" |
| 6 | 13 | |
| 14 | |
| 15 | /*************************************************************************** |
| 16 | MACROS |
| 17 | ***************************************************************************/ |
| 18 | |
| 7 | 19 | #define VERBOSE 1 |
| 8 | 20 | |
| 9 | 21 | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 10 | 22 | |
| 11 | | static struct msm8251 uart; |
| 12 | | static void msm8251_receive_character(UINT8 ch); |
| 23 | |
| 24 | /*************************************************************************** |
| 25 | TYPE DEFINITIONS |
| 26 | ***************************************************************************/ |
| 27 | |
| 28 | typedef struct _msm8251_t msm8251_t; |
| 29 | struct _msm8251_t |
| 30 | { |
| 31 | /* flags controlling how msm8251_control_w operates */ |
| 32 | UINT8 flags; |
| 33 | /* offset into sync_bytes used during sync byte transfer */ |
| 34 | UINT8 sync_byte_offset; |
| 35 | /* number of sync bytes written so far */ |
| 36 | UINT8 sync_byte_count; |
| 37 | /* the sync bytes written */ |
| 38 | UINT8 sync_bytes[2]; |
| 39 | /* status of msm8251 */ |
| 40 | UINT8 status; |
| 41 | UINT8 command; |
| 42 | /* mode byte - bit definitions depend on mode - e.g. synchronous, asynchronous */ |
| 43 | UINT8 mode_byte; |
| 44 | |
| 45 | /* data being received */ |
| 46 | UINT8 data; |
| 47 | |
| 48 | /* receive reg */ |
| 49 | struct serial_receive_register receive_reg; |
| 50 | /* transmit reg */ |
| 51 | struct serial_transmit_register transmit_reg; |
| 52 | |
| 53 | struct data_form data_form; |
| 54 | |
| 55 | /* the serial connection that data is transfered over */ |
| 56 | /* this is usually connected to the serial device */ |
| 57 | struct serial_connection connection; |
| 58 | }; |
| 59 | |
| 60 | |
| 61 | |
| 62 | /*************************************************************************** |
| 63 | PROTOTYPES |
| 64 | ***************************************************************************/ |
| 65 | |
| 66 | static void msm8251_receive_character(const device_config *device, UINT8 ch); |
| 13 | 67 | static void msm8251_in_callback(int id, unsigned long state); |
| 14 | | static void msm8251_update_tx_empty(void); |
| 15 | | static void msm8251_update_tx_ready(void); |
| 68 | static void msm8251_update_tx_empty(const device_config *device); |
| 69 | static void msm8251_update_tx_ready(const device_config *device); |
| 16 | 70 | |
| 71 | |
| 72 | |
| 73 | /*************************************************************************** |
| 74 | INLINE FUNCTIONS |
| 75 | ***************************************************************************/ |
| 76 | |
| 77 | INLINE msm8251_t *get_token(const device_config *device) |
| 78 | { |
| 79 | assert(device->type == MSM8251); |
| 80 | return (msm8251_t *) device->token; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | INLINE const msm8251_interface *get_interface(const device_config *device) |
| 85 | { |
| 86 | static msm8251_interface dummy_interface = {0, }; |
| 87 | |
| 88 | assert(device->type == MSM8251); |
| 89 | return device->static_config != NULL |
| 90 | ? (const msm8251_interface *) device->static_config |
| 91 | : &dummy_interface; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | /*************************************************************************** |
| 96 | IMPLEMENTATION |
| 97 | ***************************************************************************/ |
| 98 | |
| 99 | /*------------------------------------------------- |
| 100 | msm8251_in_callback |
| 101 | -------------------------------------------------*/ |
| 102 | |
| 17 | 103 | static void msm8251_in_callback(int id, unsigned long state) |
| 18 | 104 | { |
| 105 | const device_config *device; |
| 106 | msm8251_t *uart; |
| 19 | 107 | int changed; |
| 20 | 108 | |
| 21 | | changed = uart.connection.input_state^state; |
| 109 | /* NPW 29-Nov-2008 - These two lines are a hack and indicate why our "serial" infrastructure needs to be updated */ |
| 110 | device = device_list_find_by_tag(Machine->config->devicelist, MSM8251, "uart"); |
| 111 | uart = get_token(device); |
| 22 | 112 | |
| 23 | | uart.connection.input_state = state; |
| 113 | changed = uart->connection.input_state^state; |
| 24 | 114 | |
| 115 | uart->connection.input_state = state; |
| 116 | |
| 25 | 117 | /* did cts change state? */ |
| 26 | 118 | if (changed & SERIAL_STATE_CTS) |
| 27 | 119 | { |
| 28 | 120 | /* yes */ |
| 29 | 121 | /* update tx ready */ |
| 30 | | msm8251_update_tx_ready(); |
| 122 | /* msm8251_update_tx_ready(device); */ |
| 31 | 123 | } |
| 32 | 124 | } |
| 33 | 125 | |
| 34 | 126 | |
| 35 | | /* init */ |
| 36 | | void msm8251_init(const struct msm8251_interface *iface) |
| 127 | |
| 128 | /*------------------------------------------------- |
| 129 | DEVICE_START( msm8251 ) |
| 130 | -------------------------------------------------*/ |
| 131 | |
| 132 | static DEVICE_START( msm8251 ) |
| 37 | 133 | { |
| 134 | msm8251_t *uart = get_token(device); |
| 135 | |
| 38 | 136 | serial_helper_setup(); |
| 39 | 137 | |
| 40 | | /* copy interface */ |
| 41 | | if (iface!=NULL) |
| 42 | | { |
| 43 | | memcpy(&uart.interface, iface, sizeof(struct msm8251_interface)); |
| 44 | | } |
| 45 | | |
| 46 | 138 | /* setup this side of the serial connection */ |
| 47 | | serial_connection_init(&uart.connection); |
| 48 | | serial_connection_set_in_callback(&uart.connection, msm8251_in_callback); |
| 49 | | uart.connection.input_state = 0; |
| 50 | | /* reset chip */ |
| 51 | | msm8251_reset(); |
| 52 | | |
| 139 | serial_connection_init(&uart->connection); |
| 140 | serial_connection_set_in_callback(&uart->connection, msm8251_in_callback); |
| 141 | uart->connection.input_state = 0; |
| 142 | return DEVICE_START_OK; |
| 53 | 143 | } |
| 54 | 144 | |
| 55 | | static void msm8251_update_rx_ready(void) |
| 145 | |
| 146 | |
| 147 | /*------------------------------------------------- |
| 148 | msm8251_update_rx_ready |
| 149 | -------------------------------------------------*/ |
| 150 | |
| 151 | static void msm8251_update_rx_ready(const device_config *device) |
| 56 | 152 | { |
| 153 | msm8251_t *uart = get_token(device); |
| 154 | const msm8251_interface *uart_interface = get_interface(device); |
| 57 | 155 | int state; |
| 58 | 156 | |
| 59 | | state = uart.status & MSM8251_STATUS_RX_READY; |
| 157 | state = uart->status & MSM8251_STATUS_RX_READY; |
| 60 | 158 | |
| 61 | 159 | /* masked? */ |
| 62 | | if ((uart.command & (1<<2))==0) |
| 160 | if ((uart->command & (1<<2))==0) |
| 63 | 161 | { |
| 64 | 162 | state = 0; |
| 65 | 163 | } |
| 66 | 164 | |
| 67 | | if (uart.interface.rx_ready_callback) |
| 68 | | uart.interface.rx_ready_callback((state!=0)); |
| 69 | | |
| 165 | /* invoke rx_ready_callback, if present */ |
| 166 | if (uart_interface->rx_ready_callback != NULL) |
| 167 | (*uart_interface->rx_ready_callback)(device, state != 0); |
| 70 | 168 | } |
| 71 | 169 | |
| 72 | | void msm8251_receive_clock(void) |
| 170 | |
| 171 | |
| 172 | /*------------------------------------------------- |
| 173 | msm8251_receive_clock |
| 174 | -------------------------------------------------*/ |
| 175 | |
| 176 | void msm8251_receive_clock(const device_config *device) |
| 73 | 177 | { |
| 178 | msm8251_t *uart = get_token(device); |
| 179 | |
| 74 | 180 | /* receive enable? */ |
| 75 | | if (uart.command & (1<<2)) |
| 181 | if (uart->command & (1<<2)) |
| 76 | 182 | { |
| 77 | 183 | //logerror("MSM8251\n"); |
| 78 | 184 | /* get bit received from other side and update receive register */ |
| 79 | | receive_register_update_bit(&uart.receive_reg, get_in_data_bit(uart.connection.input_state)); |
| 185 | receive_register_update_bit(&uart->receive_reg, get_in_data_bit(uart->connection.input_state)); |
| 80 | 186 | |
| 81 | | if (uart.receive_reg.flags & RECEIVE_REGISTER_FULL) |
| 187 | if (uart->receive_reg.flags & RECEIVE_REGISTER_FULL) |
| 82 | 188 | { |
| 83 | | receive_register_extract(&uart.receive_reg, &uart.data_form); |
| 84 | | msm8251_receive_character(uart.receive_reg.byte_received); |
| 189 | receive_register_extract(&uart->receive_reg, &uart->data_form); |
| 190 | msm8251_receive_character(device, uart->receive_reg.byte_received); |
| 85 | 191 | } |
| 86 | 192 | } |
| 87 | 193 | } |
| 88 | 194 | |
| 89 | | void msm8251_transmit_clock(void) |
| 195 | |
| 196 | |
| 197 | /*------------------------------------------------- |
| 198 | msm8251_transmit_clock |
| 199 | -------------------------------------------------*/ |
| 200 | |
| 201 | void msm8251_transmit_clock(const device_config *device) |
| 90 | 202 | { |
| 203 | msm8251_t *uart = get_token(device); |
| 204 | |
| 91 | 205 | /* transmit enable? */ |
| 92 | | if (uart.command & (1<<0)) |
| 206 | if (uart->command & (1<<0)) |
| 93 | 207 | { |
| 94 | 208 | |
| 95 | 209 | /* transmit register full? */ |
| 96 | | if ((uart.status & MSM8251_STATUS_TX_READY)==0) |
| 210 | if ((uart->status & MSM8251_STATUS_TX_READY)==0) |
| 97 | 211 | { |
| 98 | 212 | /* if transmit reg is empty */ |
| 99 | | if ((uart.transmit_reg.flags & TRANSMIT_REGISTER_EMPTY)!=0) |
| 213 | if ((uart->transmit_reg.flags & TRANSMIT_REGISTER_EMPTY)!=0) |
| 100 | 214 | { |
| 101 | 215 | /* set it up */ |
| 102 | | transmit_register_setup(&uart.transmit_reg, &uart.data_form, uart.data); |
| 216 | transmit_register_setup(&uart->transmit_reg, &uart->data_form, uart->data); |
| 103 | 217 | /* msm8251 transmit reg now empty */ |
| 104 | | uart.status |=MSM8251_STATUS_TX_EMPTY; |
| 218 | uart->status |=MSM8251_STATUS_TX_EMPTY; |
| 105 | 219 | /* ready for next transmit */ |
| 106 | | uart.status |=MSM8251_STATUS_TX_READY; |
| 220 | uart->status |=MSM8251_STATUS_TX_READY; |
| 107 | 221 | |
| 108 | | msm8251_update_tx_empty(); |
| 109 | | msm8251_update_tx_ready(); |
| 222 | msm8251_update_tx_empty(device); |
| 223 | msm8251_update_tx_ready(device); |
| 110 | 224 | } |
| 111 | 225 | } |
| 112 | 226 | |
| 113 | 227 | /* if transmit is not empty... transmit data */ |
| 114 | | if ((uart.transmit_reg.flags & TRANSMIT_REGISTER_EMPTY)==0) |
| 228 | if ((uart->transmit_reg.flags & TRANSMIT_REGISTER_EMPTY)==0) |
| 115 | 229 | { |
| 116 | 230 | // logerror("MSM8251\n"); |
| 117 | | transmit_register_send_bit(&uart.transmit_reg, &uart.connection); |
| 231 | transmit_register_send_bit(&uart->transmit_reg, &uart->connection); |
| 118 | 232 | } |
| 119 | 233 | } |
| 120 | 234 | |
| 121 | 235 | #if 0 |
| 122 | 236 | /* hunt mode? */ |
| 123 | 237 | /* after each bit has been shifted in, it is compared against the current sync byte */ |
| 124 | | if (uart.command & (1<<7)) |
| 238 | if (uart->command & (1<<7)) |
| 125 | 239 | { |
| 126 | 240 | /* data matches sync byte? */ |
| 127 | | if (uart.data == uart.sync_bytes[uart.sync_byte_offset]) |
| 241 | if (uart->data == uart->sync_bytes[uart->sync_byte_offset]) |
| 128 | 242 | { |
| 129 | 243 | /* sync byte matches */ |
| 130 | 244 | /* update for next sync byte? */ |
| 131 | | uart.sync_byte_offset++; |
| 245 | uart->sync_byte_offset++; |
| 132 | 246 | |
| 133 | 247 | /* do all sync bytes match? */ |
| 134 | | if (uart.sync_byte_offset == uart.sync_byte_count) |
| 248 | if (uart->sync_byte_offset == uart->sync_byte_count) |
| 135 | 249 | { |
| 136 | 250 | /* ent hunt mode */ |
| 137 | | uart.command &=~(1<<7); |
| 251 | uart->command &=~(1<<7); |
| 138 | 252 | } |
| 139 | 253 | } |
| 140 | 254 | else |
| 141 | 255 | { |
| 142 | 256 | /* if there is no match, reset */ |
| 143 | | uart.sync_byte_offset = 0; |
| 257 | uart->sync_byte_offset = 0; |
| 144 | 258 | } |
| 145 | 259 | } |
| 146 | 260 | #endif |
| 147 | 261 | } |
| 148 | 262 | |
| 149 | 263 | |
| 150 | | static void msm8251_update_tx_ready(void) |
| 264 | |
| 265 | /*------------------------------------------------- |
| 266 | msm8251_update_tx_ready |
| 267 | -------------------------------------------------*/ |
| 268 | |
| 269 | static void msm8251_update_tx_ready(const device_config *device) |
| 151 | 270 | { |
| 271 | msm8251_t *uart = get_token(device); |
| 272 | const msm8251_interface *uart_interface = get_interface(device); |
| 273 | |
| 152 | 274 | /* clear tx ready state */ |
| 153 | 275 | int tx_ready; |
| 154 | 276 | |
| r3714 | r3715 | |
| 158 | 280 | Transmit enable is 1 |
| 159 | 281 | */ |
| 160 | 282 | |
| 161 | | |
| 162 | 283 | tx_ready = 0; |
| 163 | 284 | |
| 164 | 285 | /* transmit enable? */ |
| 165 | | if ((uart.command & (1<<0))!=0) |
| 286 | if ((uart->command & (1<<0))!=0) |
| 166 | 287 | { |
| 167 | 288 | /* other side has rts set (comes in as CTS at this side) */ |
| 168 | | if (uart.connection.input_state & SERIAL_STATE_CTS) |
| 289 | if (uart->connection.input_state & SERIAL_STATE_CTS) |
| 169 | 290 | { |
| 170 | | if (uart.status & MSM8251_STATUS_TX_EMPTY) |
| 291 | if (uart->status & MSM8251_STATUS_TX_EMPTY) |
| 171 | 292 | { |
| 172 | 293 | /* enable transfer */ |
| 173 | 294 | tx_ready = 1; |
| r3714 | r3715 | |
| 175 | 296 | } |
| 176 | 297 | } |
| 177 | 298 | |
| 178 | | if (uart.interface.tx_ready_callback) |
| 179 | | uart.interface.tx_ready_callback(tx_ready); |
| 299 | if (uart_interface->tx_ready_callback != NULL) |
| 300 | (*uart_interface->tx_ready_callback)(device, tx_ready); |
| 180 | 301 | } |
| 181 | 302 | |
| 182 | | static void msm8251_update_tx_empty(void) |
| 303 | |
| 304 | |
| 305 | /*------------------------------------------------- |
| 306 | msm8251_update_tx_empty |
| 307 | -------------------------------------------------*/ |
| 308 | |
| 309 | static void msm8251_update_tx_empty(const device_config *device) |
| 183 | 310 | { |
| 184 | | if (uart.status & MSM8251_STATUS_TX_EMPTY) |
| 311 | msm8251_t *uart = get_token(device); |
| 312 | const msm8251_interface *uart_interface = get_interface(device); |
| 313 | |
| 314 | if (uart->status & MSM8251_STATUS_TX_EMPTY) |
| 185 | 315 | { |
| 186 | 316 | /* tx is in marking state (high) when tx empty! */ |
| 187 | | set_out_data_bit(uart.connection.State,1); |
| 188 | | serial_connection_out(&uart.connection); |
| 317 | set_out_data_bit(uart->connection.State, 1); |
| 318 | serial_connection_out(&uart->connection); |
| 189 | 319 | } |
| 190 | | if (uart.interface.tx_empty_callback) |
| 191 | | uart.interface.tx_empty_callback(((uart.status & MSM8251_STATUS_TX_EMPTY)!=0)); |
| 192 | 320 | |
| 321 | if (uart_interface->tx_empty_callback != NULL) |
| 322 | (*uart_interface->tx_empty_callback)(device, (uart->status & MSM8251_STATUS_TX_EMPTY) != 0); |
| 193 | 323 | } |
| 194 | 324 | |
| 195 | | void msm8251_reset(void) |
| 325 | |
| 326 | |
| 327 | /*------------------------------------------------- |
| 328 | DEVICE_RESET( msm8251 ) |
| 329 | -------------------------------------------------*/ |
| 330 | |
| 331 | static DEVICE_RESET( msm8251 ) |
| 196 | 332 | { |
| 333 | msm8251_t *uart = get_token(device); |
| 334 | |
| 197 | 335 | LOG(("MSM8251: Reset\n")); |
| 198 | 336 | |
| 199 | 337 | /* what is the default setup when the 8251 has been reset??? */ |
| 200 | 338 | |
| 201 | 339 | /* msm8251 datasheet explains the state of tx pin at reset */ |
| 202 | 340 | /* tx is set to 1 */ |
| 203 | | set_out_data_bit(uart.connection.State,1); |
| 341 | set_out_data_bit(uart->connection.State,1); |
| 204 | 342 | |
| 205 | 343 | /* assumption, rts is set to 1 */ |
| 206 | | uart.connection.State &= ~SERIAL_STATE_RTS; |
| 207 | | serial_connection_out(&uart.connection); |
| 344 | uart->connection.State &= ~SERIAL_STATE_RTS; |
| 345 | serial_connection_out(&uart->connection); |
| 208 | 346 | |
| 209 | | transmit_register_reset(&uart.transmit_reg); |
| 210 | | receive_register_reset(&uart.receive_reg); |
| 347 | transmit_register_reset(&uart->transmit_reg); |
| 348 | receive_register_reset(&uart->receive_reg); |
| 211 | 349 | /* expecting mode byte */ |
| 212 | | uart.flags |= MSM8251_EXPECTING_MODE; |
| 350 | uart->flags |= MSM8251_EXPECTING_MODE; |
| 213 | 351 | /* not expecting a sync byte */ |
| 214 | | uart.flags &= ~MSM8251_EXPECTING_SYNC_BYTE; |
| 352 | uart->flags &= ~MSM8251_EXPECTING_SYNC_BYTE; |
| 215 | 353 | |
| 216 | 354 | /* no character to read by cpu */ |
| 217 | 355 | /* transmitter is ready and is empty */ |
| 218 | | uart.status = MSM8251_STATUS_TX_EMPTY | MSM8251_STATUS_TX_READY; |
| 219 | | uart.mode_byte = 0; |
| 220 | | uart.command = 0; |
| 356 | uart->status = MSM8251_STATUS_TX_EMPTY | MSM8251_STATUS_TX_READY; |
| 357 | uart->mode_byte = 0; |
| 358 | uart->command = 0; |
| 221 | 359 | |
| 222 | 360 | /* update tx empty pin output */ |
| 223 | | msm8251_update_tx_empty(); |
| 361 | msm8251_update_tx_empty(device); |
| 224 | 362 | /* update rx ready pin output */ |
| 225 | | msm8251_update_rx_ready(); |
| 363 | msm8251_update_rx_ready(device); |
| 226 | 364 | /* update tx ready pin output */ |
| 227 | | msm8251_update_tx_ready(); |
| 365 | msm8251_update_tx_ready(device); |
| 228 | 366 | } |
| 229 | 367 | |
| 230 | | /* write command */ |
| 231 | | WRITE8_HANDLER(msm8251_control_w) |
| 368 | |
| 369 | |
| 370 | /*------------------------------------------------- |
| 371 | WRITE8_DEVICE_HANDLER(msm8251_control_w) |
| 372 | -------------------------------------------------*/ |
| 373 | |
| 374 | WRITE8_DEVICE_HANDLER(msm8251_control_w) |
| 232 | 375 | { |
| 376 | msm8251_t *uart = get_token(device); |
| 233 | 377 | |
| 234 | | if (uart.flags & MSM8251_EXPECTING_MODE) |
| 378 | if (uart->flags & MSM8251_EXPECTING_MODE) |
| 235 | 379 | { |
| 236 | | if (uart.flags & MSM8251_EXPECTING_SYNC_BYTE) |
| 380 | if (uart->flags & MSM8251_EXPECTING_SYNC_BYTE) |
| 237 | 381 | { |
| 238 | 382 | LOG(("MSM8251: Sync byte\n")); |
| 239 | 383 | |
| 240 | 384 | LOG(("Sync byte: %02x\n", data)); |
| 241 | 385 | /* store sync byte written */ |
| 242 | | uart.sync_bytes[uart.sync_byte_offset] = data; |
| 243 | | uart.sync_byte_offset++; |
| 386 | uart->sync_bytes[uart->sync_byte_offset] = data; |
| 387 | uart->sync_byte_offset++; |
| 244 | 388 | |
| 245 | | if (uart.sync_byte_offset==uart.sync_byte_count) |
| 389 | if (uart->sync_byte_offset == uart->sync_byte_count) |
| 246 | 390 | { |
| 247 | 391 | /* finished transfering sync bytes, now expecting command */ |
| 248 | | uart.flags &= ~(MSM8251_EXPECTING_MODE | MSM8251_EXPECTING_SYNC_BYTE); |
| 249 | | uart.sync_byte_offset = 0; |
| 250 | | // uart.status = MSM8251_STATUS_TX_EMPTY | MSM8251_STATUS_TX_READY; |
| 392 | uart->flags &= ~(MSM8251_EXPECTING_MODE | MSM8251_EXPECTING_SYNC_BYTE); |
| 393 | uart->sync_byte_offset = 0; |
| 394 | // uart->status = MSM8251_STATUS_TX_EMPTY | MSM8251_STATUS_TX_READY; |
| 251 | 395 | } |
| 252 | 396 | } |
| 253 | 397 | else |
| 254 | 398 | { |
| 255 | 399 | LOG(("MSM8251: Mode byte\n")); |
| 256 | 400 | |
| 257 | | uart.mode_byte = data; |
| 401 | uart->mode_byte = data; |
| 258 | 402 | |
| 259 | 403 | /* Synchronous or Asynchronous? */ |
| 260 | 404 | if ((data & 0x03)!=0) |
| r3714 | r3715 | |
| 343 | 487 | } |
| 344 | 488 | } |
| 345 | 489 | |
| 346 | | uart.data_form.word_length = ((data>>2) & 0x03)+5; |
| 347 | | uart.data_form.parity = SERIAL_PARITY_NONE; |
| 490 | uart->data_form.word_length = ((data>>2) & 0x03)+5; |
| 491 | uart->data_form.parity = SERIAL_PARITY_NONE; |
| 348 | 492 | switch ((data>>6) & 0x03) |
| 349 | 493 | { |
| 350 | 494 | case 0: |
| 351 | 495 | case 1: |
| 352 | | uart.data_form.stop_bit_count = 1; |
| 496 | uart->data_form.stop_bit_count = 1; |
| 353 | 497 | break; |
| 354 | 498 | case 2: |
| 355 | 499 | case 3: |
| 356 | | uart.data_form.stop_bit_count = 2; |
| 500 | uart->data_form.stop_bit_count = 2; |
| 357 | 501 | break; |
| 358 | 502 | } |
| 359 | | receive_register_setup(&uart.receive_reg, &uart.data_form); |
| 503 | receive_register_setup(&uart->receive_reg, &uart->data_form); |
| 360 | 504 | |
| 361 | 505 | |
| 362 | 506 | #if 0 |
| 363 | 507 | /* data bits */ |
| 364 | | uart.receive_char_length = (((data>>2) & 0x03)+5); |
| 508 | uart->receive_char_length = (((data>>2) & 0x03)+5); |
| 365 | 509 | |
| 366 | 510 | if (data & (1<<4)) |
| 367 | 511 | { |
| 368 | 512 | /* parity */ |
| 369 | | uart.receive_char_length++; |
| 513 | uart->receive_char_length++; |
| 370 | 514 | } |
| 371 | 515 | |
| 372 | 516 | /* stop bits */ |
| 373 | | uart.receive_char_length++; |
| 517 | uart->receive_char_length++; |
| 374 | 518 | |
| 375 | | uart.receive_flags &=~MSM8251_TRANSFER_RECEIVE_SYNCHRONISED; |
| 376 | | uart.receive_flags |= MSM8251_TRANSFER_RECEIVE_WAITING_FOR_START_BIT; |
| 519 | uart->receive_flags &=~MSM8251_TRANSFER_RECEIVE_SYNCHRONISED; |
| 520 | uart->receive_flags |= MSM8251_TRANSFER_RECEIVE_WAITING_FOR_START_BIT; |
| 377 | 521 | #endif |
| 378 | 522 | /* not expecting mode byte now */ |
| 379 | | uart.flags &= ~MSM8251_EXPECTING_MODE; |
| 380 | | // uart.status = MSM8251_STATUS_TX_EMPTY | MSM8251_STATUS_TX_READY; |
| 523 | uart->flags &= ~MSM8251_EXPECTING_MODE; |
| 524 | // uart->status = MSM8251_STATUS_TX_EMPTY | MSM8251_STATUS_TX_READY; |
| 381 | 525 | } |
| 382 | 526 | else |
| 383 | 527 | { |
| r3714 | r3715 | |
| 403 | 547 | LOG(("MSM8251: Synchronous operation\n")); |
| 404 | 548 | |
| 405 | 549 | /* setup for sync byte(s) */ |
| 406 | | uart.flags |= MSM8251_EXPECTING_SYNC_BYTE; |
| 407 | | uart.sync_byte_offset = 0; |
| 550 | uart->flags |= MSM8251_EXPECTING_SYNC_BYTE; |
| 551 | uart->sync_byte_offset = 0; |
| 408 | 552 | if (data & 0x07) |
| 409 | 553 | { |
| 410 | | uart.sync_byte_count = 1; |
| 554 | uart->sync_byte_count = 1; |
| 411 | 555 | } |
| 412 | 556 | else |
| 413 | 557 | { |
| 414 | | uart.sync_byte_count = 2; |
| 558 | uart->sync_byte_count = 2; |
| 415 | 559 | } |
| 416 | 560 | |
| 417 | 561 | } |
| r3714 | r3715 | |
| 422 | 566 | /* command */ |
| 423 | 567 | LOG(("MSM8251: Command byte\n")); |
| 424 | 568 | |
| 425 | | uart.command = data; |
| 569 | uart->command = data; |
| 426 | 570 | |
| 427 | 571 | LOG(("Command byte: %02x\n", data)); |
| 428 | 572 | |
| r3714 | r3715 | |
| 494 | 638 | 1 = transmit enable |
| 495 | 639 | */ |
| 496 | 640 | |
| 497 | | uart.connection.State &=~SERIAL_STATE_RTS; |
| 641 | uart->connection.State &=~SERIAL_STATE_RTS; |
| 498 | 642 | if (data & (1<<5)) |
| 499 | 643 | { |
| 500 | 644 | /* rts set to 0 */ |
| 501 | | uart.connection.State |= SERIAL_STATE_RTS; |
| 645 | uart->connection.State |= SERIAL_STATE_RTS; |
| 502 | 646 | } |
| 503 | 647 | |
| 504 | | uart.connection.State &=~SERIAL_STATE_DTR; |
| 648 | uart->connection.State &=~SERIAL_STATE_DTR; |
| 505 | 649 | if (data & (1<<1)) |
| 506 | 650 | { |
| 507 | | uart.connection.State |= SERIAL_STATE_DTR; |
| 651 | uart->connection.State |= SERIAL_STATE_DTR; |
| 508 | 652 | } |
| 509 | 653 | |
| 510 | 654 | if ((data & (1<<0))==0) |
| 511 | 655 | { |
| 512 | 656 | /* held in high state when transmit disable */ |
| 513 | | set_out_data_bit(uart.connection.State,1); |
| 657 | set_out_data_bit(uart->connection.State,1); |
| 514 | 658 | } |
| 515 | 659 | |
| 516 | 660 | |
| 517 | 661 | /* refresh outputs */ |
| 518 | | serial_connection_out(&uart.connection); |
| 662 | serial_connection_out(&uart->connection); |
| 519 | 663 | |
| 520 | 664 | if (data & (1<<4)) |
| 521 | 665 | { |
| 522 | | uart.status &= ~(MSM8251_STATUS_PARITY_ERROR | MSM8251_STATUS_OVERRUN_ERROR | MSM8251_STATUS_FRAMING_ERROR); |
| 666 | uart->status &= ~(MSM8251_STATUS_PARITY_ERROR | MSM8251_STATUS_OVERRUN_ERROR | MSM8251_STATUS_FRAMING_ERROR); |
| 523 | 667 | } |
| 524 | 668 | |
| 525 | 669 | if (data & (1<<6)) |
| 526 | 670 | { |
| 527 | | msm8251_reset(); |
| 671 | device_reset(device); |
| 528 | 672 | } |
| 529 | 673 | |
| 530 | | msm8251_update_rx_ready(); |
| 531 | | msm8251_update_tx_ready(); |
| 674 | msm8251_update_rx_ready(device); |
| 675 | msm8251_update_tx_ready(device); |
| 532 | 676 | |
| 533 | 677 | } |
| 534 | 678 | } |
| 535 | 679 | |
| 536 | | /* read status */ |
| 537 | | READ8_HANDLER(msm8251_status_r) |
| 680 | |
| 681 | |
| 682 | /*------------------------------------------------- |
| 683 | READ8_DEVICE_HANDLER(msm8251_status_r) |
| 684 | -------------------------------------------------*/ |
| 685 | |
| 686 | READ8_DEVICE_HANDLER(msm8251_status_r) |
| 538 | 687 | { |
| 539 | | LOG(("status: %02x\n", uart.status)); |
| 688 | msm8251_t *uart = get_token(device); |
| 540 | 689 | |
| 541 | | return uart.status; |
| 690 | LOG(("status: %02x\n", uart->status)); |
| 691 | return uart->status; |
| 542 | 692 | } |
| 543 | 693 | |
| 544 | | /* write data */ |
| 545 | | WRITE8_HANDLER(msm8251_data_w) |
| 694 | |
| 695 | |
| 696 | /*------------------------------------------------- |
| 697 | WRITE8_DEVICE_HANDLER(msm8251_data_w) |
| 698 | -------------------------------------------------*/ |
| 699 | |
| 700 | WRITE8_DEVICE_HANDLER(msm8251_data_w) |
| 546 | 701 | { |
| 547 | | uart.data = data; |
| 702 | msm8251_t *uart = get_token(device); |
| 548 | 703 | |
| 704 | uart->data = data; |
| 705 | |
| 549 | 706 | logerror("write data: %02x\n",data); |
| 550 | 707 | |
| 551 | 708 | /* writing clears */ |
| 552 | | uart.status &=~MSM8251_STATUS_TX_READY; |
| 709 | uart->status &=~MSM8251_STATUS_TX_READY; |
| 553 | 710 | |
| 554 | 711 | /* if transmitter is active, then tx empty will be signalled */ |
| 555 | 712 | |
| 556 | | msm8251_update_tx_ready(); |
| 713 | msm8251_update_tx_ready(device); |
| 557 | 714 | } |
| 558 | 715 | |
| 559 | | /* called when last bit of data has been received */ |
| 560 | | static void msm8251_receive_character(UINT8 ch) |
| 716 | |
| 717 | |
| 718 | /*------------------------------------------------- |
| 719 | msm8251_receive_character - called when last |
| 720 | bit of data has been received |
| 721 | -------------------------------------------------*/ |
| 722 | |
| 723 | static void msm8251_receive_character(const device_config *device, UINT8 ch) |
| 561 | 724 | { |
| 725 | msm8251_t *uart = get_token(device); |
| 726 | |
| 562 | 727 | logerror("msm8251 receive char: %02x\n",ch); |
| 563 | 728 | |
| 564 | | uart.data = ch; |
| 729 | uart->data = ch; |
| 565 | 730 | |
| 566 | 731 | /* char has not been read and another has arrived! */ |
| 567 | | if (uart.status & MSM8251_STATUS_RX_READY) |
| 732 | if (uart->status & MSM8251_STATUS_RX_READY) |
| 568 | 733 | { |
| 569 | | uart.status |= MSM8251_STATUS_OVERRUN_ERROR; |
| 734 | uart->status |= MSM8251_STATUS_OVERRUN_ERROR; |
| 570 | 735 | } |
| 571 | | uart.status |= MSM8251_STATUS_RX_READY; |
| 736 | uart->status |= MSM8251_STATUS_RX_READY; |
| 572 | 737 | |
| 573 | | msm8251_update_rx_ready(); |
| 738 | msm8251_update_rx_ready(device); |
| 574 | 739 | } |
| 575 | 740 | |
| 576 | | /* read data */ |
| 577 | | READ8_HANDLER(msm8251_data_r) |
| 741 | |
| 742 | |
| 743 | /*------------------------------------------------- |
| 744 | READ8_DEVICE_HANDLER(msm8251_data_r) - read data |
| 745 | -------------------------------------------------*/ |
| 746 | |
| 747 | READ8_DEVICE_HANDLER(msm8251_data_r) |
| 578 | 748 | { |
| 579 | | logerror("read data: %02x\n",uart.data); |
| 749 | msm8251_t *uart = get_token(device); |
| 750 | |
| 751 | logerror("read data: %02x\n",uart->data); |
| 580 | 752 | /* reading clears */ |
| 581 | | uart.status &= ~MSM8251_STATUS_RX_READY; |
| 753 | uart->status &= ~MSM8251_STATUS_RX_READY; |
| 582 | 754 | |
| 583 | | msm8251_update_rx_ready(); |
| 584 | | return uart.data; |
| 755 | msm8251_update_rx_ready(device); |
| 756 | return uart->data; |
| 585 | 757 | } |
| 586 | 758 | |
| 587 | | /* initialise transfer using serial device - set the callback which will |
| 588 | | be called when serial device has updated it's state */ |
| 589 | | void msm8251_connect_to_serial_device(const device_config *image) |
| 759 | |
| 760 | |
| 761 | /*------------------------------------------------- |
| 762 | msm8251_connect_to_serial_device - initialise |
| 763 | transfer using serial device - set the callback |
| 764 | which will be called when serial device has |
| 765 | updated it's state |
| 766 | -------------------------------------------------*/ |
| 767 | |
| 768 | void msm8251_connect_to_serial_device(const device_config *device, const device_config *image) |
| 590 | 769 | { |
| 591 | | serial_device_connect(image, &uart.connection); |
| 770 | msm8251_t *uart = get_token(device); |
| 771 | serial_device_connect(image, &uart->connection); |
| 592 | 772 | } |
| 593 | 773 | |
| 594 | | void msm8251_connect(struct serial_connection *other_connection) |
| 774 | |
| 775 | |
| 776 | /*------------------------------------------------- |
| 777 | msm8251_connect |
| 778 | -------------------------------------------------*/ |
| 779 | |
| 780 | void msm8251_connect(const device_config *device, struct serial_connection *other_connection) |
| 595 | 781 | { |
| 596 | | serial_connection_link(&uart.connection, other_connection); |
| 782 | msm8251_t *uart = get_token(device); |
| 783 | serial_connection_link(&uart->connection, other_connection); |
| 597 | 784 | } |
| 598 | 785 | |
| 786 | |
| 787 | /*------------------------------------------------- |
| 788 | DEVICE_SET_INFO( msm8251 ) |
| 789 | -------------------------------------------------*/ |
| 790 | |
| 791 | static DEVICE_SET_INFO( msm8251 ) |
| 792 | { |
| 793 | switch (state) |
| 794 | { |
| 795 | /* no parameters to set */ |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | |
| 800 | |
| 801 | /*------------------------------------------------- |
| 802 | DEVICE_GET_INFO( msm8251 ) |
| 803 | -------------------------------------------------*/ |
| 804 | |
| 805 | DEVICE_GET_INFO( msm8251 ) |
| 806 | { |
| 807 | switch (state) |
| 808 | { |
| 809 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 810 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(msm8251_t); break; |
| 811 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 812 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 813 | |
| 814 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 815 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(msm8251); break; |
| 816 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(msm8251); break; |
| 817 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 818 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(msm8251); break; |
| 819 | |
| 820 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 821 | case DEVINFO_STR_NAME: info->s = "Intel 8251 UART"; break; |
| 822 | case DEVINFO_STR_FAMILY: info->s = "Intel 8251 UART"; break; |
| 823 | case DEVINFO_STR_VERSION: info->s = "1.0"; break; |
| 824 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 825 | case DEVINFO_STR_CREDITS: /* Nothing */ break; |
| 826 | } |
| 827 | } |
src/mess/drivers/nc.c
| r3714 | r3715 | |
| 784 | 784 | |
| 785 | 785 | static TIMER_CALLBACK(nc_serial_timer_callback) |
| 786 | 786 | { |
| 787 | | msm8251_transmit_clock(); |
| 788 | | msm8251_receive_clock(); |
| 787 | const device_config *uart = device_list_find_by_tag(machine->config->devicelist, MSM8251, "uart"); |
| 788 | |
| 789 | msm8251_transmit_clock(uart); |
| 790 | msm8251_receive_clock(uart); |
| 789 | 791 | } |
| 790 | 792 | |
| 791 | 793 | static WRITE8_HANDLER(nc_uart_control_w) |
| r3714 | r3715 | |
| 799 | 801 | /* changed uart from off to on */ |
| 800 | 802 | if ((data & (1<<3))==0) |
| 801 | 803 | { |
| 802 | | msm8251_reset(); |
| 804 | devtag_reset(space->machine, MSM8251, "uart"); |
| 803 | 805 | } |
| 804 | 806 | } |
| 805 | 807 | |
| r3714 | r3715 | |
| 887 | 889 | previous_alarm_state = state; |
| 888 | 890 | } |
| 889 | 891 | |
| 890 | | static void nc100_txrdy_callback(int state) |
| 892 | static void nc100_txrdy_callback(const device_config *device, int state) |
| 891 | 893 | { |
| 892 | 894 | nc_irq_latch &= ~(1<<1); |
| 893 | 895 | |
| r3714 | r3715 | |
| 901 | 903 | } |
| 902 | 904 | } |
| 903 | 905 | |
| 904 | | nc_update_interrupts(Machine); |
| 906 | nc_update_interrupts(device->machine); |
| 905 | 907 | } |
| 906 | 908 | |
| 907 | | static void nc100_rxrdy_callback(int state) |
| 909 | static void nc100_rxrdy_callback(const device_config *device, int state) |
| 908 | 910 | { |
| 909 | 911 | nc_irq_latch &= ~(1<<0); |
| 910 | 912 | |
| r3714 | r3715 | |
| 917 | 919 | } |
| 918 | 920 | } |
| 919 | 921 | |
| 920 | | nc_update_interrupts(Machine); |
| 922 | nc_update_interrupts(device->machine); |
| 921 | 923 | } |
| 922 | 924 | |
| 923 | 925 | |
| r3714 | r3715 | |
| 926 | 928 | nc100_tc8521_alarm_callback, |
| 927 | 929 | }; |
| 928 | 930 | |
| 929 | | static const struct msm8251_interface nc100_uart_interface= |
| 931 | static const msm8251_interface nc100_uart_interface= |
| 930 | 932 | { |
| 931 | 933 | nc100_txrdy_callback, |
| 932 | 934 | NULL, |
| r3714 | r3715 | |
| 968 | 970 | |
| 969 | 971 | tc8521_init(&nc100_tc8521_interface); |
| 970 | 972 | |
| 971 | | msm8251_init(&nc100_uart_interface); |
| 972 | | |
| 973 | 973 | centronics_config(0, nc100_cent_config); |
| 974 | 974 | /* assumption: select is tied low */ |
| 975 | 975 | centronics_write_handshake(0, CENTRONICS_SELECT | CENTRONICS_NO_RESET, CENTRONICS_SELECT| CENTRONICS_NO_RESET); |
| r3714 | r3715 | |
| 1080 | 1080 | AM_RANGE(0x91, 0x9f) AM_READ(nc_irq_status_r) |
| 1081 | 1081 | AM_RANGE(0xa0, 0xaf) AM_READ(nc100_card_battery_status_r) |
| 1082 | 1082 | AM_RANGE(0xb0, 0xb9) AM_READ(nc_key_data_in_r) |
| 1083 | | AM_RANGE(0xc0, 0xc0) AM_READWRITE(msm8251_data_r, msm8251_data_w) |
| 1084 | | AM_RANGE(0xc1, 0xc1) AM_READWRITE(msm8251_status_r, msm8251_control_w) |
| 1083 | AM_RANGE(0xc0, 0xc0) AM_DEVREADWRITE(MSM8251, "uart", msm8251_data_r, msm8251_data_w) |
| 1084 | AM_RANGE(0xc1, 0xc1) AM_DEVREADWRITE(MSM8251, "uart", msm8251_status_r, msm8251_control_w) |
| 1085 | 1085 | AM_RANGE(0xd0, 0xdf) AM_READWRITE(tc8521_r, tc8521_w) |
| 1086 | 1086 | ADDRESS_MAP_END |
| 1087 | 1087 | |
| r3714 | r3715 | |
| 1285 | 1285 | nc_update_interrupts(machine); |
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | | static void nc200_txrdy_callback(int state) |
| 1288 | static void nc200_txrdy_callback(const device_config *device, int state) |
| 1289 | 1289 | { |
| 1290 | 1290 | // nc200_uart_interrupt_irq &=~(1<<0); |
| 1291 | 1291 | // |
| r3714 | r3715 | |
| 1297 | 1297 | // nc200_refresh_uart_interrupt(Machine); |
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | | static void nc200_rxrdy_callback(int state) |
| 1300 | static void nc200_rxrdy_callback(const device_config *device, int state) |
| 1301 | 1301 | { |
| 1302 | 1302 | nc200_uart_interrupt_irq &=~(1<<1); |
| 1303 | 1303 | |
| r3714 | r3715 | |
| 1306 | 1306 | nc200_uart_interrupt_irq |=(1<<1); |
| 1307 | 1307 | } |
| 1308 | 1308 | |
| 1309 | | nc200_refresh_uart_interrupt(Machine); |
| 1309 | nc200_refresh_uart_interrupt(device->machine); |
| 1310 | 1310 | } |
| 1311 | 1311 | |
| 1312 | | static const struct msm8251_interface nc200_uart_interface= |
| 1312 | static const msm8251_interface nc200_uart_interface= |
| 1313 | 1313 | { |
| 1314 | 1314 | nc200_rxrdy_callback, |
| 1315 | 1315 | NULL, |
| r3714 | r3715 | |
| 1372 | 1372 | mc146818_init(machine, MC146818_STANDARD); |
| 1373 | 1373 | |
| 1374 | 1374 | nc200_uart_interrupt_irq = 0; |
| 1375 | | msm8251_init(&nc200_uart_interface); |
| 1376 | 1375 | |
| 1377 | 1376 | centronics_config(0, nc200_cent_config); |
| 1378 | 1377 | /* assumption: select is tied low */ |
| r3714 | r3715 | |
| 1547 | 1546 | AM_RANGE(0x90, 0x90) AM_READWRITE(nc_irq_status_r, nc_irq_status_w) |
| 1548 | 1547 | AM_RANGE(0xa0, 0xa0) AM_READ(nc200_card_battery_status_r) |
| 1549 | 1548 | AM_RANGE(0xb0, 0xb9) AM_READ(nc_key_data_in_r) |
| 1550 | | AM_RANGE(0xc0, 0xc0) AM_READWRITE(msm8251_data_r, msm8251_data_w) |
| 1551 | | AM_RANGE(0xc1, 0xc1) AM_READWRITE(msm8251_status_r, msm8251_control_w) |
| 1549 | AM_RANGE(0xc0, 0xc0) AM_DEVREADWRITE(MSM8251, "uart", msm8251_data_r, msm8251_data_w) |
| 1550 | AM_RANGE(0xc1, 0xc1) AM_DEVREADWRITE(MSM8251, "uart", msm8251_status_r, msm8251_control_w) |
| 1552 | 1551 | AM_RANGE(0xd0, 0xd1) AM_READWRITE(mc146818_port_r, mc146818_port_w) |
| 1553 | 1552 | AM_RANGE(0xe0, 0xe0) AM_READ(nec765_status_r) |
| 1554 | 1553 | AM_RANGE(0xe1, 0xe1) AM_READWRITE(nec765_data_r, nec765_data_w) |
| r3714 | r3715 | |
| 1701 | 1700 | |
| 1702 | 1701 | /* printer */ |
| 1703 | 1702 | MDRV_DEVICE_ADD("printer", PRINTER) |
| 1703 | |
| 1704 | /* uart */ |
| 1705 | MDRV_DEVICE_ADD("uart", MSM8251) |
| 1706 | MDRV_DEVICE_CONFIG(nc100_uart_interface) |
| 1704 | 1707 | MACHINE_DRIVER_END |
| 1705 | 1708 | |
| 1706 | 1709 | |
| 1707 | 1710 | static MACHINE_DRIVER_START( nc200 ) |
| 1708 | 1711 | MDRV_IMPORT_FROM( nc100 ) |
| 1712 | |
| 1709 | 1713 | MDRV_CPU_MODIFY( "main" ) |
| 1710 | 1714 | MDRV_CPU_IO_MAP(nc200_io, 0) |
| 1711 | 1715 | |
| r3714 | r3715 | |
| 1718 | 1722 | MDRV_SCREEN_VISIBLE_AREA(0, NC200_SCREEN_WIDTH-1, 0, NC200_SCREEN_HEIGHT-1) |
| 1719 | 1723 | MDRV_PALETTE_LENGTH(NC200_NUM_COLOURS) |
| 1720 | 1724 | MDRV_DEFAULT_LAYOUT(layout_nc200) |
| 1725 | |
| 1726 | /* uart */ |
| 1727 | MDRV_DEVICE_MODIFY("uart", MSM8251) |
| 1728 | MDRV_DEVICE_CONFIG(nc200_uart_interface) |
| 1721 | 1729 | MACHINE_DRIVER_END |
| 1722 | 1730 | |
| 1723 | 1731 | |