Re: [myhdl-list] yield before the end of a simulation
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2011-12-23 14:49:02
|
On Tuesday, December 20, 2011, Oscar Diaz <osc...@gm...> wrote: > 2011/12/20 Christopher Felton <chr...@gm...>: >> On 12/20/2011 5:35 AM, Oscar Diaz wrote: >>> Hi >>> >>> I have a testbench that needs to do some asserts at the end of a >>> simulation. However, I couldn't find an elegant way to do it. Right >>> now I'm passing to the testbench generator the same duration as in >>> "Simulation.run(duration)" , so I can do a "yield delay(duration-1)" >>> and do the final asserts (by the way, in my case all my simulations >>> have a defined duration). I tried to catch the StopSimulation >>> exception, but it doesn't work inside a generator. Any ideas? Thanks! >>> >>> Best regards >>> >> >> I believe you can catch exceptions in generators. At least the >> generator PEP says so and the following works. >> >> ~~~ [Code Snip] ~~~ >> from myhdl import * >> def test(): >> @instance >> def ex_in_g(): >> try: >> for ii in xrange(10): >> yield delay(7) >> raise StopSimulation >> >> except Exception, e: >> print("Caught exception %s" % (str(e))) >> raise StopSimulation >> >> return ex_in_g >> >> if __name__ == '__main__': >> Simulation(test()).run() >> ~~~~~~~~~~~~~~~~~~~~~~~ > > That's the case when the exception is raised inside the generator, > which is not my case. I'm trying to something like this: > > ~~~ [Code Snip] ~~~ > from myhdl import * > def test(): > @instance > def ex_in_g(): > try: > for ii in xrange(10): > yield delay(7) > # ideally it shouldn't got here > return > > except Exception, e: > # or maybe better "except StopSimulation" ? > print("Caught exception %s" % (str(e))) > raise StopSimulation > > return ex_in_g > > if __name__ == '__main__': > # fixed simulation time > Simulation(test()).run(50) > ~~~~~~~~~~~~~~~~~~~~~~~ > > It doesn't work because the exception is raised inside the run() > method. Right now my project store the simulation duration to yield > before raising StopSimulation, like this: > ~~~ [Code Snip] ~~~ > from myhdl import * > sim_duration = 100 > def test(): > @instance > def main_block(): > # do some stuff > return > > @instance > def last_check(): > yield delay(sim_duration - 1) > print "do some final asserts..." > return > > return instances() > > if __name__ == '__main__': > Simulation(test()).run(sim_duration) > ~~~~~~~~~~~~~~~~~~~~~~~ > > Any ideas to improve this issue? > > Best regards > >> >> Regards, >> Chris >> >> Another option you could try is to run the simulation from the test function. After the simulation completes the final state is preserved and you can do the final checks. I haven't tried it. In the above example, the test function you could do the following. Def test(): ... Simulation((ex_in_g)).run() #checks # nothing to return Regards, Chris |