Update Timer so it doesn't call into the simulator
@@ -33,7 +33,7 @@ from collections.abc import Awaitable
from cocotb import simulator
from cocotb.log import SimLog
from cocotb.utils import (
- get_sim_steps, get_time_from_sim_steps, ParametrizedSingleton,
+ get_sim_steps, ParametrizedSingleton,
lazy_property, remove_traceback_frames,
)
from cocotb import outcomes
@@ -196,7 +196,13 @@ class Timer(GPITrigger):
:func:`~cocotb.utils.get_sim_steps`
"""
GPITrigger.__init__(self)
- self.sim_steps = get_sim_steps(time_ps, units)
+ self._time_ps = time_ps
+ self._units = units
+
+ @lazy_property
+ def sim_steps(self):
+ # lazy so we don't call into the simulator until we need to
+ return get_sim_steps(self._time_ps, self._units)
def prime(self, callback):
"""Register for a timed callback."""
@@ -208,9 +214,10 @@ class Timer(GPITrigger):
GPITrigger.prime(self, callback)
def __repr__(self):
- return "<{} of {:1.2f}ps at {}>".format(
+ return "<{} of {:1.2f}{} at {}>".format(
type(self).__qualname__,
- get_time_from_sim_steps(self.sim_steps, units='ps'),
+ self._time_ps,
+ self._units,
_pointer_str(self)
)
