Examples Folder in Drivers - 2023.2 English

Porting Guide for embeddedsw Components System Device Tree Based Build Flow (UG1647)

Document ID
UG1647
Release Date
2023-11-10
Version
2023.2 English

The following changes are required in the examples folder:

  • Update the LookUp_Config API in all the driver examples to use BaseAddress instead of DeviceID.
  • In the system device tree based flow, interrupt registration has been simplified and simpler APIs are provided to offload interrupt registration process. Therefore, all references to interrupt handling in the example must be removed.
    • Use XSetupInterruptSystem() for registering the driver/application handler and XDisconnectInterruptCntrl for disabling interrupts.
    • Add interrupts and interrupt-parent fields to the driver *_Config structure.
    Refer to the changes in the following xcsudma_intr_example.c file for more information.

Sample changes for porting CSUDMA driver examples:

--- a/XilinxProcessorIPLib/drivers/csudma/data/csudma.yaml
+++ b/XilinxProcessorIPLib/drivers/csudma/data/csudma.yaml
@@ -31,4 +31,12 @@ required:
     - xlnx,dma-type
     - interrupts
     - interrupt-parent
+
+examples:
+    xcsudma_intr_example.c:
+        - interrupts
+    xcsudma_polled_example.c:
+        - reg
+    xcsudma_selftest_example.c:
+        - reg
--- a/XilinxProcessorIPLib/drivers/csudma/examples/
+++ b/XilinxProcessorIPLib/drivers/csudma/examples/xcsudma_intr_example.c
@@ -35,6 +35,7 @@
 * 1.9  sk     12/23/20 Add the documentation for XCsuDma_IntrExample() function
 *          parameters to fix the doxygen warning.
 * 1.11 sk     12/20/21 Add interrupt device id support for A78 and R52 processors.
+* 1.14  adk    05/04/23 Added support for system device-tree flow.
 * </pre>
 *
 ******************************************************************************/
@@ -44,11 +45,15 @@
 #include "xcsudma.h"
 #include "xparameters.h"
 #include "xil_exception.h"
+#ifndef SDT
 #ifdef XPAR_INTC_0_DEVICE_ID
 #include "xintc.h"
 #else
 #include "xscugic.h"
 #endif
+#else
+#include "xinterrupt_wrap.h"
+#endif
 
 /************************** Function Prototypes ******************************/
 
@@ -57,6 +62,7 @@
  * xparameters.h file. They are defined here such that a user can easily
  * change all the needed parameters in one place.
  */
+#ifndef SDT
 #define CSUDMA_DEVICE_ID  XPAR_XCSUDMA_0_DEVICE_ID /* CSU DMA device Id */
 #ifdef XPAR_INTC_0_DEVICE_ID
 #define INTC       XIntc
@@ -81,6 +87,9 @@
                         *  of CSU DMA device ID */
 #endif
 #endif
+#else
+#define CSUDMA_BASEADDR            XPAR_XCSUDMA_0_BASEADDR /* CSU DMA base address */
+#endif
 
 #define CSU_SSS_CONFIG_OFFSET  0x008       /**< CSU SSS_CFG Offset */
 #define CSUDMA_LOOPBACK_CFG    0x00000050  /**< LOOP BACK configuration
@@ -110,11 +119,15 @@ u32 SrcBuf[SIZE] __attribute__ ((aligned (64)));  /**< Source buffer */
 
 /************************** Function Prototypes ******************************/
 
+#ifndef SDT
 int XCsuDma_IntrExample(INTC *IntcInstancePtr, XCsuDma *CsuDmaInstance,
            u16 DeviceId, u16 IntrId);
 static int SetupInterruptSystem(INTC *IntcInstancePtr,
                XCsuDma *CsuDmaInstance,
                u16 CsuDmaIntrId);
+#else
+int XCsuDma_IntrExample(XCsuDma *CsuDmaInstance, UINTPTR BaseAddress);
+#endif
 void IntrHandler(void *CallBackRef);
 
 static void SrcHandler(void *CallBackRef, u32 Event);
@@ -124,8 +137,10 @@ static void DstHandler(void *CallBackRef, u32 Event);
 
 #ifndef TESTAPP_GEN
 XCsuDma CsuDma;        /**<Instance of the Csu_Dma Device */
