--- trunk/src/devices/dev_ns16550.c 2007/10/08 16:19:37 22 +++ trunk/src/devices/dev_ns16550.c 2007/10/08 16:20:58 32 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: dev_ns16550.c,v 1.51 2006/02/18 13:42:39 debug Exp $ + * $Id: dev_ns16550.c,v 1.55 2006/10/27 13:12:21 debug Exp $ * * NS16550 serial controller. * @@ -72,15 +72,13 @@ }; -/* - * dev_ns16550_tick(): - * - * This function is called at regular intervals. An interrupt is caused to the - * CPU if there is a character available for reading, or if the transmitter - * slot is empty (i.e. the ns16550 is ready to transmit). - */ -void dev_ns16550_tick(struct cpu *cpu, void *extra) +DEVICE_TICK(ns16550) { + /* + * This function is called at regular intervals. An interrupt is + * asserted if there is a character available for reading, or if the + * transmitter slot is empty (i.e. the ns16550 is ready to transmit). + */ struct ns_data *d = extra; d->reg[com_iir] &= ~IIR_RXRDY; @@ -91,6 +89,7 @@ * If interrupts are enabled, and interrupts are pending, then * cause a CPU interrupt. */ + if (((d->reg[com_ier] & IER_ETXRDY) && (d->reg[com_iir] & IIR_TXRDY)) || ((d->reg[com_ier] & IER_ERXRDY) && (d->reg[com_iir] & IIR_RXRDY))) { d->reg[com_iir] &= ~IIR_NOPEND; @@ -214,6 +213,8 @@ d->fcr = idata; } else { odata = d->reg[com_iir]; + if (d->reg[com_iir] & IIR_TXRDY) + d->reg[com_iir] &= ~IIR_TXRDY; debug("[ ns16550 (%s): read from iir: 0x%02x ]\n", d->name, (int)odata); dev_ns16550_tick(cpu, d); @@ -287,6 +288,10 @@ d->reg[com_mcr] = idata; debug("[ ns16550 (%s): write to mcr: 0x%02x ]\n", d->name, (int)idata); + if (!(d->reg[com_iir] & IIR_TXRDY) + && (idata & MCR_IENABLE)) + d->reg[com_iir] |= IIR_TXRDY; + dev_ns16550_tick(cpu, d); } else { odata = d->reg[com_mcr]; debug("[ ns16550 (%s): read from mcr: 0x%02x ]\n", @@ -358,7 +363,7 @@ DEV_NS16550_LENGTH * d->addrmult, dev_ns16550_access, d, DM_DEFAULT, NULL); machine_add_tickfunction(devinit->machine, - dev_ns16550_tick, d, TICK_SHIFT); + dev_ns16550_tick, d, TICK_SHIFT, 0.0); /* * NOTE: Ugly cast into a pointer, because this is a convenient way