FGPA_Microblaze UART 中断

由于底层所给函数发送与接收都采用中断,所用库函数比较复杂 ,有些更改涉及底层函数,因此结合网上论坛 、百度文库调试了串口中断接收程序。通过串口调试助手发送数据 ,以“发送新行”结束 。 硬件外设波特兰:115200;停止位:1数据位:8;奇偶校验:无

    #include "xuratlite.h"
    #include "xuarttlite_h.h"
    #include "xparameters.h"
    #include "xintc.h"
    #define USART_REC_LEN   100
    XUartLite UartLite;
    typedef struct
    {
            u8 Position;
            u8 ReceiveBuffer[USART_REC_LEN];
    }RingBuff_t;
    RingBuff_t buffer;

    void uart_init(void)
    {
            `XUartLite_Initialize(&UartLite,XPAR_UARTLITE_0_DEVICE_ID);  
            microblaze_enable_interrrupts();
            XUartLite_EnableInterrupt(&UartLite);
            XIntc_RegisterHandler(XPAR_INTC_0_BASEADDR,\
            XPAR_AXI_INTC_0_AXI_UARTLITE_0_INTERRUPT_INTR,\
            (XInterruptHandler)uart_rx_Handler,\
            (void *)0);
            XIntc_MasterEnable(XPAR_INTC_0_BASEADDR);
            XIntc_EnableIntr(XPAR_INTC_0_BASEADDR,\
                            XPAR_AXI_UARTLITE_0_INTERRUPT_MASK);
    }
void uart_rx_Handler(void)
{
    while(1)
    {
            if(!XUartLite_IsReceiveEmpty(XPAR_AXI_UARTLITE_0_BASEADDR))
            {
                        buffer.ReceiveBuffer[buffer.Position]=\
                                XUartLite_RecvByte(XPAR_AXI_UARTLITE_0_BASEADDR);
                        //XUartLite_SendByte(XPAR_AXI_UARTLITE_0_BASEADDR,\
                                  buffer.ReceiveBuffer[buffer.Position]);
            }
            if(buffer.ReceiveBuffer[(buffer.Position)-1] ==0x0A)
            {
                        buffer.Position = 0;
                        break;
             }
    }
}

 




posted on 2020-03-31 17:04  Windy‘s技术博客  阅读(1246)  评论(0)    收藏  举报

导航