cdlxzlp520 发表于 2013-7-18 12:20
哈哈 不错 有代码看吗?? static __inline void _uart_isr(uint8_t port,struct _uart_fifo_t *pfifo,USART_TypeDef *uart)
{
uint32_t iflag;
uint32_t event = 0;
uint8_t read;
iflag = (uart->CR1 & uart->SR);//(USART_FLAG_TXE|USART_FLAG_TC|USART_FLAG_RXNE|USART_FLAG_IDLE)
//IDLE IRQ
if(iflag & USART_FLAG_IDLE)
{
read = uart->DR;
if(pfifo->rxCnt <= (pfifo->rxSize>>1)) //rx buffer is not full when rx idle happen
{
event |= UART_RX_DONE;
}
}
//RX IRQ
if(iflag & USART_FLAG_RXNE)
{
read = uart->DR;
if(pfifo->rxCnt < pfifo->rxSize)
{
pfifo->rxBuf[pfifo->rxPush] = read;
pfifo->rxPush += 1;
if(pfifo->rxPush >= pfifo->rxSize)
{
pfifo->rxPush = 0;
}
pfifo->rxCnt += 1;
if(pfifo->rxCnt == pfifo->rxSize) //rx buffer is full
{
event |= UART_RX_FULL;
}
else if(pfifo->rxCnt > (pfifo->rxSize>>1))//rx byte is more than half of rx buffer
{
event |= UART_RX_HALF;
}
}
}
//TXE IRQ
if(iflag & USART_FLAG_TXE)
{
uart->CR1 &= (uint16_t)~0x0080; //off TX
if(pfifo->txCnt)
{
uart->DR = pfifo->txBuf[pfifo->txPop];
uart->CR1 |= (uint16_t)0x0080;
pfifo->txPop += 1;
if(pfifo->txPop >= pfifo->txSize)
{
pfifo->txPop = 0;
}
pfifo->txCnt -= 1;
if(pfifo->txCnt == 0)
{
event |= UART_TX_DONE;
}
}
}
//run isr function
if((pfifo->isr) && (event))
{
event |= (uint8_t)port<<8 ;
pfifo->isr(event,pfifo->msg);
}
}
|