I am designing an interface that implements an 8-bit-to-32-bit register. Upon clear or reset, I want to reset the byte value registers to 0. I hoped to do this using an elegant approach but have only succeeded with something that feels crufty.
The overview is that you can write to any byte of the 4-byte register with data_in, when all 4 bytes have been loaded, the data valid signal is generated so that a 32-bit word my be read from data_out.
Any recommendations for a beginner?
This is the code that works. If I swap out the comments for the 4 explicit register assignements, things go badly. I’ve included the trace below the code when this happens.
def register_32(data_in=None, data_out=None, data_valid=None, byte=None, enable=None, clear=None, clock=None, reset=None):
register = [Signal(intbv(0)[8:0]) for _ in range(4)]
q = ConcatSignal(*register[::-1])
flags = [Signal(bool(0)) for _ in range(4)]
@always_comb
def pack():
data_out.next = q
data_valid.next = flags[0] and flags[1] and flags[2] and flags[3]
@always(clock.posedge, reset.posedge)
def logic():
if reset or clear:
# for i in range(3):
# register[i].next = 0
register[0].next = 0
register[1].next = 0
register[2].next = 0
register[3].next = 0
flags[0].next = False
flags[1].next = False
flags[2].next = False
flags[3].next = False
if enable:
register[byte].next = data_in
flags[byte].next = True
return pack, logic
Trace:
Traceback (most recent call last):
File "C:/MyPython/myhdl_demo/register_32.py", line 122, in <module>
convert()
File "C:/MyPython/myhdl_demo/register_32.py", line 118, in convert
toVerilog(register_32, data_in, data_out, data_valid, byte, enable, clear, clock, reset)
File "C:\MyPython\myhdl_demo\venv\lib\site-packages\myhdl\conversion\_toVerilog.py", line 151, in __call__
genlist = _analyzeGens(arglist, h.absnames)
File "C:\MyPython\myhdl_demo\venv\lib\site-packages\myhdl\conversion\_analyze.py", line 164, in _analyzeGens
v.visit(tree)
File "C:\Python_v3.6.2\lib\ast.py", line 253, in visit
return visitor(node)
File "C:\Python_v3.6.2\lib\ast.py", line 261, in generic_visit
self.visit(item)
File "C:\Python_v3.6.2\lib\ast.py", line 253, in visit
return visitor(node)
File "C:\MyPython\myhdl_demo\venv\lib\site-packages\myhdl\conversion\_analyze.py", line 290, in visit_FunctionDef
self.visitList(node.body)
File "C:\MyPython\myhdl_demo\venv\lib\site-packages\myhdl\conversion\_misc.py", line 162, in visitList
self.visit(n)
File "C:\Python_v3.6.2\lib\ast.py", line 253, in visit
return visitor(node)
File "C:\MyPython\myhdl_demo\venv\lib\site-packages\myhdl\conversion\_analyze.py", line 312, in visit_If
self.generic_visit(node)
File "C:\Python_v3.6.2\lib\ast.py", line 261, in generic_visit
self.visit(item)
File "C:\Python_v3.6.2\lib\ast.py", line 253, in visit
return visitor(node)
File "C:\MyPython\myhdl_demo\venv\lib\site-packages\myhdl\conversion\_analyze.py", line 261, in visit_Assign
self.visit(node.value)
File "C:\Python_v3.6.2\lib\ast.py", line 253, in visit
return visitor(node)
File "C:\MyPython\myhdl_demo\venv\lib\site-packages\myhdl\conversion\_analyze.py", line 248, in visit_List
self.raiseError(node, _error.NotSupported, "list")
File "C:\MyPython\myhdl_demo\venv\lib\site-packages\myhdl\conversion\_misc.py", line 149, in raiseError
raise ConversionError(kind, msg, info)
myhdl.ConversionError: in file C:/MyPython/myhdl_demo/register_32.py, line 24:
Not supported: list