
void UART1Handler (void) __irq
{
u08 iid;
// loop until not more interrupt sources
while (((iid = U1IIR) & UIIR_NO_INT) == 0)
{
// identify & process the highest priority interrupt
switch (iid & UIIR_ID_MASK)
{
case UIIR_RLS_INT: // Receive Line Status
U1LSR; // read LSR to clear
break;
case UIIR_CTI_INT: // Character Timeout Indicator
case UIIR_RDA_INT: // Receive Data Available
do
{
// calc next insert index & store character
utemp1 = (uart1_rx_insert_idx + 1) % UART1_RX_BUFFER_SIZE;
uart1_rx_buffer[uart1_rx_insert_idx] = U1RBR;
// check for more room in queue
if (utemp1 != uart1_rx_extract_idx)
uart1_rx_insert_idx = utemp1; // update insert index
}
while (U1LSR & ULSR_RDR);
break;
case UIIR_THRE_INT: // Transmit Holding Register Empty
while (U1LSR & ULSR_THRE)
{
// check if more data to send
if (uart1_tx_insert_idx != uart1_tx_extract_idx)
{
U1THR = uart1_tx_buffer[uart1_tx_extract_idx++];
uart1_tx_extract_idx %= UART1_TX_BUFFER_SIZE;
}
else
{
// no
uart1_tx_running = 0; // clear running flag
break;
}
}
break;
default: // Unknown
U1LSR;
U1RBR;
U1MSR;
break;
}
}
VICVectAddr = 0; /* Acknowledge Interrupt */
}