Skip to content

Instantly share code, notes, and snippets.

@cfelton
Created March 8, 2016 12:37
Show Gist options
  • Save cfelton/e28e20aaa618cd8440f7 to your computer and use it in GitHub Desktop.
Save cfelton/e28e20aaa618cd8440f7 to your computer and use it in GitHub Desktop.
class FIFOBus(object):
def __init__(self, size=16, width=8):
"""
"""
self.name = "fifobus{0}".format(_fb_num)
# @todo: add write clock and read clock to the interface!
# @todo: use longer names read, read_valid, read_data,
# @todo: write, write_data, etc.!
# all the data signals are from the perspective
# of the FIFO being interfaced to.
self.clear = Signal(bool(0)) # fifo clear
#self.wclk = None # write side clock
self.write = Signal(bool(0)) # write strobe to fifo
self.write_data = Signal(intbv(0)[width:]) # fifo data in
#self.rclk = None # read side clock
self.read = Signal(bool(0)) # fifo read strobe
self.read_data = Signal(intbv(0)[width:]) # fifo data out
self.read_valid = Signal(bool(0))
self.empty = Signal(bool(1)) # fifo empty
self.full = Signal(bool(0)) # fifo full
self.count = Signal(intbv(0, min=0, max=size+1))
self.width = width
self.size = size
_add_bus(self, self.name)
def __str__(self):
s = "wr: {} {:04X}, rd: {} {:04X}, empty {}, full {}".format(
int(self.write), int(self.write_data), int(self.read), int(self.read_data),
int(self.empty), int(self.full))
return s
def assign_read_write_paths(self, readpath, writepath):
"""
Assign the signals from the `readpath` to the read signals
of this interface and same for write
"""
assert isinstance(readpath, FIFOBus)
assert isinstance(writepath, FIFOBUus)
@always_comb
def beh_assign():
readpath.read_data.next = self.read_data
self.read.next = readpath.read
self.write_data.next = writepath.write_data
self.write.next = writepath.write
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment