int ProgramSi5324(void) { XIIC_LIB I2cLibInstance; int Index; int Status; u8 WrBuffer[2]; Status = I2cSetupHardware(&I2cLibInstance); if (Status != XST_SUCCESS) { xil_printf("Si5324: Configuring HW failed\n\r"); return XST_FAILURE; } Status = MuxInit(&I2cLibInstance); if (Status != XST_SUCCESS) { xil_printf("Si5324: Mux Init failed\n\r"); return XST_FAILURE; } for (Index = 0; Index < sizeof(InitTable)/8; Index++) { WrBuffer[0] = InitTable[Index].RegIndex; WrBuffer[1] = InitTable[Index].Value; Status = I2cWriteData(&I2cLibInstance, WrBuffer, 2, IIC_SLAVE_ADDR); if (Status != XST_SUCCESS) { xil_printf("Si5324: Writing failed\n\r"); return XST_FAILURE; } } return XST_SUCCESS; }
/************************** Function Definitions *****************************/ int MuxInit(XIIC_LIB *I2cLibInstancePtr) { u8 WrBuffer[0]; int Status; WrBuffer[0] = IIC_CHANNEL_ADDRESS; Status = I2cWriteData(I2cLibInstancePtr, WrBuffer, 1, IIC_MUX_ADDRESS); if (Status != XST_SUCCESS) { xil_printf("Si5324: Writing failed\n\r"); return XST_FAILURE; } return XST_SUCCESS; }
/** * This function writes data to the PHY. * * @param I2cLibPtr contains a pointer to the instance of the IIC library * @param PhyAddr is the address of PHY to be written * @param Reg is the register address to be written to * @param Data is the pointer which contains the data to be written * @param SlaveAddr is the address of the slave we are sending to. * * @return XST_SUCCESS if successful else XST_FAILURE. * ******************************************************************************/ int I2cPhyWrite(XIIC_LIB *I2cLibPtr, u8 PhyAddr, u8 Reg, u16 Data, u16 SlaveAddr) { int Status; u8 WrBuffer[3]; WrBuffer[0] = Reg; WrBuffer[1] = Data >> 8; WrBuffer[2] = Data; Status = I2cWriteData(I2cLibPtr, WrBuffer, 3, SlaveAddr); if (Status != XST_SUCCESS) { xil_printf("PhyWrite: Writing data failed\n\r"); return Status; } return Status; }
/** * This function reads data from the PHY. * * @param I2cLibPtr contains a pointer to the instance of the IIC library * @param PhyAddr is the address of PHY to be read from * @param Reg is the register address to be read from * @param Data is the pointer which stores the data read * @param SlaveAddr is the address of the slave we are sending to. * * @return XST_SUCCESS if successful else XST_FAILURE. * ******************************************************************************/ int I2cPhyRead(XIIC_LIB *I2cLibPtr, u8 PhyAddr, u8 Reg, u16 *Data, u16 SlaveAddr) { int Status; u8 WrBuffer[2]; u8 RdBuffer[2]; WrBuffer[0] = Reg; Status = I2cWriteData(I2cLibPtr, WrBuffer, 1, SlaveAddr); if (Status != XST_SUCCESS) { xil_printf("PhyWrite: Writing data failed\n\r"); return Status; } Status = I2cReadData(I2cLibPtr, RdBuffer, 2, SlaveAddr); if (Status != XST_SUCCESS) { xil_printf("PhyRead: Reading data failed\n\r"); return Status; } *Data = RdBuffer[0] << 8 | RdBuffer[1]; return Status; }