///////////////////////////////////////////////// // // initialize first DMA function // ///////////////////////////////////////////////// int init_dma(){ XAxiDma_Config *CfgPtr; int status; CfgPtr = XAxiDma_LookupConfig(XPAR_AXI_DMA_0_DEVICE_ID); if(!CfgPtr){ print("Error looking for AXI DMA config\n\r"); return XST_FAILURE; } status = XAxiDma_CfgInitialize(&AxiDma,CfgPtr); if(status != XST_SUCCESS){ print("Error initializing DMA 0\n\r"); return XST_FAILURE; } //check for scatter gather mode if(XAxiDma_HasSg(&AxiDma)){ print("Error DMA configured in SG mode\n\r"); return XST_FAILURE; } /* Disable interrupts, we use polling mode */ XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK,XAXIDMA_DEVICE_TO_DMA); XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK,XAXIDMA_DMA_TO_DEVICE); return XST_SUCCESS; }
// A function that wraps all AXI DMA initialization related API calls int init_dma(XAxiDma *axiDmaPtr){ XAxiDma_Config *CfgPtr; int status; // Get pointer to DMA configuration CfgPtr = XAxiDma_LookupConfig(XPAR_AXIDMA_0_DEVICE_ID); if(!CfgPtr){ print("Error looking for AXI DMA config\n\r"); return XST_FAILURE; } // Initialize the DMA handle status = XAxiDma_CfgInitialize(axiDmaPtr,CfgPtr); if(status != XST_SUCCESS){ print("Error initializing DMA\n\r"); return XST_FAILURE; } //check for scatter gather mode - this example must have simple mode only if(XAxiDma_HasSg(axiDmaPtr)){ print("Error DMA configured in SG mode\n\r"); return XST_FAILURE; } //disable the interrupts XAxiDma_IntrDisable(axiDmaPtr, XAXIDMA_IRQ_ALL_MASK,XAXIDMA_DEVICE_TO_DMA); XAxiDma_IntrDisable(axiDmaPtr, XAXIDMA_IRQ_ALL_MASK,XAXIDMA_DMA_TO_DEVICE); return XST_SUCCESS; }
int DMA_init(u16 DeviceId) { XAxiDma_Config *CfgPtr; int Status; CfgPtr = XAxiDma_LookupConfig(DeviceId); if (!CfgPtr) { xil_printf("No config found for %d\r\n", DeviceId); return XST_FAILURE; } Status = XAxiDma_CfgInitialize(&AxiDma, CfgPtr); if (Status != XST_SUCCESS) { xil_printf("Initialization failed %d\r\n", Status); return XST_FAILURE; } if(XAxiDma_HasSg(&AxiDma)){ xil_printf("Device configured as SG mode\r\n"); return XST_FAILURE; } /* Disable interrupts, we use polling mode */ //XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DEVICE_TO_DMA); XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DMA_TO_DEVICE); return XST_SUCCESS; }
/** * * Main function * * This function is the main entry of the interrupt test. It does the following: * Set up the output terminal if UART16550 is in the hardware build * Initialize the DMA engine * Set up Tx and Rx channels * Set up the interrupt system for the Tx and Rx interrupts * Submit a transfer * Wait for the transfer to finish * Check transfer status * Disable Tx and Rx interrupts * Print test status and exit * * @param None * * @return * - XST_SUCCESS if example finishes successfully * - XST_FAILURE if example fails. * * @note None. * ******************************************************************************/ int main(void) { int Status; XAxiDma_Config *Config; int Tries = NUMBER_OF_TRANSFERS; int Index; u8 *TxBufferPtr; u8 *RxBufferPtr; u8 Value; TxBufferPtr = (u8 *)TX_BUFFER_BASE ; RxBufferPtr = (u8 *)RX_BUFFER_BASE; /* Initial setup for Uart16550 */ #ifdef XPAR_UARTNS550_0_BASEADDR Uart550_Setup(); #endif xil_printf("\r\n--- Entering main() --- \r\n"); Config = XAxiDma_LookupConfig(DMA_DEV_ID); if (!Config) { xil_printf("No config found for %d\r\n", DMA_DEV_ID); return XST_FAILURE; } /* Initialize DMA engine */ Status = XAxiDma_CfgInitialize(&AxiDma, Config); if (Status != XST_SUCCESS) { xil_printf("Initialization failed %d\r\n", Status); return XST_FAILURE; } if(XAxiDma_HasSg(&AxiDma)){ xil_printf("Device configured as SG mode \r\n"); return XST_FAILURE; } /* Set up Interrupt system */ Status = SetupIntrSystem(&Intc, &AxiDma, TX_INTR_ID, RX_INTR_ID); if (Status != XST_SUCCESS) { xil_printf("Failed intr setup\r\n"); return XST_FAILURE; } /* Disable all interrupts before setup */ XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DMA_TO_DEVICE); XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DEVICE_TO_DMA); /* Enable all interrupts */ XAxiDma_IntrEnable(&AxiDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DMA_TO_DEVICE); XAxiDma_IntrEnable(&AxiDma, XAXIDMA_IRQ_ALL_MASK, XAXIDMA_DEVICE_TO_DMA); /* Initialize flags before start transfer test */ TxDone = 0; RxDone = 0; Error = 0; Value = TEST_START_VALUE; for(Index = 0; Index < MAX_PKT_LEN; Index ++) { TxBufferPtr[Index] = Value; Value = (Value + 1) & 0xFF; } /* Flush the SrcBuffer before the DMA transfer, in case the Data Cache * is enabled */ Xil_DCacheFlushRange((u32)TxBufferPtr, MAX_PKT_LEN); #ifdef __aarch64__ Xil_DCacheFlushRange((UINTPTR)RxBufferPtr, MAX_PKT_LEN); #endif /* Send a packet */ for(Index = 0; Index < Tries; Index ++) { Status = XAxiDma_SimpleTransfer(&AxiDma,(u32) RxBufferPtr, MAX_PKT_LEN, XAXIDMA_DEVICE_TO_DMA); if (Status != XST_SUCCESS) { return XST_FAILURE; } Status = XAxiDma_SimpleTransfer(&AxiDma,(u32) TxBufferPtr, MAX_PKT_LEN, XAXIDMA_DMA_TO_DEVICE); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Wait TX done and RX done */ while (!TxDone && !RxDone && !Error) { /* NOP */ } if (Error) { xil_printf("Failed test transmit%s done, " "receive%s done\r\n", TxDone? "":" not", RxDone? "":" not"); goto Done; } /* * Test finished, check data */ Status = CheckData(MAX_PKT_LEN, 0xC); if (Status != XST_SUCCESS) { xil_printf("Data check failed\r\n"); goto Done; } } xil_printf("AXI DMA interrupt example test passed\r\n"); /* Disable TX and RX Ring interrupts and return success */ DisableIntrSystem(&Intc, TX_INTR_ID, RX_INTR_ID); Done: xil_printf("--- Exiting main() --- \r\n"); return XST_SUCCESS; }