+#ifndef SDT
 static INTC Intc;  /* Instance of the Interrupt Controller */
 #endif
+#endif
 volatile u32 DstDone = 0;
 
 #ifndef TESTAPP_GEN
@@ -146,8 +161,12 @@ int main(void)
    int Status;
 
    /* Run the selftest example */
+#ifndef SDT
    Status = XCsuDma_IntrExample(&Intc, &CsuDma, (u16)CSUDMA_DEVICE_ID,
                     INTG_CSUDMA_INTR_DEVICE_ID);
+#else
+   Status = XCsuDma_IntrExample(&CsuDma, CSUDMA_BASEADDR);
+#endif
    if (Status != XST_SUCCESS) {
        xil_printf("CSU_DMA Interrupt Example Failed\r\n");
        return XST_FAILURE;
@@ -178,8 +197,12 @@ int main(void)
 * @note        None.
 *
 ******************************************************************************/
+#ifndef SDT
 int XCsuDma_IntrExample(INTC *IntcInstancePtr, XCsuDma *CsuDmaInstance,
            u16 DeviceId, u16 IntrId)
+#else
+int XCsuDma_IntrExample(XCsuDma *CsuDmaInstance, UINTPTR BaseAddress)
+#endif
 {
    int Status;
    XCsuDma_Config *Config;
@@ -194,7 +217,11 @@ int XCsuDma_IntrExample(INTC *IntcInstancePtr, XCsuDma *CsuDmaInstance,
     * look up the configuration in the config table,
     * then initialize it.
     */
+#ifndef SDT
    Config = XCsuDma_LookupConfig(DeviceId);
+#else
+   Config = XCsuDma_LookupConfig(BaseAddress);
+#endif
    if (NULL == Config) {
        return XST_FAILURE;
    }
@@ -221,8 +248,15 @@ int XCsuDma_IntrExample(INTC *IntcInstancePtr, XCsuDma *CsuDmaInstance,
    /*
     * Connect to the interrupt controller.
     */
+#ifndef SDT
    Status = SetupInterruptSystem(IntcInstancePtr, CsuDmaInstance,
                      IntrId);
+#else
+   Status = XSetupInterruptSystem(CsuDmaInstance, &IntrHandler,
+                      CsuDmaInstance->Config.IntrId,
+                      CsuDmaInstance->Config.IntrParent,
+                      XINTERRUPT_DEFAULT_PRIORITY);
+#endif
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }
@@ -311,6 +345,7 @@ int XCsuDma_IntrExample(INTC *IntcInstancePtr, XCsuDma *CsuDmaInstance,
 
 *
 ****************************************************************************/
+#ifndef SDT
 static int SetupInterruptSystem(INTC *IntcInstancePtr,
                XCsuDma *InstancePtr,
                u16 IntrId)
@@ -415,7 +450,7 @@ static int SetupInterruptSystem(INTC *IntcInstancePtr,
    return XST_SUCCESS;
 }
 
-
+#endif
--- a/XilinxProcessorIPLib/drivers/csudma/examples/xcsudma_polled_example.c
+++ b/XilinxProcessorIPLib/drivers/csudma/examples/xcsudma_polled_example.c
@@ -22,6 +22,7 @@
 * ----- ------  -------- -----------------------------------------------------
 * 1.0   vnsld   22/10/14 First release
 * 1.4   adk     04/12/17 Added support for PMC DMA.
+* 1.14  adk     04/05/23 Added support for system device-tree flow.
 * </pre>
 *
 ******************************************************************************/
@@ -38,7 +39,11 @@
  * xparameters.h file. They are defined here such that a user can easily
  * change all the needed parameters in one place.
  */
+#ifndef SDT
 #define CSUDMA_DEVICE_ID   XPAR_XCSUDMA_0_DEVICE_ID /* CSU DMA device Id */
+#else
+#define CSUDMA_BASEADDR        XPAR_XCSUDMA_0_BASEADDR /* CSU DMA Baseaddress */
+#endif
 #define CSU_SSS_CONFIG_OFFSET  0x008       /**< CSU SSS_CFG Offset */
 #define CSUDMA_LOOPBACK_CFG    0x00000050  /**< LOOP BACK configuration
                          *  macro */
@@ -61,7 +66,11 @@
 /************************** Function Prototypes ******************************/
 
 
+#ifndef SDT
 int XCsuDma_PolledExample(u16 DeviceId);
+#else
+int XCsuDma_PolledExample(UINTPTR BaseAddress);
+#endif
 
 /************************** Variable Definitions *****************************/
 
@@ -84,7 +93,11 @@ int main(void)
    int Status;
 
    /* Run the selftest example */
+#ifndef SDT
    Status = XCsuDma_PolledExample((u16)CSUDMA_DEVICE_ID);
+#else
+   Status = XCsuDma_PolledExample(CSUDMA_BASEADDR);
+#endif
    if (Status != XST_SUCCESS) {
        xil_printf("CSU_DMA Polled Example Failed\r\n");
        return XST_FAILURE;
@@ -110,7 +123,11 @@ int main(void)
 * @note        None.
 *
 ******************************************************************************/
+#ifndef SDT
 int XCsuDma_PolledExample(u16 DeviceId)
+#else
+int XCsuDma_PolledExample(UINTPTR BaseAddress)
+#endif
 {
    int Status;
    XCsuDma_Config *Config;
@@ -125,7 +142,11 @@ int XCsuDma_PolledExample(u16 DeviceId)
     * look up the configuration in the config table,
     * then initialize it.
     */
+#ifndef SDT
    Config = XCsuDma_LookupConfig(DeviceId);
+#else
+   Config = XCsuDma_LookupConfig(BaseAddress);
+#endif
--- a/XilinxProcessorIPLib/drivers/csudma/examples/xcsudma_selftest_example.c
+++ b/XilinxProcessorIPLib/drivers/csudma/examples/xcsudma_selftest_example.c
@@ -22,6 +22,7 @@
 *       ms     04/10/17 Modified filename tag to include the file in doxygen
 *                       examples.
 * 1.2   adk    11/22/17 Added peripheral test app support.
+* 1.14  adk    05/04/23 Added support for system device-tree flow.
 * </pre>
 *
 ******************************************************************************/
@@ -38,7 +39,11 @@
  * xparameters.h file. They are defined here such that a user can easily
  * change all the needed parameters in one place.
  */
+#ifndef SDT
 #define CSUDMA_DEVICE_ID  XPAR_XCSUDMA_0_DEVICE_ID /* CSU DMA device Id */
+#else
+#define CSUDMA_BASEADDR    XPAR_XCSUDMA_0_BASEADDR /* CSU DMA base address */
+#endif
 
 /**************************** Type Definitions *******************************/
 
@@ -48,7 +53,11 @@
 /************************** Function Prototypes ******************************/
 
 
+#ifndef SDT
 int XCsuDma_SelfTestExample(u16 DeviceId);
+#else
+int XCsuDma_SelfTestExample(UINTPTR BaseAddress);
+#endif
 
 /************************** Variable Definitions *****************************/
 
@@ -72,7 +81,11 @@ int main(void)
    int Status;
 
    /* Run the selftest example */
+#ifndef SDT
    Status = XCsuDma_SelfTestExample((u16)CSUDMA_DEVICE_ID);
+#else
+   Status = XCsuDma_SelfTestExample(CSUDMA_BASEADDR);
+#endif
    if (Status != XST_SUCCESS) {
        xil_printf("CSU_DMA Selftest Example Failed\r\n");
        return XST_FAILURE;
@@ -99,7 +112,11 @@ int main(void)
 * @note        None.
 *
 ******************************************************************************/
+#ifndef SDT
 int XCsuDma_SelfTestExample(u16 DeviceId)
+#else
+int XCsuDma_SelfTestExample(UINTPTR BaseAddress)
+#endif
 {
    int Status;
    XCsuDma_Config *Config;
@@ -109,7 +126,11 @@ int XCsuDma_SelfTestExample(u16 DeviceId)
     * look up the configuration in the config table,
     * then initialize it.
     */
+#ifndef SDT
    Config = XCsuDma_LookupConfig(DeviceId);
+#else
+   Config = XCsuDma_LookupConfig(BaseAddress);
+#endif
    if (NULL == Config) {
        return XST_FAILURE;
    }