zynq-uart中断学习记录+关闭cache

发布时间:2024年01月01日

uart中断初始化流程

int SetupInterruptSystem(INTC *IntcInstancePtr,
				XUartPs *UartInstancePtr,
				u16 UartIntrId)
{
	int Status;
	/*
	 * Initialize the interrupt controller driver so that it's ready to
	 * use.
	 */
	Xil_ExceptionInit();

	GicPtr=XScuGic_LookupConfig(GIC_VEC_ID);

	status=XScuGic_CfgInitialize(&ScuGic,GicPtr,GicPtr->CpuBaseAddress);
	if(status!=XST_SUCCESS){
		return XST_FAILURE;
	}
	/*
	 * Connect the handler that will be called when an interrupt
	 * for the device occurs, the handler defined above performs the
	 * specific interrupt processing for the device.
	 */
	Status = XIntc_Connect(IntcInstancePtr, UartIntrId,
		(XInterruptHandler) XUartPs_InterruptHandler, UartInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
    XScuGic_Enable(&ScuGic,UART_INTR_ID);
	/*
	 * Start the interrupt controller so interrupts are enabled for all
	 * devices that cause interrupts.
	 */
    Xil_ExceptionEnable();

	return XST_SUCCESS;
}

uart初始化流程:

int UARTOinitial(){
	int status;
	u32 intrMask=0;

	UartPtr=XUartPs_LookupConfig(UART_DEVICE_ID);
	status=XUartPs_CfgInitialize(&Uart0,UartPtr,UartPtr->BaseAddress);
	if(status!=XST_SUCCESS){
		return XST_FAILURE;
	}

	status=XUartPs_SetBaudRate(&Uart0,115200);
	if(status!=XST_SUCCESS){
		return XST_FAILURE;
	}
    //设置波特率
	//Callback function
	XUartPs_SetHandler(&Uart0,(XUartPs_Handler)uart0Handler,&Uart0);
    //设置中断处理函数

	intrMask=XUARTPS_IXR_TOUT;
    //设置uart中断触条件
    /*(#define XUARTPS_IXR_RBRK	0x00002000U /**< Rx FIFO break detect interrupt */
#define XUARTPS_IXR_TOVR	0x00001000U /**< Tx FIFO Overflow interrupt */
#define XUARTPS_IXR_TNFUL	0x00000800U /**< Tx FIFO Nearly Full interrupt */
#define XUARTPS_IXR_TTRIG	0x00000400U /**< Tx Trig interrupt */
#define XUARTPS_IXR_DMS		0x00000200U /**< Modem status change interrupt */
#define XUARTPS_IXR_TOUT	0x00000100U /**< Timeout error interrupt */
#define XUARTPS_IXR_PARITY 	0x00000080U /**< Parity error interrupt */
#define XUARTPS_IXR_FRAMING	0x00000040U /**< Framing error interrupt */
#define XUARTPS_IXR_OVER	0x00000020U /**< Overrun error interrupt */
#define XUARTPS_IXR_TXFULL 	0x00000010U /**< TX FIFO full interrupt. */
#define XUARTPS_IXR_TXEMPTY	0x00000008U /**< TX FIFO empty interrupt. */
#define XUARTPS_IXR_RXFULL 	0x00000004U /**< RX FIFO full interrupt. */
#define XUARTPS_IXR_RXEMPTY	0x00000002U /**< RX FIFO empty interrupt. */
#define XUARTPS_IXR_RXOVR  	0x00000001U /**< RX FIFO trigger interrupt. */
#define XUARTPS_IXR_MASK	0x00003FFFU /**< Valid bit mask */
/* @} */)*/
	XUartPs_SetInterruptMask(&Uart0,intrMask);

	XUartPs_SetOperMode(&Uart0,XUARTPS_OPER_MODE_NORMAL);
    //设置模式(共4种)

	XUartPs_SetRecvTimeout(&Uart0, 8);
    //This function sets the Receive Timeout of the UART.设置两帧之间间隔的时间以触发中断
	XUartPs_Recv(&Uart0, RecvBuffer, 32);
    //接收上位机传输数据
}

关闭cache:Xil_SetTlbAttributes(0xFFFF0000,0x14de2);

文章来源:https://blog.csdn.net/weixin_60010850/article/details/135297338
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。