IP Modeling
Besides support for connectivity, the System Mock also provides several C++ interfaces to define software models that mimic behaviors of hardware components. As mentioned earlier, these models are known as IP mocks. In an IP mock, you can implement IP’s functionality and establish the expected handshake with the Nios® II software. System Mock instantiates and maintains all IP mocks. When System Mock intercepts a Nios® II Avalon® memory-mapped interface memory access, it goes through a list of IP mocks and passes the memory access to the appropriate IP mock. Then, this IP mock responds to the Nios® II memory access accordingly. In addition, System Mock keeps lists of user-defined pre-read, post-read, pre-write, and post-write callback functions. By calling those functions, System Mock can inject events before or after passing on the memory access to IP mock.
To illustrate this further, take an example of a Crypto IP, which provides cryptographic services in an FPGA design. This Crypto IP has a control and status registers (CSR) interface. Beneath this communication interface, there is a state machine to deal with requests and responses. This IP also has core algorithms to perform cryptographic functions such as hashing. In the mock module for this Crypto IP, developers can define the same CSR interface and use switch statements to represent the state machine. For the cryptographic functions, developers can call OpenSSL C++ library APIs to implement the same functionality. From Nios® II code’s perspective, interaction with this IP mock is the same as with the actual Crypto IP.
It can be a big overhead to implement IP mocks for all hardware components in an FPGA design. Developers can choose to only implement the relevant features to cut down this overhead. IPs are usually designed to support a wide range of use cases. For example, a flash memory IP can support many configuration settings and hundreds of commands. But a Nios® II software may only send read, write, and erase commands in a particular mode. Developers can focus on implementing these commands and flash mode in their flash memory IP mock.