Electrical – How to verify a VHDL I2C master


Once an I2C master has been written, the next step is verification. Provided that a BFM for the slave does not exist, how should one go about doing this? Also seeing how I2C is open collector in nature.

Of course in any I2C transaction, the master would transmit the start condition, address, r/w bit and slave would transfer an ACK and so on and so forth. Is there a "standard" testbench for this? I would expect there to be code with flexibility to create BFM for our slave with some modification and then do self checks to verify if our master is working correctly.

Please don't tell me to use an open source I2C master. The purpose of this question is to understand how to do this.

Best Answer

You need to start by determining exactly what it is you want to "verify".

Obviously, I2C is a simple protocol, and writing a monitor that verifies that the protocol is not being violated (including timing measurements, if desired1) is a relatively straightforward matter.

But anything beyond that — including whether the master is accessing the correct addresses, writing the correct data, responding correctly to the data it reads and handling any exceptions that occur — is all very much application-dependent, and generally requires a BFM for the specific slave device(s) in your system.

For example, I once needed to verify a system that included a soft-core CPU, in which I needed to allow it to execute the code that initialized a TI C1101 radio chip (through its SPI interface) in order to get to the message-processing code. I wrote a bare-bones ad-hoc BFM for the C1101 slave interface that implemented just enough functionality to accomplish that.

1 The VHDL function now (returning type time) gives the current simulation time. You can use this to directly measure the time between important events. For example, you keep one variable that gets set to now on every data edge, and when you get a clock edge, the difference between now and that variable is the setup time. A similar technique measures hold time. Here is some sample code relating to now.