/*********************************************************************//** * @brief UART0 interrupt handler sub-routine * @param[in] None * @return None **********************************************************************/ void UART0_IRQHandler(void) { uint32_t intsrc, tmp, tmp1; /* Determine the interrupt source */ intsrc = UART_GetIntId(LPC_UART0); tmp = intsrc & UART_IIR_INTID_MASK; // Receive Line Status if (tmp == UART_IIR_INTID_RLS){ // Check line status tmp1 = UART_GetLineStatus(LPC_UART0); // Mask out the Receive Ready and Transmit Holding empty status tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \ | UART_LSR_BI | UART_LSR_RXFE); // If any error exist if (tmp1) { UART_IntErr(tmp1); } } // Receive Data Available or Character time-out if ((tmp == UART_IIR_INTID_RDA) || (tmp == UART_IIR_INTID_CTI)){ UART_IntReceive(); } // Transmit Holding Empty if (tmp == UART_IIR_INTID_THRE){ UART_IntTransmit(); } }
/*********************************************************************//** * @brief UART transmit function for interrupt mode (using ring buffers) * @param[in] UARTPort Selected UART peripheral used to send data, * should be UART0 * @param[out] txbuf Pointer to Transmit buffer * @param[in] buflen Length of Transmit buffer * @return Number of bytes actually sent to the ring buffer **********************************************************************/ static uint32_t UARTSend(LPC_UART_TypeDef *UARTPort, uint8_t txbuf[], uint8_t buflen) { uint8_t* data = &txbuf[0]; uint32_t bytes = 0; /* Temporarily lock out UART transmit interrupts during this read so the UART transmit interrupt won't cause problems with the index values */ UART_IntConfig(UARTPort, UART_INTCFG_THRE, DISABLE); /* Loop until transmit run buffer is full or until n_bytes expires */ while ((buflen > 0) && (!__BUF_IS_FULL(rb.tx_head, rb.tx_tail))) { /* Write data from buffer into ring buffer */ rb.tx[rb.tx_head] = *data; data++; /* Increment head pointer */ __BUF_INCR(rb.tx_head); /* Increment data count and decrement buffer size count */ bytes++; buflen--; } /* * Check if current Tx interrupt enable is reset, * that means the Tx interrupt must be re-enabled * due to call UART_IntTransmit() function to trigger * this interrupt type */ if (TxIntStat == RESET) { UART_IntTransmit(); } /* * Otherwise, re-enables Tx Interrupt */ else { UART_IntConfig(UARTPort, UART_INTCFG_THRE, ENABLE); } return bytes; }
void Uart_X_Isr(int which_port) { uint32_t intsrc, tmp, tmp1; LPC_UART_TypeDef *UARTx; UARTx=(LPC_UART_TypeDef *)uartDrvDataArray[which_port].reg_base; /* Determine the interrupt source */ intsrc = UART_GetIntId(UARTx); tmp = intsrc & UART_IIR_INTID_MASK; // Receive Line Status if (tmp == UART_IIR_INTID_RLS){ // Check line status tmp1 = UART_GetLineStatus(UARTx); // Mask out the Receive Ready and Transmit Holding empty status tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \ | UART_LSR_BI | UART_LSR_RXFE); // If any error exist if (tmp1) { UART_IntErr(tmp1); } } // Receive Data Available or Character time-out if ((tmp == UART_IIR_INTID_RDA) || (tmp == UART_IIR_INTID_CTI)){ UART_IntReceive(which_port); } // Transmit Holding Empty if (tmp == UART_IIR_INTID_THRE){ #if 0 UART_IntTransmit(); #else innerDeadNoOutput(); #endif } }