0
votes

Take UART as an example.

When UART received data, the UART device(chip) generates an interrupt, the SW interrupt handler will process this interrupt, ex: read data from HW buffer. This part is reasonable.

For TX case, will OS/driver generate an interrupt to the device (UART chip) to let UART chip know there are some data need to send out?

3
This is probably too broad for SO (or perhaps even off topic for SO). Anyway - I have never heard about a UART that gets an interrupt from OS/driver. AFAIK the interrupts are generated by the UART - they are not received by the UART. When the driver wants to send data it writes the data to the UART (to a tx-buffer of some kind). The UART may generate an interrupt when the data has been transmitted so that the driver can write the next chunk of data to the UART.4386427
You may find this interresting: electronics.stackexchange.com/questions/270743/…4386427

3 Answers

0
votes

A typical way to handle UART input goes a bit further than you say:

When data has been received the UART generates a HW interrupt and the interrupt handler reads the data from UART and places it in a FIFO buffer, often a circular buffer.

At the higher level when the OS wants to receive data it looks at the input buffer to see if there is any data there.

This mechanism provides another layer of asynchronicity and it means that the input data flow control need only block the remote transmitter when the receiver's input buffer is (nearly) full.


output

The UART generates a HW interrupt when it is ready to transmit data. The interrupt handler will then look at the FIFO output buffer and place the first item in the queue in the UART's transmit register. Otherwise if there is no data waiting to be transmitted the interrupt status is cleared.

At the higher level when the OS wants to transmit data it places the item in the output buffer and ensures that the UART will generate a HW interrupt when it is ready to transmit, which may be straight away.

This means that the output data flow is only blocked when the output buffer is full.


0
votes

Device generate hardware interrupts not OS-es or drivers.

Generally communication hardware generate interrupts when:

  1. It has got some data
  2. It is ready to send data
  3. It is in error condition.
  4. It has ended the commucication (especially important for hardware with internal buffers like FIFOs)

If hardware uses DMA you may have another interrupts as well

  1. End of DMA transaction
  2. Half of the transaction
  3. DMA error
0
votes

To put things easier, here I check Linux 1.0 as the code base.

static void rs_stop(struct tty_struct *tty)
{
...
info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI; 
// you can see UART_IER_THRI is not here, the TX interrupt was disabled.
...
}

static void rs_start(struct tty_struct *tty)
{
    info->IER = (UART_IER_MSI | UART_IER_RLSI |
         UART_IER_THRI | UART_IER_RDI);
  // THRI is enabled here.
}