Re: [myhdl-list] Calling regular python code during simulation
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2012-01-19 10:15:31
|
On 1/18/12 6:35 AM, Matti wrote: > I want to do something like this: > > def myfunc(data): > return float(data) > > def Int2Float(inval, outval, clock): > @always(clock.posedge) > def Int2FloatLogic(): > out.next = myfunc(data) > return instances > > Of course this will not pass the convertor. But I would like to use it in > simulation, and at a later date replace the float() call with an appropriate > vendor-supplied library. In the real example myfunc is more complicated. > Questions: > - How can I get the simulator to just execute the python code without trying to > convert it to myhdl primitives? > - How do I tell the simulator that myfunc requires 28 clock cycles? > > Thanks, > Matti > As you elude, you can use any valid Python in simulation (this is why any other HDL language is extinct for verification!). In Python speak you want to create a generator that can be passed to the MyHDL simulation engine. Your example would be valid other than it does not have the 28 clock cycle delay. You could add a counter to count clock cycles or you could use the delay (@always(delay(28*CLK_SIM_STEPS))). By using the delay in the @always decorator your generator will only execute the specified number of simulation steps. Another, slightly more flexible, way to write generators is like the following. def mod(): @instance def tb_model(): # Init variables while(True): out.next = myfunc(data) yield delay(28*CLK_SIM_STEPS) # can do some more # ... In the above form, you have a little more flexibility but you have to be more explicit. It doesn't "feel" as hardware description as the decorators (@always, @always_comb). In the above you can use the delay or you can use a "variable" as a counter. Hope that helps, Chris |