From 16795cbacfe024db21fdcfca60ff5ad2da66b044 Mon Sep 17 00:00:00 2001 From: VNSL Durga Date: Tue, 17 Mar 2015 14:20:23 +0530 Subject: [PATCH] ZDMA_v1_0: Added examples to ZDMA driver. Signed-off-by: VNSL Durga --- .../drivers/zdma/examples/index.html | 32 ++ .../zdma/examples/xzdma_linear_example.c | 375 ++++++++++++++++++ .../zdma/examples/xzdma_linkedlist_example.c | 353 +++++++++++++++++ .../examples/xzdma_readonlymode_example.c | 318 +++++++++++++++ .../zdma/examples/xzdma_selftest_example.c | 147 +++++++ .../zdma/examples/xzdma_simple_example.c | 332 ++++++++++++++++ .../examples/xzdma_writeonlymode_example.c | 339 ++++++++++++++++ 7 files changed, 1896 insertions(+) create mode 100755 XilinxProcessorIPLib/drivers/zdma/examples/index.html create mode 100644 XilinxProcessorIPLib/drivers/zdma/examples/xzdma_linear_example.c create mode 100644 XilinxProcessorIPLib/drivers/zdma/examples/xzdma_linkedlist_example.c create mode 100644 XilinxProcessorIPLib/drivers/zdma/examples/xzdma_readonlymode_example.c create mode 100644 XilinxProcessorIPLib/drivers/zdma/examples/xzdma_selftest_example.c create mode 100644 XilinxProcessorIPLib/drivers/zdma/examples/xzdma_simple_example.c create mode 100644 XilinxProcessorIPLib/drivers/zdma/examples/xzdma_writeonlymode_example.c diff --git a/XilinxProcessorIPLib/drivers/zdma/examples/index.html b/XilinxProcessorIPLib/drivers/zdma/examples/index.html new file mode 100755 index 00000000..5547c515 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/zdma/examples/index.html @@ -0,0 +1,32 @@ + + + + + +Driver example applications + + + +

Example Applications for the driver ccm_v5_0

+
+ + + + + + +

Copyright � 1995-2014 Xilinx, Inc. All rights reserved.

