Re: Setting of enum values

Christopher Felton <[email protected]> Thu, 21 Jan 2016 10:34:17 -0600
Newsgroups gmane.comp.python.myhdl
Message-ID <[email protected]>
On 1/21/2016 5:15 AM, Marcel Hellwig wrote:
> On 21.01.2016 09:47, Thomas Heller wrote:
>> [...]
>> I had the same problem and currently only see these two possibilities:
>>
>> 1. Import each constant and assign it in the myhdl code, like this:
>>
>> from cpumode import CpuMode
>> cpumode_User = CpuMode.User
>> ...
>
> ugly as hell :D but yeah, it kind of works...
>
>>
>> 2. Define the constants as module level constants
>> and use 'from mymodule import *' in the myhdl code.
>
> I decided myself to this design. Would be nice though to have some kind
> of namespace seperation.
>

Disclaimer: I quickly review the previous posts in this
thread (I might not understand the intent) - if this is
off base ignore.

You should be able to use constant values in an object,
this code snip might help:


     from myhdl import *

     class MyConstants(object):
         def __init__(self):
             self.const1 = int(intbv("1111_0001"))
             self.const2 = int(intbv("1010_0101"))

     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


The above converts as expected.  You could also
convert the object to a tuple of ints, something
like (for this example):

     rom = [int(v) for k, v in vars(const)]

Regards,
Chris




------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140