Re: [myhdl-list] Setting of enum values
Brought to you by:
jandecaluwe
From: Marcel H. <1he...@in...> - 2016-01-21 17:19:46
|
On 21.01.2016 17:34, Christopher Felton wrote: > > from myhdl import * > > class MyConstants(object): > def __init__(self): > self.const1 = int(intbv("1111_0001")) > self.const2 = int(intbv("1010_0101")) why the intbv -> int conversion here? Just for using bitwise representation? > > def const_select(sel, x): > const = MyConstants() > > @always_comb > def beh_select(): > if sel == 1: > x.next = const.const1 > elif sel == 2: > x.next = const.const2 > else: > x.next = 0 > > return beh_select > Although I can reproduce your example in some test-cases, I can't use it in my project... I use two approaches here. First is to create a instance of the class in the __init__.py. Then I will get a > Local variable may be referenced before assignment: ProcMode When I create the instance directly in my myhdl-method, I will get > Free variable should be a Signal or an int: ProcMode The advantage of having the enum over, that you can use it directly in a Signal, e.g. > mode = Signal(ProcMode.User) currently, it will complain about not havin the bitsize (I have set it manually, which will work fine) I'm not happy about the solutions yet, altough I really appreciate the help I'm getting here (thanks!), but in my eyes, I just want to solve a simple problem. Has never anyone encountered this and made some thoughts? :/ |