Thread: [myhdl-list] enums and non-local
Brought to you by:
jandecaluwe
From: JOSE M. G. C. <jm....@ub...> - 2015-02-11 07:12:25
|
Hello all, I am trying to use an enumeration to define the states of a finite state machine. There are examples where it seems to work, but I am not able to do that. Moreover, I have gone through the code and in the _analyze.py module it seems that only intbv are allowed to be seen as non-locals. I assume there is a reason for this filtering, but there is no information. Can anyone provide a hint? Thanks in advance, Jose M. Aquest correu electrònic i els annexos poden contenir informació confidencial o protegida legalment i està adreçat exclusivament a la persona o entitat destinatària. Si no sou el destinatari final o la persona encarregada de rebre’l, no esteu autoritzat a llegir-lo, retenir-lo, modificar-lo, distribuir-lo, copiar-lo ni a revelar-ne el contingut. Si heu rebut aquest correu electrònic per error, us preguem que n’informeu al remitent i que elimineu del sistema el missatge i el material annex que pugui contenir. Gràcies per la vostra col·laboració. Este correo electrónico y sus anexos pueden contener información confidencial o legalmente protegida y está exclusivamente dirigido a la persona o entidad destinataria. Si usted no es el destinatario final o la persona encargada de recibirlo, no está autorizado a leerlo, retenerlo, modificarlo, distribuirlo, copiarlo ni a revelar su contenido. Si ha recibido este mensaje electrónico por error, le rogamos que informe al remitente y elimine del sistema el mensaje y el material anexo que pueda contener. Gracias por su colaboración. This email message and any documents attached to it may contain confidential or legally protected material and are intended solely for the use of the individual or organization to whom they are addressed. We remind you that if you are not the intended recipient of this email message or the person responsible for processing it, then you are not authorized to read, save, modify, send, copy or disclose any of its contents. If you have received this email message by mistake, we kindly ask you to inform the sender of this and to eliminate both the message and any attachments it carries from your account. Thank you for your collaboration. |
From: Christopher F. <chr...@gm...> - 2015-02-11 13:46:13
|
On 2/11/2015 1:11 AM, JOSE MARIA GOMEZ CAMA wrote: > Hello all, > > I am trying to use an enumeration to define the states of a finite state machine. There are examples where it seems to work, but I am not able to do that. Moreover, I have gone through the code and in the _analyze.py module it seems that only intbv are allowed to be seen as non-locals. I assume there is a reason for this filtering, but there is no information. Can anyone provide a hint? Do you have an example of the enumeration not working? I have used it many times, you can peruse this example if you like: https://github.com/schoeberl/comphdl/blob/master/myhdl/vending/vending.py#L31 Also the examples on the MyHDL website: http://www.myhdl.org/examples/sinecomp/#design The nonlocals are a little more complicated and will be enhanced (!) when porting to Py3k is completed. In general using /intbv/ is the safest approach. def m_some_module(*portmap): myvar = intbv(0, min=-8, max=8) @always... def rtl(): myvar[:] = x + 1 ... Hope that helps, Chris |
From: Jose M. G. C. <ch...@gm...> - 2015-02-11 15:47:50
|
This is a piece of code that does not work. I think it is more or less equivalent to yours. from myhdl import * def test(clk, reset, a, b): t_state = enum("WAIT", "CALC") state = Signal(t_state.WAIT) @always_seq(clk.posedge, reset) def fsm(): if state == t_state.WAIT: b.next = 0 state.next = t_state.CALC elif state == t_state.CALC: a.next = b state = t_state.WAIT return fsm clk = Signal(intbv(0)[1:]) reset = ResetSignal(1, active=1, async=False) a = Signal(intbv(0)[1:]) b = Signal(intbv(0)[1:]) toVHDL(test, clk, reset, a, b) The error is: Local variable may be referenced before assignment: state Thanks for your help, Jose M. > El 11/2/2015, a las 14:45, Christopher Felton <chr...@gm...> escribió: > > On 2/11/2015 1:11 AM, JOSE MARIA GOMEZ CAMA wrote: >> Hello all, >> >> I am trying to use an enumeration to define the states of a finite state machine. There are examples where it seems to work, but I am not able to do that. Moreover, I have gone through the code and in the _analyze.py module it seems that only intbv are allowed to be seen as non-locals. I assume there is a reason for this filtering, but there is no information. Can anyone provide a hint? > > Do you have an example of the enumeration not working? I > have used it many times, you can peruse this example if > you like: > https://github.com/schoeberl/comphdl/blob/master/myhdl/vending/vending.py#L31 > > Also the examples on the MyHDL website: > http://www.myhdl.org/examples/sinecomp/#design > > The nonlocals are a little more complicated and will be > enhanced (!) when porting to Py3k is completed. In general > using /intbv/ is the safest approach. > > > def m_some_module(*portmap): > > myvar = intbv(0, min=-8, max=8) > > @always... > def rtl(): > myvar[:] = x + 1 > ... > > > Hope that helps, > Chris > > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list |
From: Henry G. <he...@ca...> - 2015-02-11 16:17:56
|
On 11/02/15 15:47, Jose M. Gomez Cama wrote: > This is a piece of code that does not work. I think it is more or less equivalent to yours. > > > from myhdl import * > > def test(clk, reset, a, b): > t_state = enum("WAIT", "CALC") > state = Signal(t_state.WAIT) > @always_seq(clk.posedge, reset) > def fsm(): > if state == t_state.WAIT: > b.next = 0 > state.next = t_state.CALC > elif state == t_state.CALC: > a.next = b > state = t_state.WAIT > return fsm > > clk = Signal(intbv(0)[1:]) > reset = ResetSignal(1, active=1, async=False) > a = Signal(intbv(0)[1:]) > b = Signal(intbv(0)[1:]) > > toVHDL(test, clk, reset, a, b) > > The error is: > > Local variable may be referenced before assignment: state You're trying to assign state here: elif state == t_state.CALC: a.next = b state = t_state.WAIT Perhaps you want `state.next = t_state.WAIT`? Henry |
From: Jose M. G. C. <ch...@gm...> - 2015-02-11 19:57:25
|
Ups, you are right... Sorry > El 11/2/2015, a las 17:35, Christopher Felton <chr...@gm...> escribió: > > <snip> >> >> You're trying to assign state here: >> >> elif state == t_state.CALC: >> a.next = b >> state = t_state.WAIT >> >> Perhaps you want `state.next = t_state.WAIT`? >> > > Yup, what Henry said. > > Regards, > Chris > > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > myhdl-list mailing list > myh...@li... > https://lists.sourceforge.net/lists/listinfo/myhdl-list |
From: Christopher F. <chr...@gm...> - 2015-02-11 20:17:43
|
On 2/11/2015 1:57 PM, Jose M. Gomez Cama wrote: > Ups, you are right... > > Sorry > No problem! Glad we could help. Chris |
From: Christopher F. <chr...@gm...> - 2015-02-11 16:35:54
|
<snip> > > You're trying to assign state here: > > elif state == t_state.CALC: > a.next = b > state = t_state.WAIT > > Perhaps you want `state.next = t_state.WAIT`? > Yup, what Henry said. Regards, Chris |