text: /******************************************************************************
  * Copyright (C) 2002 - 2020 Xilinx, Inc.  All rights reserved.
  * SPDX-License-Identifier: MIT
  ******************************************************************************/
  
  /******************************************************************************/
  /**
  * @file xiic_selftest_example.c
  *
  * This file contains a example for using the IIC hardware device and
  * XIic driver.
  *
  * @note
  *
  * None
  *
  * <pre>
  * MODIFICATION HISTORY:
  *
  * Ver   Who  Date	 Changes
  * ----- ---- -------- -----------------------------------------------
  * 1.00a sv   05/09/05 Initial release for TestApp integration.
  * 2.00a sdm  09/22/09 Updated to use the HAL APIs, replaced call to
  *		      XIic_Initialize API with XIic_LookupConfig and
  *		      XIic_CfgInitialize. Minor changes made as per
  *		      coding guidelines.
  * 3.4   ms   01/23/17 Added xil_printf statement in main function to
  *                     ensure that "Successfully ran" and "Failed" strings
  *                     are available in all examples. This is a fix for
  *                     CR-965028.
  * </pre>
  *
  *******************************************************************************/
  
  #include "xparameters.h"
  #include "xiic.h"
  #include "xil_printf.h"
  #ifdef SDT
  #include "xiic_example.h"
  #endif
  
  /************************** 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.
   */
  #ifndef SDT
  #ifndef TESTAPP_GEN
  #define IIC_DEVICE_ID	   XPAR_IIC_0_DEVICE_ID
  #endif
  #endif
  
  /**************************** Type Definitions ********************************/
  
  
  /***************** Macros (Inline Functions) Definitions **********************/
  
  
  /************************** Function Prototypes *******************************/
  #ifndef SDT
  int IicSelfTestExample(u16 DeviceId);
  #else
  int IicSelfTestExample(UINTPTR BaseAddress);
  #endif
  /************************** Variable Definitions ******************************/
  
  /*
   * The following are declared globally so they are zeroed and so they are
   * easily accessible from a debugger.
   */
  XIic Iic; /* The driver instance for IIC Device */
  
  
  /******************************************************************************/
  /**
  * Main function to call the example. This function is not included if the
  * example is generated from the TestAppGen test tool.
  *
  *
  * @return	XST_SUCCESS if successful, XST_FAILURE if unsuccessful.
  *
  * @note		None.
  *
  ******************************************************************************/
  #ifndef TESTAPP_GEN
  int main(void)
  {
  	int Status;
  
  	/*
  	 * Run the example, specify the device ID that is generated in
  	 * xparameters.h.
  	 */
  #ifndef SDT
  	Status = IicSelfTestExample(IIC_DEVICE_ID);
  #else
  	Status = IicSelfTestExample(XIIC_BASEADDRESS);
  #endif
  	if (Status != XST_SUCCESS) {
  		xil_printf("IIC selftest Example Failed\r\n");
  		return XST_FAILURE;
  	}
  
  	xil_printf("Successfully ran IIC selftest Example\r\n");
  	return XST_SUCCESS;
  
  }
  #endif
  
  /*****************************************************************************/
  /**
  *
  * This function does a selftest on the IIC device and XIic driver as an
  * example.
  *
  * @param	DeviceId is the XPAR_<IIC_instance>_DEVICE_ID value from
  *		xparameters.h.
  *
  * @return	XST_SUCCESS if successful, XST_FAILURE if unsuccessful.
  *
  * @note		None.
  *
  ****************************************************************************/
  #ifndef SDT
  int IicSelfTestExample(u16 DeviceId)
  #else
  int IicSelfTestExample(UINTPTR BaseAddress)
  #endif
  {
  	int Status;
  	XIic_Config *ConfigPtr;	/* Pointer to configuration data */
  
  	/*
  	 * Initialize the IIC driver so that it is ready to use.
  	 */
  #ifndef SDT
  	ConfigPtr = XIic_LookupConfig(DeviceId);
  #else
  	ConfigPtr = XIic_LookupConfig(BaseAddress);
  #endif
  	if (ConfigPtr == NULL) {
  		return XST_FAILURE;
  	}
  
  	Status = XIic_CfgInitialize(&Iic, ConfigPtr, ConfigPtr->BaseAddress);
  	if (Status != XST_SUCCESS) {
  		return XST_FAILURE;
  	}
  
  
  	/*
  	 * Perform a self-test to ensure that the hardware was built
  	 * correctly.
  	 */
  	Status = XIic_SelfTest(&Iic);
  	if (Status != XST_SUCCESS) {
  		return XST_FAILURE;
  	}
  
  	return XST_SUCCESS;
  }
  