[myhdl-list] Signal initialization
Brought to you by:
jandecaluwe
From: David B. <dav...@fr...> - 2004-10-26 07:32:50
|
There is another issue that I would like to bring up. In the following co= de: ------------------------------------------------------------- from myhdl import intbv, Signal, Simulation, instances, delay def test(a, b, c): while 1: yield a, b c.next =3D a.val + b.val print "Test function executed" def a_gen(a): while 1: yield delay(10) a.next =3D 0 def top(): a =3D Signal(intbv(0)) b =3D Signal(intbv(1)) c =3D Signal(intbv()) a_gen_i =3D a_gen(a) test_i =3D test(a, b, c) return instances() top_inst =3D top() sim =3D Simulation(top_inst) sim.run(100) ------------------------------------------------------------- The "test" function is never executed, because "a" and "b" never change t= heir value (always 0 and 1 respectively). It means that if another function us= es the "c" output value of "test", it will be wrong. A workaround would be to initialize "a" like this: a =3D Signal(intbv(None)) So that "a" changes its value in the "a_gen" function. But then I found o= ut that in the general case it causes too many problems because some inputs might= not be initialized (still at "None") when the code is executed, resulting in an = error. We can solve this by executing the code only if all the input values are different than "None". Writing this condition after every "yield" stateme= nt is not very beautiful (maybe MyHDL could resume the function only if all the= input values are different than "None"?). Another workaround would be to initialize "a" like that: a =3D Signal(intbv(0)) and writing "test" with the "yield" statement at the end: def test(a, b, c): while 1: c.next =3D a.val + b.val print "Test function executed" yield a, b This way, "test" is always executed at least once. I don't know if "alway= s_comb" corresponds to this configuration though. David. |