I am trying to create a fifo by a queue (this is also mentioned in the MyHDL manual) but get errors when I try to convert it to VHDL. Not sure if this are MyHDL errors or normal Python errors.
convert_model.py
’
from myhdl import Signal,intbv, ResetSignal
from fifo_queue import Fifo
from rw_fifo import *
def convert_rw_fifo(hdl):
#assign default/initial values to signals
ip_rst = ResetSignal(0, active=1, isasync=True)
ip_clk = Signal(bool(0))
ResetError = Signal(bool(0))
write = Signal(bool(0))
write_data = Signal(intbv(val=0, min=0, max=2**16))
read = Signal(bool(0))
rw_fifo_1 = rw_fifo(ip_rst, ip_clk, ResetError, write, write_data, read)
rw_fifo_1.convert(hdl=hdl)
#------------------------------------------------------------------------------
Main
#------------------------------------------------------------------------------
if name == ‘main’ :
convert_rw_fifo(hdl=‘VHDL’)
’
fifo_queue.py
’
#from myhdl import (Signal, ResetSignal, intbv, modbv, always, always_comb, always_seq)
import queue
“”"
FIFO definition with queue
“”"
class Fifo():
def init (self, depth, width, almost_full_level, almost_empty_level):
“”" create queue and attributes “”"
self.fifo = queue.Queue(depth)
self.depth = depth
self.width = width
self.full_flag = 0
self.empty_flag = 1
self.almost_full_level = almost_full_level
self.almost_empty_level = almost_empty_level
“”" keep track of number of values in fifo “”"
self.level = 0
def put(self, symbol):
“”" store a value in fifo if not full “”"
if self.level != self.depth:
self.fifo.put(symbol, block=False, timeout=None)
self.level = self.level + 1
def get(self):
“”" get a value from fifo if not empty “”"
if self.level != 0:
symbol = self.fifo.get(block=False)
self.level = self.level - 1
return symbol
def is_full(self):
“”" check if fifo is full “”"
return self.limit_reached(self.depth)
def is_empty(self):
“”" check if fifo is full “”"
return self.limit_reached(0)
def is_almost_full(self):
“”" check if fifo is almost full “”"
return self.limit_reached(self.almost_full_level)
def is_almost_empty(self):
“”" check if fifo is almost empty “”"
return self.limit_reached(self.almost_empty_level)
def limit_reached(self, limit):
if self.level == limit:
return True
else:
return False
def reset(self):
“”" reset level counter “”"
self.fifo = queue.Queue(self.depth)
self.level = 0
#------------------------------------------------------------------------------
Test functions
#------------------------------------------------------------------------------
def tst_queue_1():
depth = 10
width = 3
almost_full_level = 9
almost_empty_level = 1
Print all methods
print(dir(Fifo))
Testing Put element:
header_fifo = Fifo(depth, width, almost_full_level, almost_empty_level)
fifo = Fifo(depth, width, almost_full_level, almost_empty_level)
for i in range(11):
print(‘Putting {:d}\n’.format(i))
if header_fifo.is_full():
if fifo.is_full():
print('\t\tShit, the fifo is full')
else:
header_fifo.put(i)
a=1
Testing Get element:
for i in range(11):
if header_fifo.is_empty():
print(’\t\tShit, the fifo is empty’)
else:
symbol = header_fifo.get()
print(‘Getting {:d}\n’.format(symbol))
header_fifo.put(20)
header_fifo.put(30)
header_fifo.reset()
if header_fifo.is_empty():
print(‘The fifo is empty and should be\n’)
#------------------------------------------------------------------------------
Main
#------------------------------------------------------------------------------
if name == ‘main’ :
tst_queue_1()
’
rw_fifo.py
’
from myhdl import block, instance, Signal, ResetSignal, intbv, modbv, concat, always, always_comb, always_seq
from fifo_queue import Fifo
@block
def rw_fifo (ip_rst, ip_clk, ResetError, write, write_data, read):
“”" create fifo
“”"
header_fifo = Fifo(32, 16, 16-4, 4)
write_data = Signal(intbv(val=0, min=0, max=216))
read_data = Signal(intbv(val=0, min=0, max=216))
@always_seq (ip_clk.negedge, reset=ip_rst)
def fifo_write():
"""
clear fifo's at reset
"""
if ResetError == 1:
header_fifo.reset()
else:
""" write to fifo """
if write == 1 and header_fifo.is_full==0:
header_fifo.put(write_data)
@always_comb
def fifo_read():
""" read from fifo if requested and there is data """
if read == 1 and header_fifo.is_empty() == 0:
""" change format only """
read_data = header_fifo.get()
return fifo_write, fifo_read
’
The error is that it cannot find the reset method in the class definition. If I run the testfunction in the fifo_queue it seems to work.