Py4Hw User Guide> 5.1 The Simulator¶

Next: 5.2 Scopes¶

The simulator can be obtained from the HWSystem.

The current simulator is implemented as a cycle based simulator. You basically call the method clk to advance the number of clocks you want.

In [1]:
import py4hw

sys = py4hw.HWSystem()
sim = sys.getSimulator()
sim.clk(1)

The simulator object has the following fields and methods

Field Description
total_clks The number of clocks run from the initial time of the session
sys The HWSystem associated with the simulator
listeners A list of the objects that listen to simulator events
Method Description
init Constructor
propagateAll Propagates all combinational circuits
topologicalSort We segment the circuit by clock drivers. Sorts all the elements of the circuit so that cycle-base simulation is possible. Clockables do not require any order. Propagatables must be sorted in propagation order, so when we insert we should check if there are elements in the list that depend on the current item, and in this case we should place it before them
getOrCreateClockDriverSimulator get a clock driver simulator
findFirstDependentPosition We look at the outputs of the provided circuit and find all the dependent cells, then we locate them in
clk Advance a number of clock cycles
_clk_cycle Advance one clock cycle
stop Stop the simulation
addListener Add a listener of the simulator events
_notifyListeners Notify the listeners of a simulator event

Summary¶

  • There is a singleton object that implements the Simulator which is attached to HWSystem
  • The simulator is a cycle-based simulator