Skip to content

Commit

Permalink
litedram/frontend/wishbone: Add initial LiteDRAMNative2Wishbone.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Aug 22, 2024
1 parent a194044 commit 15fe3d9
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions litedram/frontend/wishbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def __init__(self, wishbone, port, base_address=0x00000000):
port_data_width = 2**int(log2(len(port.wdata.data))) # Round to lowest power 2
ratio = wishbone_data_width/port_data_width

assert wishbone.addressing == "byte"

This comment has been minimized.

Copy link
@jersey99

jersey99 Aug 23, 2024

Contributor

@enjoy-digital Looks like this is failing in CI, both with LiteDRAM and a bunch of my CI builds as well.

This comment has been minimized.

Copy link
@jersey99

jersey99 Aug 23, 2024

Contributor

Basically, inside soc.py, in connect_main_bus_to_dram section, all instances of wishbone.Interface are instantiated with addressing="word", so this check fails when LiteDRAMWishbone2Native gets instantiated.

This comment has been minimized.

Copy link
@enjoy-digital

enjoy-digital Aug 23, 2024

Author Owner

Thanks @jersey99, that's indeed assert wishbone.addressing == "byte" that I wanted to add... :), going to fix it.


if wishbone_data_width != port_data_width:
if wishbone_data_width > port_data_width:
addr_shift = -log2_int(wishbone_data_width//port_data_width)
Expand Down Expand Up @@ -79,3 +81,62 @@ def __init__(self, wishbone, port, base_address=0x00000000):
NextState("CMD")
)
)

# LiteDRAMNative2Wishbone --------------------------------------------------------------------------

class LiteDRAMNative2Wishbone(LiteXModule):
def __init__(self, port, wishbone, base_address=0x00000000):
wishbone_data_width = len(wishbone.dat_w)
port_data_width = 2**int(log2(len(port.wdata.data))) # Round to lowest power 2
ratio = wishbone_data_width/port_data_width

assert ratio == 1

# # #

# Signals.
adr = Signal(32)

# FSM.
self.fsm = fsm = FSM(reset_state="CMD")
fsm.act("CMD",
If(port.cmd.valid,
port.cmd.ready.eq(1),
If(wishbone.addressing == "byte",
NextValue(adr, port.cmd.addr*int(port_data_width//8) + base_address),
).Else(
NextValue(adr, port.cmd.addr + base_address//int(port_data_width//8)),
),
If(port.cmd.we,
NextState("WRITE")
).Else(
NextState("READ")
)
)
)
fsm.act("WRITE",
If(port.wdata.valid,
wishbone.stb.eq(1),
wishbone.cyc.eq(1),
wishbone.we.eq(1),
wishbone.adr.eq(adr),
wishbone.sel.eq(port.wdata.we),
wishbone.dat_w.eq(port.wdata.data),
If(wishbone.ack,
port.wdata.ready.eq(1),
NextState("CMD")
)
)
)
fsm.act("READ",
wishbone.stb.eq(1),
wishbone.cyc.eq(1),
wishbone.adr.eq(adr),
wishbone.sel.eq(2**len(wishbone.sel) - 1),
If(wishbone.ack,
# Assume port.rdata.ready always 1.
port.rdata.valid.eq(1),
port.rdata.data.eq(wishbone.dat_r),
NextState("CMD"),
)
)

0 comments on commit 15fe3d9

Please sign in to comment.