我用了PS端的UART0,实现它的数据环回,测试是可以的;然后再增加了UARTLITE IP核,也是实现它的数据环回,测试也是正常的。把两部分代码合在一起,先用串口助手向UART0发送数据,它是能实现数据回环的,然后再用串口助手向UARTLITE对应的串口发送数据,它也是能实现数据环回,但是这时我再向UART0发送数据,它就没响应了?这是为什么阿?有没有佬指点下
int main(void)
{
int status;
status = uart_init(&Uart0_Ps,UART0_DEVICE_ID); //串口初始化
if (status == XST_FAILURE) {
xil_printf("Uart Initial Failed\r\n");
return XST_FAILURE;
}
XUartLite_Initialize(&Uartlite,XPAR_UARTLITE_0_DEVICE_ID);
uart_intr_init(&Intc, &Uart0_Ps); //串口中断初始化
setup_interrupt_uartlite(&Intc, &Uartlite, UARTLITE_INT_IRQ_ID);
while (1){
};
return 0;
}
//串口0中断处理函数
void uart0_intr_handler(void *call_back_ref)
{
XUartPs *uart_instance_ptr = (XUartPs *) call_back_ref;
u8 rec_data = 0 ;
u32 isr_status ; //中断状态标志
//读取中断ID寄存器,判断触发的是哪种中断
isr_status = XUartPs_ReadReg(uart_instance_ptr->Config.BaseAddress,
XUARTPS_IMR_OFFSET);
isr_status &= XUartPs_ReadReg(uart_instance_ptr->Config.BaseAddress,
XUARTPS_ISR_OFFSET);
//判断中断标志位RxFIFO是否触发
if (isr_status & (u32)XUARTPS_IXR_RXOVR){
rec_data = XUartPs_RecvByte(XPAR_PS7_UART_0_BASEADDR);
XUartPs_SendByte(XPAR_PS7_UART_0_BASEADDR,rec_data);
//清除中断标志
XUartPs_WriteReg(uart_instance_ptr->Config.BaseAddress,
XUARTPS_ISR_OFFSET, XUARTPS_IXR_RXOVR) ;
}
}
//串口0中断初始化
int uart_intr_init(XScuGic *intc, XUartPs *uart0_ps)
{
int status;
// u32 IntrMask;
//初始化中断控制器
XScuGic_Config *intc_cfg;
intc_cfg = XScuGic_LookupConfig(XPAR_SCUGIC_SINGLE_DEVICE_ID);
if (NULL == intc_cfg)
return XST_FAILURE;
status = XScuGic_CfgInitialize(intc, intc_cfg,
intc_cfg->CpuBaseAddress);
if (status != XST_SUCCESS)
return XST_FAILURE;
//设置并打开中断异常处理功能
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)XScuGic_InterruptHandler,
(void *)intc);
Xil_ExceptionEnable();
//为中断设置中断处理函数
XScuGic_Connect(intc, XPAR_XUARTPS_0_INTR,
(Xil_ExceptionHandler) uart0_intr_handler,(void *) uart0_ps);
//设置UART的中断触发方式
XUartPs_SetInterruptMask(uart0_ps, XUARTPS_IXR_RXOVR);
XScuGic_SetPriorityTriggerType(intc, XPAR_XUARTPS_0_INTR, 0x10, 0x3);
//使能GIC中的串口中断
XScuGic_Enable(intc, XPAR_XUARTPS_0_INTR);
return XST_SUCCESS;
}
//uartlite中断处理函数
void uartlite_handel(void *callback_ref){
XUartLite *uartlite_pl = (XUartLite *) callback_ref;
u32 IsrStatus;
u8 rec_data;
IsrStatus = XUartLite_ReadReg(uartlite_pl->RegBaseAddress,
XUL_STATUS_REG_OFFSET);
if(IsrStatus|XUL_SR_RX_FIFO_VALID_DATA){
rec_data = XUartLite_RecvByte(uartlite_pl->RegBaseAddress);
XUartLite_SendByte(uartlite_pl->RegBaseAddress,rec_data);
}
};
int setup_interrupt_uartlite(XScuGic *gic_ins_ptr, XUartLite *uartlite_ins_ptr, u16 uartlite_int_id){
int status;
XUartLite_WriteReg(uartlite_ins_ptr->RegBaseAddress,XUL_CONTROL_REG_OFFSET,XUL_CR_ENABLE_INTR);
XScuGic_SetPriorityTriggerType(gic_ins_ptr, uartlite_int_id,0x20, 0x3);
status = XScuGic_Connect(gic_ins_ptr, uartlite_int_id,
(Xil_ExceptionHandler) uartlite_handel, (void *) uartlite_ins_ptr);
if (status != XST_SUCCESS) {
return status;
}
XScuGic_Enable(gic_ins_ptr, uartlite_int_id);
XUartLite_EnableInterrupt(uartlite_ins_ptr);
return XST_SUCCESS;
}
int main(void)
{
int status;
status = uart_init(&Uart0_Ps,UART0_DEVICE_ID); //串口初始化
if (status == XST_FAILURE) {
xil_printf("Uart Initial Failed\r\n");
return XST_FAILURE;
}
XUartLite_Initialize(&Uartlite,XPAR_UARTLITE_0_DEVICE_ID);
uart_intr_init(&Intc, &Uart0_Ps); //串口中断初始化
setup_interrupt_uartlite(&Intc, &Uartlite, UARTLITE_INT_IRQ_ID);
while (1){
};
return 0;
}
//串口0中断处理函数
void uart0_intr_handler(void *call_back_ref)
{
XUartPs *uart_instance_ptr = (XUartPs *) call_back_ref;
u8 rec_data = 0 ;
u32 isr_status ; //中断状态标志
//读取中断ID寄存器,判断触发的是哪种中断
isr_status = XUartPs_ReadReg(uart_instance_ptr->Config.BaseAddress,
XUARTPS_IMR_OFFSET);
isr_status &= XUartPs_ReadReg(uart_instance_ptr->Config.BaseAddress,
XUARTPS_ISR_OFFSET);
//判断中断标志位RxFIFO是否触发
if (isr_status & (u32)XUARTPS_IXR_RXOVR){
rec_data = XUartPs_RecvByte(XPAR_PS7_UART_0_BASEADDR);
XUartPs_SendByte(XPAR_PS7_UART_0_BASEADDR,rec_data);
//清除中断标志
XUartPs_WriteReg(uart_instance_ptr->Config.BaseAddress,
XUARTPS_ISR_OFFSET, XUARTPS_IXR_RXOVR) ;
}
}
//串口0中断初始化
int uart_intr_init(XScuGic *intc, XUartPs *uart0_ps)
{
int status;
// u32 IntrMask;
//初始化中断控制器
XScuGic_Config *intc_cfg;
intc_cfg = XScuGic_LookupConfig(XPAR_SCUGIC_SINGLE_DEVICE_ID);
if (NULL == intc_cfg)
return XST_FAILURE;
status = XScuGic_CfgInitialize(intc, intc_cfg,
intc_cfg->CpuBaseAddress);
if (status != XST_SUCCESS)
return XST_FAILURE;
//设置并打开中断异常处理功能
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)XScuGic_InterruptHandler,
(void *)intc);
Xil_ExceptionEnable();
//为中断设置中断处理函数
XScuGic_Connect(intc, XPAR_XUARTPS_0_INTR,
(Xil_ExceptionHandler) uart0_intr_handler,(void *) uart0_ps);
//设置UART的中断触发方式
XUartPs_SetInterruptMask(uart0_ps, XUARTPS_IXR_RXOVR);
XScuGic_SetPriorityTriggerType(intc, XPAR_XUARTPS_0_INTR, 0x10, 0x3);
//使能GIC中的串口中断
XScuGic_Enable(intc, XPAR_XUARTPS_0_INTR);
return XST_SUCCESS;
}
//uartlite中断处理函数
void uartlite_handel(void *callback_ref){
XUartLite *uartlite_pl = (XUartLite *) callback_ref;
u32 IsrStatus;
u8 rec_data;
IsrStatus = XUartLite_ReadReg(uartlite_pl->RegBaseAddress,
XUL_STATUS_REG_OFFSET);
if(IsrStatus|XUL_SR_RX_FIFO_VALID_DATA){
rec_data = XUartLite_RecvByte(uartlite_pl->RegBaseAddress);
XUartLite_SendByte(uartlite_pl->RegBaseAddress,rec_data);
}
};
int setup_interrupt_uartlite(XScuGic *gic_ins_ptr, XUartLite *uartlite_ins_ptr, u16 uartlite_int_id){
int status;
XUartLite_WriteReg(uartlite_ins_ptr->RegBaseAddress,XUL_CONTROL_REG_OFFSET,XUL_CR_ENABLE_INTR);
XScuGic_SetPriorityTriggerType(gic_ins_ptr, uartlite_int_id,0x20, 0x3);
status = XScuGic_Connect(gic_ins_ptr, uartlite_int_id,
(Xil_ExceptionHandler) uartlite_handel, (void *) uartlite_ins_ptr);
if (status != XST_SUCCESS) {
return status;
}
XScuGic_Enable(gic_ins_ptr, uartlite_int_id);
XUartLite_EnableInterrupt(uartlite_ins_ptr);
return XST_SUCCESS;
}