zynq的串口中断不能触发问题

2020-01-30 16:32发布

zynq板,想用串口接收中断,但是完全没反应,发送的字符可以接收,但就是没有触发中断,用过串口中断的帮忙看看,是uart初始化有问题,还是gic初始化有问题啊,急


#include "../inc/UartInit.h"

static void UartInterruptHandler(void);
static int GIC_Init(void);

XUartPs UartPs;
XScuGic ScuGic;

char rec;
int Uart_Init(void)
{
        int Status;
        u32 u32RegBaseAddress;
        XUartPs_Config *ConfigPtr;

        ConfigPtr = XUartPs_LookupConfig(XPAR_PS7_UART_1_DEVICE_ID);
        if (ConfigPtr == (XUartPs_Config *)NULL)
    {
                return XST_DEVICE_NOT_FOUND;
        }
        u32RegBaseAddress = ConfigPtr->BaseAddress;//
        XUartPs_CfgInitialize(&UartPs, ConfigPtr, ConfigPtr->BaseAddress);  //初始化
//        XUartPs_SetHandler(&UartPs, (XUartPs_Handler)UartInterruptHandler, (void *)0);
        Status = GIC_Init();   //配置GIC
        if (Status != XST_SUCCESS)
    {
                return XST_FAILURE;
        }
        XUartPs_WriteReg(u32RegBaseAddress, XUARTPS_RXWM_OFFSET, 1);

        XUartPs_WriteReg(u32RegBaseAddress, XUARTPS_IER_OFFSET, XUARTPS_IXR_RXFULL|XUARTPS_IXR_RXOVR);     //允许接收中断
        XUartPs_WriteReg(u32RegBaseAddress, XUARTPS_IDR_OFFSET, ~(XUARTPS_IXR_RXFULL|XUARTPS_IXR_RXOVR));  //允许接收中断

        XUartPs_SetBaudRate(&UartPs, UART_BAUDRATE);                              //设置波特率
        XUartPs_WriteReg(u32RegBaseAddress, XUARTPS_MR_OFFSET, 0x20);
        XUartPs_WriteReg(u32RegBaseAddress, XUARTPS_CR_OFFSET, 0x17);


        printf("0x%x ",XUartPs_ReadReg(u32RegBaseAddress, XUARTPS_IMR_OFFSET));

        return XST_SUCCESS;
}

static int GIC_Init(void)
{
        int Status;

        XScuGic_Config * ConfigPtr;

        ConfigPtr = XScuGic_LookupConfig(XPAR_SCUGIC_0_DEVICE_ID);

        Status = XScuGic_CfgInitialize(&ScuGic, ConfigPtr, ConfigPtr->CpuBaseAddress);
        if (Status != XST_SUCCESS)
    {
                return XST_FAILURE;
        }
        XScuGic_Disable(&ScuGic, UART1_IRQ_ID);

        XScuGic_SetPriorityTriggerType(&ScuGic, UART1_IRQ_ID, 0x2, 0x1);  //设置优先级和触发类型
        XScuGic_Connect (&ScuGic, UART1_IRQ_ID, (Xil_InterruptHandler)UartInterruptHandler, (void *)0);
        if (Status != XST_SUCCESS)
    {
                return XST_FAILURE;
        }

        XScuGic_Enable(&ScuGic, UART1_IRQ_ID);                //允许串口中断

        Xil_ExceptionInit();

        Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XScuGic_InterruptHandler, &ScuGic);

        Xil_ExceptionEnable();

        return XST_SUCCESS;
}

static void UartInterruptHandler(void)
{
    volatile u8 StatusRegister;

    u32 u32RegBaseAddress;

    u32RegBaseAddress = UartPs.Config.BaseAddress;

        XUartPs_WriteReg(u32RegBaseAddress, XUARTPS_ISR_OFFSET, 0xffffffff);

    StatusRegister = XUartPs_ReadReg(u32RegBaseAddress, XUARTPS_ISR_OFFSET);
        /* enable Tx/Rx and reset Tx/Rx data path */


    while(StatusRegister & (XUARTPS_SR_RXFULL | XUARTPS_SR_RXOVR))//接收
    {
        if(StatusRegister & (XUARTPS_SR_RXFULL | XUARTPS_SR_RXOVR))
        {
                rec = XUartPs_ReadReg(u32RegBaseAddress, XUARTPS_FIFO_OFFSET);
            }
    }

}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。