+ + diff --git a/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_linear_example.c b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_linear_example.c new file mode 100644 index 00000000..74fe731e --- /dev/null +++ b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_linear_example.c @@ -0,0 +1,375 @@ +/****************************************************************************** +* +* Copyright (C) 2014 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* +* @file xzdma_linear_example.c +* +* This file contains the example using XZDma driver to do data transfer in +* Linear mode on ZDMA device. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who     Date     Changes
+* ----- ------  -------- -----------------------------------------------------
+* 1.0   vns     2/27/15  First release
+* 
+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xzdma.h" +#include "xparameters.h" +#include "xscugic.h" + +/************************** Function Prototypes ******************************/ + +int XZDma_LinearExample(u16 DeviceId); +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XZDma *InstancePtr, u16 IntrId); +static void DoneHandler(void *CallBackRef); +static void ErrorHandler(void *CallBackRef, u32 Mask); + +/************************** Constant Definitions ******************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define ZDMA_DEVICE_ID XPAR_XZDMA_0_DEVICE_ID /* ZDMA device Id */ +#define ZDMA_INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID + /**< SCUGIC Device ID */ +#define ZDMA_INTR_DEVICE_ID XPAR_XADMAPS_0_INTR/**< ZDMA Interrupt Id */ + +/**************************** Type Definitions *******************************/ + + +/************************** Variable Definitions *****************************/ + +XZDma ZDma; /**_DEVICE_ID value from +* xparameters.h. +* +* @return +* - XST_SUCCESS if successful. +* - XST_FAILURE if failed. +* +* @note None. +* +******************************************************************************/ +int XZDma_LinearExample(u16 DeviceId) +{ + int Status; + XZDma_Config *Config; + XZDma_DataConfig Configure; /**< Configuration values */ + XZDma_Transfer Data[2]; + u32 Value; + u32 Index; + + /* + * Initialize the ZDMA driver so that it's ready to use. + * Look up the configuration in the config table, + * then initialize it. + */ + Config = XZDma_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XZDma_CfgInitialize(&ZDma, Config, Config->BaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + /* + * Performs the self-test to check hardware build. + */ + Status = XZDma_SelfTest(&ZDma); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Filling the buffers for data transfer */ + Value = 0x1230; + for (Index = 0; Index < 5; Index++) { + SrcBuf[Index] = Value++; + } + Value = 0x002345F; + for (Index = 0; Index < 5; Index++) { + Src1Buf[Index] = Value++; + } + + /* ZDMA has set in simple transfer of Normal mode */ + Status = XZDma_SetMode(&ZDma, TRUE, XZDMA_NORMAL_MODE); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Allocated memory starting address should be 64 bit aligned */ + XZDma_CreateBDList(&ZDma, XZDMA_LINEAR, (UINTPTR)AlloMem, 256); + + /* Interrupt call back has been set */ + XZDma_SetCallBack(&ZDma, XZDMA_HANDLER_DONE, + (void *)DoneHandler, &ZDma); + XZDma_SetCallBack(&ZDma, XZDMA_HANDLER_ERROR, + (void *)ErrorHandler, &ZDma); + /* + * Connect to the interrupt controller. + */ + Status = SetupInterruptSystem(&Intc, &(ZDma), + ZDMA_INTR_DEVICE_ID); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Configuration settings */ + XZDma_GetChDataConfig(&ZDma, &Configure); + Configure.OverFetch = 0; + Configure.SrcIssue = 0x1F; + Configure.SrcBurstType = XZDMA_INCR_BURST; + Configure.SrcBurstLen = 0xF; + Configure.DstBurstType = XZDMA_INCR_BURST; + Configure.DstBurstLen = 0xF; + XZDma_SetChDataConfig(&ZDma, &Configure); + + /* Enable required interrupts */ + XZDma_EnableIntr(&ZDma, (XZDMA_IXR_DMA_DONE_MASK | + XZDMA_IXR_DMA_PAUSE_MASK)); + + /* Filling the data transfer elements */ + Data[0].SrcAddr = (UINTPTR)SrcBuf; + Data[0].Size = 1000; + Data[0].DstAddr = (UINTPTR)DstBuf; + Data[0].SrcCoherent = 0; + Data[0].DstCoherent = 0; + Data[0].Pause = 1; + + Data[1].SrcAddr = (UINTPTR)Src1Buf; + Data[1].Size = 1200; + Data[1].DstAddr = (UINTPTR)Dst1Buf; + Data[1].SrcCoherent = 0; + Data[1].DstCoherent = 0; + Data[1].Pause = 0; + /* + * Invalidating destination address and flushing + * source address in cache before the start of DMA data transfer. + */ + Xil_DCacheFlushRange((INTPTR)Data[0].SrcAddr, Data[0].Size); + Xil_DCacheInvalidateRange((INTPTR)Data[0].DstAddr, Data[0].Size); + Xil_DCacheFlushRange((INTPTR)Data[1].SrcAddr, Data[1].Size); + Xil_DCacheInvalidateRange((INTPTR)Data[1].DstAddr, Data[1].Size); + + XZDma_Start(&ZDma, Data, 2); /* Initiates the data transfer */ + + /* wait until pause interrupt is generated and has been resumed */ + while (Pause == 0); + + /* Resuming the ZDMA core */ + XZDma_Resume(&ZDma); + + while (Done == 0); /* Wait till DMA done interrupt generated */ + + /* Validating the data transfer */ + for (Index = 0; Index < 250; Index++) { + if (SrcBuf[Index] != DstBuf[Index]) { + return XST_FAILURE; + } + } + for (Index = 0; Index < 300; Index++) { + if (Src1Buf[Index] != Dst1Buf[Index]) { + return XST_FAILURE; + } + } + + return XST_SUCCESS; + +} + +/*****************************************************************************/ +/** +* This function sets up the interrupt system so interrupts can occur for the +* ZDMA. This function is application-specific. The user should modify this +* function to fit the application. +* +* @param IntcInstancePtr is a pointer to the instance of the INTC. +* @param InstancePtr contains a pointer to the instance of the ZDMA +* driver which is going to be connected to the interrupt +* controller. +* @param IntrId is the interrupt Id and is typically +* XPAR__INTR value from xparameters.h. +* +* @return +* - XST_SUCCESS if successful +* - XST_FAILURE if failed +* +* @note None. + +* +****************************************************************************/ +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XZDma *InstancePtr, u16 IntrId) +{ + int Status; + +#ifndef TESTAPP_GEN + XScuGic_Config *IntcConfig; /* Config for interrupt controller */ + + /* + * Initialize the interrupt controller driver + */ + IntcConfig = XScuGic_LookupConfig(ZDMA_INTC_DEVICE_ID); + if (NULL == IntcConfig) { + return XST_FAILURE; + } + + Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, + IntcConfig->CpuBaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Connect the interrupt controller interrupt handler to the + * hardware interrupt handling logic in the processor. + */ + Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, + (Xil_ExceptionHandler) XScuGic_InterruptHandler, + IntcInstancePtr); +#endif + + /* + * Connect a device driver handler that will be called when an + * interrupt for the device occurs, the device driver handler + * performs the specific interrupt processing for the device + */ + Status = XScuGic_Connect(IntcInstancePtr, IntrId, + (Xil_ExceptionHandler) XZDma_IntrHandler, + (void *) InstancePtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Enable the interrupt for the device + */ + XScuGic_Enable(IntcInstancePtr, IntrId); + + + /* + * Enable interrupts + */ + Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ); + + + return XST_SUCCESS; +} + +/*****************************************************************************/ +/** +* This static function handles ZDMA Done interrupts. +* +* @param CallBackRef is the callback reference passed from the interrupt +* handler, which in our case is a pointer to the driver instance. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void DoneHandler(void *CallBackRef) +{ + Done = 1; + +} + +/*****************************************************************************/ +/** +* This static function handles ZDMA pause interrupts. +* +* @param CallBackRef is the callback reference passed from the interrupt +* handler, which in our case is a pointer to the driver instance. +* @param Event specifies which interrupts were occurred. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void ErrorHandler(void *CallBackRef, u32 Mask) +{ + Pause = 1; +} diff --git a/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_linkedlist_example.c b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_linkedlist_example.c new file mode 100644 index 00000000..228c2581 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_linkedlist_example.c @@ -0,0 +1,353 @@ +/****************************************************************************** +* +* Copyright (C) 2014 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* +* @file xzdma_linkedlist_example.c +* +* This file contains the example using XZDma driver to do data transfer in +* Linked list mode on ZDMA device. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who     Date     Changes
+* ----- ------  -------- -----------------------------------------------------
+* 1.0   vns     2/27/15  First release
+* 
+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xzdma.h" +#include "xparameters.h" +#include "xscugic.h" + +/************************** Function Prototypes ******************************/ + +int XZDma_LinkedListExample(u16 DeviceId); +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XZDma *InstancePtr, u16 IntrId); +static void DoneHandler(void *CallBackRef); + +/************************** Constant Definitions ******************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define ZDMA_DEVICE_ID XPAR_XZDMA_0_DEVICE_ID /* ZDMA device Id */ +#define ZDMA_INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID + /**< SCUGIC Device ID */ +#define ZDMA_INTR_DEVICE_ID XPAR_XADMAPS_0_INTR /**< ZDMA Interrupt Id */ +#define TESTDATA1 0xABCD1230 /**< Test data */ +#define TESTDATA2 0x00005000 /**< Test data */ + +/**************************** Type Definitions *******************************/ + + +/************************** Variable Definitions *****************************/ + +XZDma ZDma; /**_DEVICE_ID value from +* xparameters.h. +* +* @return +* - XST_SUCCESS if successful. +* - XST_FAILURE if failed. +* +* @note None. +* +******************************************************************************/ +int XZDma_LinkedListExample(u16 DeviceId) +{ + int Status; + XZDma_Config *Config; + XZDma_DataConfig Configur; /**< Configuration values */ + XZDma_Transfer Data[2]; + u32 Value; + u32 Index; + /* + * Initialize the ZDMA driver so that it's ready to use. + * Look up the configuration in the config table, + * then initialize it. + */ + Config = XZDma_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XZDma_CfgInitialize(&ZDma, Config, Config->BaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Performs the self-test to check hardware build. + */ + Status = XZDma_SelfTest(&ZDma); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + /* Filling the buffers for data transfer */ + Value = TESTDATA1; + for (Index = 0; Index < 250; Index++) { + SrcBuf[Index] = Value++; + } + Value = TESTDATA2; + for (Index = 0; Index < 4; Index++) { + *(Src1Buf+Index) = Value++; + } + + /* ZDMA has set in linked list mode for normal transfer */ + Status = XZDma_SetMode(&ZDma, TRUE, XZDMA_NORMAL_MODE); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Allocated memory starting address should be 64 bit aligned */ + XZDma_CreateBDList(&ZDma, XZDMA_LINKEDLIST, (UINTPTR)AlloMem, 256); + + /* Interrupt call back has been set */ + XZDma_SetCallBack(&ZDma, XZDMA_HANDLER_DONE, + (void *)DoneHandler, &ZDma); + + /* + * Connect to the interrupt controller. + */ + Status = SetupInterruptSystem(&Intc, &(ZDma), + ZDMA_INTR_DEVICE_ID); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + /* + * All the configurations are kept as is which was got + * through XZDma_GetChDataConfig and only over fetch is disabled + */ + /* Configuration settings */ + XZDma_GetChDataConfig(&ZDma, &Configur); + Configur.OverFetch = 0; + XZDma_SetChDataConfig(&ZDma, &Configur); + + /* Enable required interrupts */ + XZDma_EnableIntr(&ZDma, XZDMA_IXR_DMA_DONE_MASK); + + /* Filling the data transfer elements */ + Data[0].SrcAddr = (UINTPTR)SrcBuf; + Data[0].Size = 1000; + Data[0].DstAddr = (UINTPTR)DstBuf; + Data[0].SrcCoherent = 0; + Data[0].DstCoherent = 0; + Data[0].Pause = 0; + + Data[1].SrcAddr = (UINTPTR)Src1Buf; + Data[1].Size = 16; + Data[1].DstAddr = (UINTPTR)Dst1Buf; + Data[1].SrcCoherent = 0; + Data[1].DstCoherent = 0; + Data[1].Pause = 0; + /* + * Invalidating destination address and flushing + * source address in cache before initiating the data transfer + */ + Xil_DCacheFlushRange((INTPTR)Data[0].SrcAddr, Data[0].Size); + Xil_DCacheInvalidateRange((INTPTR)Data[0].DstAddr, Data[0].Size); + Xil_DCacheFlushRange((INTPTR)Data[1].SrcAddr, Data[1].Size); + Xil_DCacheInvalidateRange((INTPTR)Data[1].DstAddr, Data[1].Size); + + XZDma_Start(&ZDma, Data, 2); /* Initiates the data transfer */ + + while (Done == 0); /* Wait till DMA done interrupt generated */ + + XZDma_DisableIntr(&ZDma, XZDMA_IXR_DMA_DONE_MASK); + + /* Validating the data transfer */ + for (Index = 0; Index < 250; Index++) { + if (SrcBuf[Index] != DstBuf[Index]) { + return XST_FAILURE; + } + } + for (Index = 0; Index < 4; Index++) { + if (Src1Buf[Index] != Dst1Buf[Index]) { + return XST_FAILURE; + } + } + + return XST_SUCCESS; + +} + +/*****************************************************************************/ +/** +* This function sets up the interrupt system so interrupts can occur for the +* ZDMA. This function is application-specific. The user should modify this +* function to fit the application. +* +* @param IntcInstancePtr is a pointer to the instance of the INTC. +* @param InstancePtr contains a pointer to the instance of the ZDMA +* driver which is going to be connected to the interrupt +* controller. +* @param IntrId is the interrupt Id and is typically +* XPAR__INTR value from xparameters.h. +* +* @return +* - XST_SUCCESS if successful +* - XST_FAILURE if failed +* +* @note None. + +* +****************************************************************************/ +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XZDma *InstancePtr, u16 IntrId) +{ + int Status; + +#ifndef TESTAPP_GEN + XScuGic_Config *IntcConfig; /* Config for interrupt controller */ + + /* + * Initialize the interrupt controller driver + */ + IntcConfig = XScuGic_LookupConfig(ZDMA_INTC_DEVICE_ID); + if (NULL == IntcConfig) { + return XST_FAILURE; + } + + Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, + IntcConfig->CpuBaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Connect the interrupt controller interrupt handler to the + * hardware interrupt handling logic in the processor. + */ + Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, + (Xil_ExceptionHandler) XScuGic_InterruptHandler, + IntcInstancePtr); +#endif + + /* + * Connect a device driver handler that will be called when an + * interrupt for the device occurs, the device driver handler + * performs the specific interrupt processing for the device + */ + Status = XScuGic_Connect(IntcInstancePtr, IntrId, + (Xil_ExceptionHandler) XZDma_IntrHandler, + (void *) InstancePtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Enable the interrupt for the device + */ + XScuGic_Enable(IntcInstancePtr, IntrId); + + + /* + * Enable interrupts + */ + Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ); + + + return XST_SUCCESS; +} + +/*****************************************************************************/ +/** +* This static function handles ZDMA Done interrupts. +* +* @param CallBackRef is the callback reference passed from the interrupt +* handler, which in our case is a pointer to the driver instance. +* @param Event specifies which interrupts were occurred. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void DoneHandler(void *CallBackRef) +{ + + Done = 1; + +} diff --git a/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_readonlymode_example.c b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_readonlymode_example.c new file mode 100644 index 00000000..f9bad52e --- /dev/null +++ b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_readonlymode_example.c @@ -0,0 +1,318 @@ +/****************************************************************************** +* +* Copyright (C) 2014 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* +* @file xzdma_simple_example.c +* +* This file contains the example using XZDma driver to do simple data read +* on ZDMA device. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who     Date     Changes
+* ----- ------  -------- ------------------------------------------------------
+* 1.0   vns     2/27/15  First release
+* 
+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xzdma.h" +#include "xparameters.h" +#include "xscugic.h" + +/************************** Function Prototypes ******************************/ + +int XZDma_SimpleReadOnlyExample(u16 DeviceId); +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XZDma *InstancePtr, u16 IntrId); +static void DoneHandler(void *CallBackRef); + +/************************** Constant Definitions ******************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define ZDMA_DEVICE_ID XPAR_XZDMA_0_DEVICE_ID /* ZDMA device Id */ +#define ZDMA_INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID + /**< SCUGIC Device ID */ +#define ZDMA_INTR_DEVICE_ID XPAR_XADMAPS_0_INTR/**< ZDMA Interrupt Id */ + +#define SIZE 100 /**< Size of the data to be + * transferred */ + +/**************************** Type Definitions *******************************/ + + +/************************** Variable Definitions *****************************/ + +XZDma ZDma; /**_DEVICE_ID value from +* xparameters.h. +* +* @return +* - XST_SUCCESS if successful. +* - XST_FAILURE if failed. +* +* @note None. +* +******************************************************************************/ +int XZDma_SimpleReadOnlyExample(u16 DeviceId) +{ + int Status; + XZDma_Config *Config; + XZDma_DataConfig Configur; /**< Configuration values */ + XZDma_Transfer Data; + u32 Value; + u32 Index; + + /* + * Initialize the ZDMA driver so that it's ready to use. + * Look up the configuration in the config table, + * then initialize it. + */ + Config = XZDma_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XZDma_CfgInitialize(&ZDma, Config, Config->BaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Performs the self-test to check hardware build. + */ + Status = XZDma_SelfTest(&ZDma); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + /* Filling the buffer for data transfer */ + Value = 0xABCD1230; + for (Index = 0; Index < 256; Index++) { + SrcBuf[Index] = Value++; + } + /* + * Flushing source address in cache + */ + Xil_DCacheFlushRange((INTPTR)SrcBuf, SIZE); + + /* ZDMA has set in simple transfer of Read only mode */ + Status = XZDma_SetMode(&ZDma, FALSE, XZDMA_RDONLY_MODE); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + (void)XZDma_SetCallBack(&ZDma, XZDMA_HANDLER_DONE, + DoneHandler, &ZDma); + /* + * Connect to the interrupt controller. + */ + Status = SetupInterruptSystem(&Intc, &(ZDma), + ZDMA_INTR_DEVICE_ID); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Configuration settings */ + Configur.OverFetch = 0; + Configur.SrcIssue = 0x1F; + Configur.SrcBurstType = XZDMA_INCR_BURST; + Configur.SrcBurstLen = 0xF; + Configur.DstBurstType = XZDMA_INCR_BURST; + Configur.DstBurstLen = 0xF; + XZDma_SetChDataConfig(&ZDma, &Configur); + + /* Enable required interrupts */ + XZDma_EnableIntr(&ZDma, XZDMA_IXR_DMA_DONE_MASK); + /* + * Transfer elements + */ + Data.DstAddr = 0; + Data.DstCoherent = 0; + Data.Pause = 0; + Data.SrcAddr = (UINTPTR)SrcBuf; + Data.SrcCoherent = 0; + Data.Size = SIZE; /* Size in bytes */ + + XZDma_Start(&ZDma, &Data, 1); /* Initiates the data transfer */ + /* Wait till DMA Source done interrupt generated */ + while (Done == 0); + + /* + * Validation of read only mode cannot be performed as it will not + * store the values + */ + + return XST_SUCCESS; + +} + +/*****************************************************************************/ +/** +* This function sets up the interrupt system so interrupts can occur for the +* ZDMA. This function is application-specific. The user should modify this +* function to fit the application. +* +* @param IntcInstancePtr is a pointer to the instance of the INTC. +* @param InstancePtr contains a pointer to the instance of the ZDMA +* driver which is going to be connected to the interrupt +* controller. +* @param IntrId is the interrupt Id and is typically +* XPAR__INTR value from xparameters.h. +* +* @return +* - XST_SUCCESS if successful +* - XST_FAILURE if failed +* +* @note None. + +* +****************************************************************************/ +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XZDma *InstancePtr, u16 IntrId) +{ + int Status; + +#ifndef TESTAPP_GEN + XScuGic_Config *IntcConfig; /* Config for interrupt controller */ + + /* + * Initialize the interrupt controller driver + */ + IntcConfig = XScuGic_LookupConfig(ZDMA_INTC_DEVICE_ID); + if (NULL == IntcConfig) { + return XST_FAILURE; + } + + Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, + IntcConfig->CpuBaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Connect the interrupt controller interrupt handler to the + * hardware interrupt handling logic in the processor. + */ + Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, + (Xil_ExceptionHandler) XScuGic_InterruptHandler, + IntcInstancePtr); +#endif + + /* + * Connect a device driver handler that will be called when an + * interrupt for the device occurs, the device driver handler + * performs the specific interrupt processing for the device + */ + Status = XScuGic_Connect(IntcInstancePtr, IntrId, + (Xil_ExceptionHandler) XZDma_IntrHandler, + (void *) InstancePtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Enable the interrupt for the device + */ + XScuGic_Enable(IntcInstancePtr, IntrId); + + + /* + * Enable interrupts + */ + Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ); + + + return XST_SUCCESS; +} + +/*****************************************************************************/ +/** +* This static function handles ZDMA Done interrupts. +* +* @param CallBackRef is the callback reference passed from the interrupt +* handler, which in our case is a pointer to the driver instance. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void DoneHandler(void *CallBackRef) +{ + + Done = 1; + +} diff --git a/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_selftest_example.c b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_selftest_example.c new file mode 100644 index 00000000..7775bf70 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_selftest_example.c @@ -0,0 +1,147 @@ +/****************************************************************************** +* +* Copyright (C) 2014 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* +* @file xzdma_selftest_example.c +* +* This file contains an example using the XZDma driver to do self test +* on the device. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who     Date     Changes
+* ----- ------  -------- ------------------------------------------------------
+* 1.0   vns     2/27/15  First release
+* 
+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xzdma.h" +#include "xparameters.h" + +/************************** Function Prototypes ******************************/ + +int XZDma_SelfTestExample(u16 DeviceId); + +/************************** Constant Definitions ******************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define ZDMA_DEVICE_ID XPAR_XZDMA_0_DEVICE_ID /* ZDMA device Id */ + +/**************************** Type Definitions *******************************/ + + +/************************** Variable Definitions *****************************/ + +XZDma ZDma; /**_DEVICE_ID value from +* xparameters.h. +* +* @return +* - XST_SUCCESS if successful. +* - XST_FAILURE if failed. +* +* @note None. +* +******************************************************************************/ +int XZDma_SelfTestExample(u16 DeviceId) +{ + int Status; + XZDma_Config *Config; + + /* + * Initialize the ZDMA driver so that it's ready to use. + * Look up the configuration in the config table, + * then initialize it. + */ + Config = XZDma_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XZDma_CfgInitialize(&ZDma, Config, Config->BaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Performs the self-test to check hardware build. + */ + + Status = XZDma_SelfTest(&ZDma); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + return XST_SUCCESS; +} diff --git a/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_simple_example.c b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_simple_example.c new file mode 100644 index 00000000..92d3c0ca --- /dev/null +++ b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_simple_example.c @@ -0,0 +1,332 @@ +/****************************************************************************** +* +* Copyright (C) 2014 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* +* @file xzdma_simple_example.c +* +* This file contains the example using XZDma driver to do simple data transfer +* in Normal mode on ZDMA device for 1GB data transfer. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who     Date     Changes
+* ----- ------  -------- ------------------------------------------------------
+* 1.0   vns     2/27/15  First release
+* 
+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xzdma.h" +#include "xparameters.h" +#include "xscugic.h" +#include "xil_cache.h" + +/************************** Function Prototypes ******************************/ + +int XZDma_SimpleExample(u16 DeviceId); +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XZDma *InstancePtr, u16 IntrId); +static void DoneHandler(void *CallBackRef); + +/************************** Constant Definitions ******************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define ZDMA_DEVICE_ID XPAR_XZDMA_0_DEVICE_ID /* ZDMA device Id */ +#define ZDMA_INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID + /**< SCUGIC Device ID */ +#define ZDMA_INTR_DEVICE_ID XPAR_XADMAPS_0_INTR /**< ZDMA Interrupt Id */ + +#define SIZE 1000000000 /**< Size of the data to be transferred */ +#define TESTVALUE 0x1230 /**< For writing into source buffer */ + +/**************************** Type Definitions *******************************/ + + +/************************** Variable Definitions *****************************/ + +XZDma ZDma; /**_DEVICE_ID value from +* xparameters.h. +* +* @return +* - XST_SUCCESS if successful. +* - XST_FAILURE if failed. +* +* @note None. +* +******************************************************************************/ +int XZDma_SimpleExample(u16 DeviceId) +{ + int Status; + XZDma_Config *Config; + XZDma_DataConfig Configure; /**< Configuration values */ + XZDma_Transfer Data; + u32 Index; + u32 Value; + + /* + * Initialize the ZDMA driver so that it's ready to use. + * Look up the configuration in the config table, + * then initialize it. + */ + Config = XZDma_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + + Status = XZDma_CfgInitialize(&ZDma, Config, Config->BaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + /* + * Performs the self-test to check hardware build. + */ + Status = XZDma_SelfTest(&ZDma); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Filling the buffer for data transfer */ + Value = TESTVALUE; + for (Index = 0; Index < SIZE/4; Index++) { + *(SrcBuf +Index) = Value++; + } + /* + * Invalidating destination address and flushing + * source address in cache + */ + Xil_DCacheFlushRange((INTPTR)SrcBuf, SIZE); + Xil_DCacheInvalidateRange((INTPTR)DstBuf, SIZE); + + /* ZDMA has set in simple transfer of Normal mode */ + Status = XZDma_SetMode(&ZDma, FALSE, XZDMA_NORMAL_MODE); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* Interrupt call back has been set */ + XZDma_SetCallBack(&ZDma, XZDMA_HANDLER_DONE, + (void *)DoneHandler, &ZDma); + /* + * Connect to the interrupt controller. + */ + Status = SetupInterruptSystem(&Intc, &(ZDma), + ZDMA_INTR_DEVICE_ID); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + /* Enable required interrupts */ + XZDma_EnableIntr(&ZDma, (XZDMA_IXR_DMA_DONE_MASK)); + + /* Configuration settings */ + Configure.OverFetch = 1; + Configure.SrcIssue = 0x1F; + Configure.SrcBurstType = XZDMA_INCR_BURST; + Configure.SrcBurstLen = 0xF; + Configure.DstBurstType = XZDMA_INCR_BURST; + Configure.DstBurstLen = 0xF; + Configure.SrcCache = 0x2; + Configure.DstCache = 0x2; + Configure.SrcQos = 0; + Configure.DstQos = 0; + + XZDma_SetChDataConfig(&ZDma, &Configure); + /* + * Transfer elements + */ + Data.DstAddr = (UINTPTR)DstBuf; + Data.DstCoherent = 1; + Data.Pause = 0; + Data.SrcAddr = (UINTPTR)SrcBuf; + Data.SrcCoherent = 1; + Data.Size = SIZE; /* Size in bytes */ + + XZDma_Start(&ZDma, &Data, 1); /* Initiates the data transfer */ + + while (Done == 0); /* Wait till DMA done interrupt generated */ + + /* Checking the data transferred */ + for (Index = 0; Index < SIZE/4; Index++) { + if (SrcBuf[Index] != DstBuf[Index]) { + return XST_FAILURE; + } + } + + return XST_SUCCESS; +} + +/*****************************************************************************/ +/** +* This function sets up the interrupt system so interrupts can occur for the +* ZDMA. This function is application-specific. The user should modify this +* function to fit the application. +* +* @param IntcInstancePtr is a pointer to the instance of the INTC. +* @param InstancePtr contains a pointer to the instance of the ZDMA +* driver which is going to be connected to the interrupt +* controller. +* @param IntrId is the interrupt Id and is typically +* XPAR__INTR value from xparameters.h. +* +* @return +* - XST_SUCCESS if successful +* - XST_FAILURE if failed +* +* @note None. + +* +****************************************************************************/ +int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XZDma *InstancePtr, + u16 IntrId) +{ + int Status; + +#ifndef TESTAPP_GEN + XScuGic_Config *IntcConfig; /* Config for interrupt controller */ + + /* + * Initialize the interrupt controller driver + */ + IntcConfig = XScuGic_LookupConfig(ZDMA_INTC_DEVICE_ID); + if (NULL == IntcConfig) { + return XST_FAILURE; + } + + Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, + IntcConfig->CpuBaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Connect the interrupt controller interrupt handler to the + * hardware interrupt handling logic in the processor. + */ + Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, + (Xil_ExceptionHandler) XScuGic_InterruptHandler, + IntcInstancePtr); +#endif + + /* + * Connect a device driver handler that will be called when an + * interrupt for the device occurs, the device driver handler + * performs the specific interrupt processing for the device + */ + Status = XScuGic_Connect(IntcInstancePtr, IntrId, + (Xil_ExceptionHandler) XZDma_IntrHandler, + (void *) InstancePtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Enable the interrupt for the device + */ + XScuGic_Enable(IntcInstancePtr, IntrId); + + + /* + * Enable interrupts + */ + Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ); + + + return XST_SUCCESS; +} + + +/*****************************************************************************/ +/** +* This static function handles ZDMA Done interrupts. +* +* @param CallBackRef is the callback reference passed from the interrupt +* handler, which in our case is a pointer to the driver instance. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void DoneHandler(void *CallBackRef) +{ + Done = 1; + +} diff --git a/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_writeonlymode_example.c b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_writeonlymode_example.c new file mode 100644 index 00000000..d14f4590 --- /dev/null +++ b/XilinxProcessorIPLib/drivers/zdma/examples/xzdma_writeonlymode_example.c @@ -0,0 +1,339 @@ +/****************************************************************************** +* +* Copyright (C) 2014 Xilinx, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* Use of the Software is limited solely to applications: +* (a) running on a Xilinx device, or +* (b) that interact with a Xilinx device through a bus or interconnect. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +* Except as contained in this notice, the name of the Xilinx shall not be used +* in advertising or otherwise to promote the sale, use or other dealings in +* this Software without prior written authorization from Xilinx. +* +******************************************************************************/ +/*****************************************************************************/ +/** +* +* @file xzdma_writeonlymode_example.c +* +* This file contains the example using XZDma driver to do simple data transfer +* in Write only mode on ZDMA device. In this mode data will be predefined +* and will be repetitively written into the given address and for given size. +* For ADMA only 2 words are repeated and for GDMA 4 words are repeated. +* +*
+* MODIFICATION HISTORY:
+*
+* Ver   Who     Date     Changes
+* ----- ------  -------- ------------------------------------------------------
+* 1.0   vns     2/27/15  First release
+* 
+* +******************************************************************************/ + +/***************************** Include Files *********************************/ + +#include "xzdma.h" +#include "xparameters.h" +#include "xscugic.h" + +/************************** Function Prototypes ******************************/ + +int XZDma_WriteOnlyExample(u16 DeviceId); +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XZDma *InstancePtr, u16 IntrId); +static void DoneHandler(void *CallBackRef); + +/************************** Constant Definitions ******************************/ + +/* + * The following constants map to the XPAR parameters created in the + * xparameters.h file. They are defined here such that a user can easily + * change all the needed parameters in one place. + */ +#define ZDMA_DEVICE_ID XPAR_XZDMA_0_DEVICE_ID /* ZDMA device Id */ +#define ZDMA_INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID + /**< SCUGIC Device ID */ +#define ZDMA_INTR_DEVICE_ID XPAR_XADMAPS_0_INTR /**< ZDMA Interrupt Id */ + +#define SIZE 1024 /* Size of the data to be written */ + +/**************************** Type Definitions *******************************/ + + +/************************** Variable Definitions *****************************/ + +XZDma ZDma; /**_DEVICE_ID value from +* xparameters.h. +* +* @return +* - XST_SUCCESS if successful. +* - XST_FAILURE if failed. +* +* @note None. +* +******************************************************************************/ +int XZDma_WriteOnlyExample(u16 DeviceId) +{ + int Status; + XZDma_Config *Config; + XZDma_DataConfig Configur; /**< Configuration values */ + XZDma_Transfer Data; + u32 *Buf = (u32 *)DstBuf; + u32 Index; + u32 Index1; + + /* + * Initialize the ZDMA driver so that it's ready to use. + * Look up the configuration in the config table, + * then initialize it. + */ + Config = XZDma_LookupConfig(DeviceId); + if (NULL == Config) { + return XST_FAILURE; + } + Status = XZDma_CfgInitialize(&ZDma, Config, Config->BaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + /* + * Performs the self-test to check hardware build. + */ + Status = XZDma_SelfTest(&ZDma); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* ZDMA has set in simple transfer of Normal mode */ + Status = XZDma_SetMode(&ZDma, FALSE, XZDMA_WRONLY_MODE); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + XZDma_EnableIntr(&ZDma, XZDMA_IXR_DMA_DONE_MASK); + /* + * Connect to the interrupt controller. + */ + Status = SetupInterruptSystem(&Intc, &(ZDma), + ZDMA_INTR_DEVICE_ID); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + (void)XZDma_SetCallBack(&ZDma, + XZDMA_HANDLER_DONE, (void *)(DoneHandler), + &ZDma); + /* Configuration settings */ + Configur.OverFetch = 0; + Configur.SrcIssue = 0x1F; + Configur.SrcBurstType = XZDMA_INCR_BURST; + Configur.SrcBurstLen = 0xF; + Configur.DstBurstType = XZDMA_INCR_BURST; + Configur.DstBurstLen = 0xF; + XZDma_SetChDataConfig(&ZDma, &Configur); + /* + * Transfer elements + */ + Data.DstAddr = (UINTPTR)DstBuf; + Data.DstCoherent = 0; + Data.Pause = 0; + Data.SrcAddr = (UINTPTR)NULL; + Data.SrcCoherent = 0; + Data.Size = SIZE; /* Size in bytes */ + + if (ZDma.Config.DmaType == 0) { /* For GDMA */ + SrcBuf[0] = 0x1234; + SrcBuf[1] = 0xABCD; + SrcBuf[2] = 0x4567; + SrcBuf[3] = 0xEF; + XZDma_WOData(&ZDma, SrcBuf); + } + else { /* For ADMA */ + SrcBuf[0] = 0x1234; + SrcBuf[1] = 0xABCD; + XZDma_WOData(&ZDma, SrcBuf); + } + + Xil_DCacheInvalidateRange((INTPTR)DstBuf, SIZE); + + XZDma_Start(&ZDma, &Data, 1); /* Initiates the data transfer */ + + /* Wait till DMA destination done interrupt generated */ + while (Done == 0); + + /* Validation */ + if (ZDma.Config.DmaType == 0) { /* For GDMA */ + for (Index = 0; Index < (SIZE/4)/4; Index++) { + for (Index1 = 0; Index1 < 4; Index1++) { + if (SrcBuf[Index1] != *Buf++) { + return XST_FAILURE; + } + } + } + } + else { /* For ADMA */ + for (Index = 0; Index < (SIZE/4)/2; Index++) { + for (Index1 = 0; Index1 < 2; Index1++) { + if (SrcBuf[Index1] != *Buf++) { + return XST_FAILURE; + } + } + } + } + +return XST_SUCCESS; + +} + +/*****************************************************************************/ +/** +* This function sets up the interrupt system so interrupts can occur for the +* ZDMA. This function is application-specific. The user should modify this +* function to fit the application. +* +* @param IntcInstancePtr is a pointer to the instance of the INTC. +* @param InstancePtr contains a pointer to the instance of the ZDMA +* driver which is going to be connected to the interrupt +* controller. +* @param IntrId is the interrupt Id and is typically +* XPAR__INTR value from xparameters.h. +* +* @return +* - XST_SUCCESS if successful +* - XST_FAILURE if failed +* +* @note None. + +* +****************************************************************************/ +static int SetupInterruptSystem(XScuGic *IntcInstancePtr, + XZDma *InstancePtr, u16 IntrId) +{ + int Status; + +#ifndef TESTAPP_GEN + XScuGic_Config *IntcConfig; /* Config for interrupt controller */ + + /* + * Initialize the interrupt controller driver + */ + IntcConfig = XScuGic_LookupConfig(ZDMA_INTC_DEVICE_ID); + if (NULL == IntcConfig) { + return XST_FAILURE; + } + + Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig, + IntcConfig->CpuBaseAddress); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Connect the interrupt controller interrupt handler to the + * hardware interrupt handling logic in the processor. + */ + Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, + (Xil_ExceptionHandler) XScuGic_InterruptHandler, + IntcInstancePtr); +#endif + + /* + * Connect a device driver handler that will be called when an + * interrupt for the device occurs, the device driver handler + * performs the specific interrupt processing for the device + */ + Status = XScuGic_Connect(IntcInstancePtr, IntrId, + (Xil_ExceptionHandler) XZDma_IntrHandler, + (void *) InstancePtr); + if (Status != XST_SUCCESS) { + return XST_FAILURE; + } + + /* + * Enable the interrupt for the device + */ + XScuGic_Enable(IntcInstancePtr, IntrId); + + + /* + * Enable interrupts + */ + Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ); + + + return XST_SUCCESS; +} + +/*****************************************************************************/ +/** +* This static function handles ZDMA Done interrupts. +* +* @param CallBackRef is the callback reference passed from the interrupt +* handler, which in our case is a pointer to the driver instance. +* @param Event specifies which interrupts were occurred. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void DoneHandler(void *CallBackRef) +{ + Done = 1; + +}