-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
litedram/frontend/wishbone: Add initial LiteDRAMNative2Wishbone.
- Loading branch information
1 parent
a194044
commit 15fe3d9
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jersey99
Contributor
|
||
|
||
if wishbone_data_width != port_data_width: | ||
if wishbone_data_width > port_data_width: | ||
addr_shift = -log2_int(wishbone_data_width//port_data_width) | ||
|
@@ -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"), | ||
) | ||
) |
@enjoy-digital Looks like this is failing in CI, both with LiteDRAM and a bunch of my CI builds as well.