/*! Sends BYTE to the serial port. */ void serial_putc(uint8_t byte) { enum intr_level old_level = intr_disable(); if (mode != QUEUE) { /* If we're not set up for interrupt-driven I/O yet, use dumb polling to transmit a byte. */ if (mode == UNINIT) init_poll(); putc_poll(byte); } else { /* Otherwise, queue a byte and update the interrupt enable register. */ if (old_level == INTR_OFF && intq_full(&txq)) { /* Interrupts are off and the transmit queue is full. If we wanted to wait for the queue to empty, we'd have to reenable interrupts. That's impolite, so we'll send a character via polling instead. */ putc_poll(intq_getc (&txq)); } intq_putc(&txq, byte); write_ier(); } intr_set_level(old_level); }
/* Flushes anything in the serial buffer out the port in polling mode. */ void serial_flush(void) { unsigned old_level = int_intr_disable(); while (!cyb_isempty(txq)) putc_poll(cyb_getc(txq)); int_intr_setlevel(old_level); }
/* Sends BYTE to the serial port. */ void serial_putc(unsigned char byte) { unsigned old_level = int_intr_disable(); if (mode != QUEUE) { /* If we're not set up for interrupt-driven I/O yet, use dumb polling to transmit a byte. */ if (mode == UNINIT) init_poll(); putc_poll(byte); } else { /* Otherwise, queue a byte and update the interrupt enable register. */ if (old_level == 0 && cyb_isfull(txq)) { /* Interrupts are off and the transmit queue is full. If we wanted to wait for the queue to empty, we'd have to reenable interrupts. That's impolite, so we'll send a character via polling instead. */ putc_poll(cyb_getc(txq)); } if (byte == '\n') { cyb_putc(txq, '\r'); } cyb_putc(txq, byte); write_ier(); } int_intr_setlevel(old_level); }
/*! Flushes anything in the serial buffer out the port in polling mode. */ void serial_flush(void) { enum intr_level old_level = intr_disable(); while (!intq_empty(&txq)) putc_poll(intq_getc(&txq)); intr_set_level(old_level); }