iicps
Xilinx Vitis Drivers API Documentation
iicps Documentation

This is an implementation of IIC driver in the PS block. The device can be either a master or a slave on the IIC bus. This implementation supports both interrupt mode transfer and polled mode transfer. Only 7-bit address is used in the driver, although the hardware also supports 10-bit address.

IIC is a 2-wire serial interface. The master controls the clock, so it can regulate when it wants to send or receive data. The slave is under control of the master, it must respond quickly since it has no control of the clock and must send/receive data as fast or as slow as the master does.

The higher level software must implement a higher layer protocol to inform the slave what to send to the master.

Initialization & Configuration

The XIicPs_Config structure is used by the driver to configure itself. This configuration structure is typically created by the tool-chain based on HW build properties.

To support multiple runtime loading and initialization strategies employed by various operating systems, the driver instance can be initialized in the following way:

  • XIicPs_LookupConfig(DeviceId) - Use the device identifier to find the static configuration structure defined in xiicps_g.c. This is setup by the tools. For some operating systems the config structure will be initialized by the software and this call is not needed.
  • XIicPs_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddr) - Uses a configuration structure provided by the caller. If running in a system with address translation, the provided virtual memory base address replaces the physical address in the configuration structure.

Multiple Masters

More than one master can exist, bus arbitration is defined in the IIC standard. Lost of arbitration causes arbitration loss interrupt on the device.

Multiple Slaves

Multiple slaves are supported by selecting them with unique addresses. It is up to the system designer to be sure all devices on the IIC bus have unique addresses.

Addressing

The IIC hardware can use 7 or 10 bit addresses. The driver provides the ability to control which address size is sent in messages as a master to a slave device.

FIFO Size The hardware FIFO is 32 bytes deep. The user must know the limitations of other IIC devices on the bus. Some are only able to receive a limited number of bytes in a single transfer.

Data Rates

The data rate is set by values in the control register. The formula for determining the correct register values is: Fscl = Fpclk/(22 x (divisor_a+1) x (divisor_b+1))

When the device is configured as a slave, the slck setting controls the sample rate and so must be set to be at least as fast as the fastest scl expected to be seen in the system.

Polled Mode Operation

This driver supports polled mode transfers.

Interrupts

The user must connect the interrupt handler of the driver, XIicPs_InterruptHandler to an interrupt system such that it will be called when an interrupt occurs. This function does not save and restore the processor context such that the user must provide this processing.

The driver handles the following interrupts:

  • Transfer complete
  • More Data
  • Transfer not Acknowledged
  • Transfer Time out
  • Monitored slave ready - master mode only
  • Receive Overflow
  • Transmit FIFO overflow
  • Receive FIFO underflow
  • Arbitration lost

Bus Busy

Bus busy is checked before the setup of a master mode device, to avoid unnecessary arbitration loss interrupt.

RTOS Independence

This driver is intended to be RTOS and processor independent. It works with physical addresses only. Any needs for dynamic memory management, threads or thread mutual exclusion, virtual memory, or cache control must be satisfied by the layer above this driver.

Repeated Start

The I2C controller does not indicate completion of a receive transfer if HOLD bit is set. Due to this errata, repeated start cannot be used if a receive transfer is followed by any other transfer.

 MODIFICATION HISTORY:
 Ver   Who     Date     Changes


1.00a drg/jz 01/30/08 First release 1.00a sdm 09/21/11 Fixed an issue in the XIicPs_SetOptions and XIicPs_ClearOptions where the InstancePtr->Options was not updated correctly. Updated the InstancePtr->Options in the XIicPs_CfgInitialize by calling XIicPs_GetOptions. Updated the XIicPs_SetupMaster to not check for Bus Busy condition when the Hold Bit is set. Removed some unused variables. 1.01a sg 03/30/12 Fixed an issue in XIicPs_MasterSendPolled where a check for transfer completion is added, which indicates the completion of current transfer. 1.02a sg 08/29/12 Updated the logic to arrive at the best divisors to achieve I2C clock with minimum error for CR #674195 1.03a hk 05/04/13 Initialized BestDivA and BestDivB to 0. This is fix for CR#704398 to remove warning. 2.0 hk 03/07/14 Added check for error status in the while loop that checks for completion. (XIicPs_MasterSendPolled function). CR# 762244, 764875. Limited frequency set when 100KHz or 400KHz is selected. This is a hardware limitation. CR#779290. 2.1 hk 04/24/14 Fix for CR# 789821 to handle >14 byte transfers. Explicitly reset CR and clear FIFO in Abort function and state the same in the comments. CR# 784254. Fix for CR# 761060 - provision for repeated start. 2.2 hk 08/23/14 Slave monitor mode changes - clear FIFO, enable read mode and clear transfer size register. Disable NACK to avoid interrupts on each retry. 2.3 sk 10/07/14 Repeated start feature deleted. 3.0 sk 11/03/14 Modified TimeOut Register value to 0xFF in XIicPs_Reset. 12/06/14 Implemented Repeated start feature. 01/31/15 Modified the code according to MISRAC 2012 Compliant. 02/18/15 Implemented larger data transfer using repeated start in Zynq UltraScale MP. 3.3 kvn 05/05/16 Modified latest code for MISRA-C:2012 Compliance. ms 03/17/17 Added readme.txt file in examples folder for doxygen generation. 3.7 ask 04/17/18 Updated the Eeprom scanning mechanism as per the other examples (CR#997545) 3.8 ask 08/01/18 Fix for Cppcheck and Doxygen warnings 3.8 sd 09/06/18 Enable the Timeout interrupt 3.9 sg 03/09/19 Added arbitration lost support in polled transfer 3.11 rna 12/23/19 Added 10 bit address support for Master/Slave 3.11 sd 02/06/20 Added clocking support. 3.11 rna 02/20/20 Reorganization of driver for modularity. Added new files xiicps_xfer.c and xiicps_xfer.h. Moved internal data transfer APIs to xiicps_xfer.