lpc176x移植包串口接收没有错误处理,导致接收数据出错时中断无法清除。参照官方例程改动如下:
//
t-threadsplpc176xuart.c
void UART0_IRQHandler(void)
{
rt_ubase_t level, iir;
struct rt_uart_lpc* uart = &uart_device;
/* read IIR and clear it */
iir = LPC_UART->IIR;
iir >>= 1; /* skip pending bit in IIR */
iir &= 0x07; /* check bit 1~3, interrupt identification */
if (( iir == IIR_RLS && (LPC_UART0->LSR & LSR_RDR) ) || iir == IIR_RDA) /* Receive Data Available */
{
/* Receive Data Available */
uart->rx_buffer[uart->save_index] = LPC_UART->RBR;
level = rt_hw_interrupt_disable();
uart->save_index ++;
if (uart->save_index >= RT_UART_RX_BUFFER_SIZE)
uart->save_index = 0;
rt_hw_interrupt_enable(level);
/* invoke callback */
if(uart->parent.rx_indicate != RT_NULL)
{
rt_size_t length;
if (uart->read_index > uart->save_index)
length = RT_UART_RX_BUFFER_SIZE - uart->read_index + uart->save_index;
else
length = uart->save_index - uart->read_index;
uart->parent.rx_indicate(&uart->parent, length);
}
}
else if ( iir == IIR_RLS && (LPC_UART0->LSR & (LSR_OE|LSR_PE|LSR_FE|LSR_RXFE|LSR_BI)) )
{
uart->rx_buffer[uart->save_index] = LPC_UART->RBR; /*Dummy read on RX to clear interrupt*/
}
return;
}