/** * * Initializes a specific XIicPs instance such that the driver is ready to use. * * The state of the device after initialization is: * - Device is disabled * - Slave mode * * @param InstancePtr is a pointer to the XIicPs instance. * @param ConfigPtr is a reference to a structure containing information * about a specific IIC device. This function initializes an * InstancePtr object for a specific device specified by the * contents of Config. * @param EffectiveAddr is the device base address in the virtual memory * address space. The caller is responsible for keeping the address * mapping from EffectiveAddr to the device physical base address * unchanged once this function is invoked. Unexpected errors may * occur if the address mapping changes after this function is * called. If address translation is not used, use * ConfigPtr->BaseAddress for this parameter, passing the physical * address instead. * * @return The return value is XST_SUCCESS if successful. * * @note None. * ******************************************************************************/ int XIicPs_CfgInitialize(XIicPs *InstancePtr, XIicPs_Config *ConfigPtr, u32 EffectiveAddr) { /* * Assert validates the input arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(ConfigPtr != NULL); /* * Set some default values. */ InstancePtr->Config.DeviceId = ConfigPtr->DeviceId; InstancePtr->Config.BaseAddress = EffectiveAddr; InstancePtr->Config.InputClockHz = ConfigPtr->InputClockHz; InstancePtr->StatusHandler = StubHandler; InstancePtr->CallBackRef = NULL; InstancePtr->IsReady = XIL_COMPONENT_IS_READY; /* * Reset the IIC device to get it into its initial state. It is expected * that device configuration will take place after this initialization * is done, but before the device is started. */ XIicPs_Reset(InstancePtr); /* * Keep a copy of what options this instance has. */ InstancePtr->Options = XIicPs_GetOptions(InstancePtr); return XST_SUCCESS; }
/** * * Runs a self-test on the driver/device. The self-test is destructive in that * a reset of the device is performed in order to check the reset values of * the registers and to get the device into a known state. * * Upon successful return from the self-test, the device is reset. * * @param InstancePtr is a pointer to the XIicPs instance. * * @return * - XST_SUCCESS if successful. * - XST_REGISTER_ERROR indicates a register did not read or write * correctly * * @note None. * ******************************************************************************/ int XIicPs_SelfTest(XIicPs *InstancePtr) { Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); /* * All the IIC registers should be in their default state right now. */ if ((XIICPS_CR_RESET_VALUE != XIicPs_ReadReg(InstancePtr->Config.BaseAddress, XIICPS_CR_OFFSET)) || (XIICPS_TO_RESET_VALUE != XIicPs_ReadReg(InstancePtr->Config.BaseAddress, XIICPS_TIME_OUT_OFFSET)) || (XIICPS_IXR_ALL_INTR_MASK != XIicPs_ReadReg(InstancePtr->Config.BaseAddress, XIICPS_IMR_OFFSET))) { return XST_FAILURE; } XIicPs_Reset(InstancePtr); /* * Write, Read then write a register */ XIicPs_WriteReg(InstancePtr->Config.BaseAddress, XIICPS_SLV_PAUSE_OFFSET, REG_TEST_VALUE); if (REG_TEST_VALUE != XIicPs_ReadReg(InstancePtr->Config.BaseAddress, XIICPS_SLV_PAUSE_OFFSET)) { return XST_FAILURE; } XIicPs_WriteReg(InstancePtr->Config.BaseAddress, XIICPS_SLV_PAUSE_OFFSET, 0); XIicPs_Reset(InstancePtr); return XST_SUCCESS; }