Re: [myhdl-list] yield before the end of a simulation
Brought to you by:
jandecaluwe
From: Oscar D. <osc...@gm...> - 2011-12-20 13:55:12
|
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 > > > ------------------------------------------------------------------------------ > Write once. Port to many. > Get the SDK and tools to simplify cross-platform app development. Create > new or port existing apps to sell to consumers worldwide. Explore the > Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join > http://p.sf.net/sfu/intel-appdev > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list -- Oscar Díaz Key Fingerprint = 904B 306C C3C2 7487 650B BFAC EDA2 B702 90E9 9964 gpg --keyserver subkeys.pgp.net --recv-keys 90E99964 I recommend using OpenDocument Format for daily use and exchange of documents. http://www.fsf.org/campaigns/opendocument |