📄 testapp_memorycaching.c
字号:
/* * Initialize the interrupt controller driver so that it's ready to use. */ Status = XIntc_Initialize(&InterruptController, INTC_DEVICE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Connect the device driver 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(&InterruptController, INTR_ID, (XInterruptHandler)DmaInterruptHandler, DmaCentralPtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Start the interrupt controller so interrupts are enabled for all * devices that cause interrupts. Specify real mode so that the DMA device * can cause interrupts through the interrupt controller. */ Status = XIntc_Start(&InterruptController, XIN_REAL_MODE); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupt for the DMA device */ XIntc_Enable(&InterruptController, INTR_ID); /* * Initialize interrupts on Microblaze */ microblaze_enable_interrupts(); return XST_SUCCESS;}/****************************************************************************//**** This function is the Interrupt Service Routine for the DMA Central device.* It will be called by the processor whenever an interrupt is asserted by the* device.** @param CallBackRef is a pointer to the instance of the DMA Central device.** @return None.** @note None.******************************************************************************/static void DmaInterruptHandler(void *CallBackRef){ Xuint32 IntrStatusValue; Xuint32 StatusValue; XDmaCentral *DmaCentralPtr = (XDmaCentral *)CallBackRef; /* * Get the interrupt status from the device and check the value. */ IntrStatusValue = XDmaCentral_InterruptStatusGet(DmaCentralPtr); if (IntrStatusValue & XDMC_IXR_DMA_ERROR_MASK) /* DMA Error Interrupt */ { /* * Read DMA Status register. */ StatusValue = XDmaCentral_GetStatus(DmaCentralPtr); if (StatusValue & XDMC_DMASR_BUS_ERROR_MASK) /* Bus error occurs */ { DmaBusError = XTRUE; /* Set DMA Bus Error flag */ } if (StatusValue & XDMC_DMASR_BUS_TIMEOUT_MASK) /* Bus Timeout occurs */ { DmaBusTimeout = XTRUE; /* Set DMA Bus Timeout flag */ } } if (IntrStatusValue & XDMC_IXR_DMA_DONE_MASK) /* DMA Done Interrupt */ { /* * Set DMA Done flag so the code in application context can be aware * of the finished DMA transfer. */ DmaDone = XTRUE; } /* * Clear all bits in Interrupt Status Register. */ XDmaCentral_InterruptClear(DmaCentralPtr, IntrStatusValue);}/*****************************************************************************//**** This function writes a data pattern to the DMA source address and clears the* data at the DMA destination address.** @param SrcAddress is the source address of the DMA transfer.* @param DesAddress is the destination address of the DMA transfer.** @return None** @note None*******************************************************************************/static void SrcDesWriteClear(XIo_Address SrcAddress, XIo_Address DesAddress){ int Index; xil_printf("\r\nStarting Writing and Clearing Source and Destination Address.\r\n"); for(Index = 0; Index < BUFFER_BYTESIZE; Index++) { XIo_Out32(SrcAddress, Index); XIo_Out32(DesAddress, 0); SrcAddress = SrcAddress + 4; DesAddress = DesAddress + 4; } xil_printf("\r\nFinished Writing and Clearing Source and Destination Address.\r\n");}/*****************************************************************************//**** This function waits in a while loop for the completion of the DMA transfers.** @param None** @return XST_SUCCESS to indicate success, else XST_FAILURE to indicate* failure.** @note None*******************************************************************************/static XStatus WaitForDmaCompletion(){ Xuint32 IntRegStatus; /* DMA Interrupt Status */ int i; int j; xil_printf("\r\nWaiting:"); while (1) { xil_printf("."); if (DmaBusError == XTRUE) /* DMA Bus Error occurs. */ { xil_printf("Bus error \r\n"); return XST_FAILURE; } if (DmaBusTimeout == XTRUE) /* DMA Bus Timeout occurs */ { xil_printf("Bus Timeout \r\n"); return XST_FAILURE; } if (DmaDone == XTRUE) /* DMA transfer is done */ { xil_printf("\r\n"); xil_printf("\r\nDMA Transfer Complete, Verifying Destination Data\r\n"); for (i=0; i<OPB_CENTRAL_DMA_LEN/4-1; i++) { j = *((volatile int *)(OPB_CENTRAL_DMA_DA + (4*i))); if (i != j) { xil_printf("Read from DMA Destination Address Failed %d \r\n", i); error(); } } xil_printf("\r\nDestination Data is Correct\r\n"); /* * Check the interrupt register to see if it is cleared */ IntRegStatus = XDmaCentral_InterruptStatusGet(&DmaCentral); if(IntRegStatus == 0) { xil_printf("\r\nDMA Interrupt Cleared\r\n"); return XST_SUCCESS; } else { xil_printf("\r\n Interrupt Didn't Clear \r\n"); } } }}/*****************************************************************************//**** This function writes a pattern to the GPIO device which is configured as an* output** @param BaseAddress is the baseaddress of the GPIO device.* @param GpioWidth is the width of the GPIO.** @return None** @note None*******************************************************************************/void WriteToGPOutput(Xuint32 BaseAddress, Xuint32 GpioWidth){ Xuint32 LedWidth; Xuint32 LedOutput; volatile int Delay = 0; Xuint32 NumTimes = 6; /* * Set the direction for all signals to be outputs */ XGpio_mSetDataDirection(BaseAddress, 1, 0x00000000); while (NumTimes > 0) { LedOutput = 1; for(LedWidth=0; LedWidth < (GpioWidth-1); LedWidth++) { /* * Set the LED to glow */ XGpio_mSetDataReg(BaseAddress, 1, LedOutput); LedOutput = LedOutput << 1; /* * Wait a small amount of time so the LED is visible */ for (Delay=0; Delay<1000000; Delay++); } LedOutput = 1; LedOutput = ~LedOutput; for(LedWidth=0; LedWidth < (GpioWidth-1); LedWidth++) { /* * Clear the LED */ XGpio_mSetDataReg(BaseAddress, 1, LedOutput); LedOutput = LedOutput << 1; /* * Wait a small amount of time so the LED is visible */ for (Delay=0; Delay<1000000; Delay++); } NumTimes--; }}/*****************************************************************************//**** This function is the error handler and waits in a while(1) loop if an error* occurs in this example.** @param None** @return None** @note None*******************************************************************************/void error(void){ while (1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -