Re: [myhdl-list] Setting of enum values
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2016-01-21 18:25:05
|
On 1/21/2016 11:19 AM, Marcel Hellwig wrote: > 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? Correct, I could have done int("11110001", 2). The only reason I used `intbv` was so I could use the '_' separator :) Or as you did in your original example, 0b11110001. > > 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 Hmm, I am not following what you are trying to do different. From your description, it sounds like the object is not defined when the generator is analyzed? I modified my example slightly to match your original class attribute (instead of instance attribute): https://gist.github.com/cfelton/50cb0fbed5f188fcc1bb > > 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) What are you interested in here, using the value or the type? If it is the value you can still use it, if it is the type can create a method in your function mode = Signal(ProcMode.const_type()) Then the method can look at all the constants defined and determine the appropriate bitwidth and return the appropriate type (e.g `intbv(0)[8:]`). Regards, Chris |