Merge branch 'enjoy-digital:master' into master

This commit is contained in:
John_Tito 2024-11-09 09:57:56 +08:00 committed by GitHub
commit 9f7186a002
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 117 additions and 100 deletions

View file

@ -34,7 +34,102 @@ GCC_FLAGS = {
"standard": "-march=rv32i2p0_m -mabi=ilp32", "standard": "-march=rv32i2p0_m -mabi=ilp32",
} }
# uRV ------------------------------------------------------------------------------------------ # uRV Instruction Bus To Wishbone ------------------------------------------------------------------
instruction_bus_layout = [
("addr", 32),
("rd", 1),
("data", 32),
("valid", 1)
]
class InstructionBusToWishbone(LiteXModule):
def __init__(self, ibus, wb_ibus):
self.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE",
If(ibus.rd,
NextValue(ibus.valid, 0),
NextState("READ")
)
)
fsm.act("READ",
wb_ibus.stb.eq(1),
wb_ibus.cyc.eq(1),
wb_ibus.we.eq(0),
wb_ibus.adr.eq(ibus.addr),
wb_ibus.sel.eq(0b1111),
If(wb_ibus.ack,
NextValue(ibus.valid, 1),
NextValue(ibus.data, wb_ibus.dat_r),
NextState("IDLE")
)
)
# uRV Data Bus To Wishbone -------------------------------------------------------------------------
data_bus_layout = [
("addr", 32),
("data_s", 32),
("data_l", 32),
("sel", 4),
("store", 1),
("load", 1),
("load_done", 1),
("store_done", 1)
]
class DataBusToWishbone(LiteXModule):
def __init__(self, dbus, wb_dbus):
self.fifo = fifo = stream.SyncFIFO(
layout=[("addr", 32), ("we", 1), ("data", 32), ("sel", 4)],
depth=16,
)
self.comb += [
fifo.sink.valid.eq(dbus.store | dbus.load),
fifo.sink.we.eq(dbus.store),
fifo.sink.addr.eq(dbus.addr),
fifo.sink.data.eq(dbus.data_s),
fifo.sink.sel.eq(dbus.sel),
]
self.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE",
If(fifo.source.valid,
If(fifo.source.we,
NextState("WRITE")
).Else(
NextState("READ")
)
)
)
fsm.act("WRITE",
wb_dbus.stb.eq(1),
wb_dbus.cyc.eq(1),
wb_dbus.we.eq(1),
wb_dbus.adr.eq(fifo.source.addr),
wb_dbus.sel.eq(fifo.source.sel),
wb_dbus.dat_w.eq(fifo.source.data),
If(wb_dbus.ack,
fifo.source.ready.eq(1),
dbus.store_done.eq(1),
NextState("IDLE")
)
)
fsm.act("READ",
wb_dbus.stb.eq(1),
wb_dbus.cyc.eq(1),
wb_dbus.we.eq(0),
wb_dbus.adr.eq(fifo.source.addr),
wb_dbus.sel.eq(fifo.source.sel),
If(wb_dbus.ack,
fifo.source.ready.eq(1),
dbus.load_done.eq(1),
dbus.data_l.eq(wb_dbus.dat_r),
NextState("IDLE")
)
)
# uRV ----------------------------------------------------------------------------------------------
class uRV(CPU): class uRV(CPU):
category = "softcore" category = "softcore"
@ -66,21 +161,10 @@ class uRV(CPU):
self.periph_buses = [ibus, dbus] # Peripheral buses (Connected to main SoC's bus). self.periph_buses = [ibus, dbus] # Peripheral buses (Connected to main SoC's bus).
self.memory_buses = [] # Memory buses (Connected directly to LiteDRAM). self.memory_buses = [] # Memory buses (Connected directly to LiteDRAM).
# uRV Signals. # uRV Buses.
# ------------ # ----------
im_addr = Signal(32) im_bus = Record(instruction_bus_layout)
im_rd = Signal() dm_bus = Record(data_bus_layout)
im_data = Signal(32)
im_valid = Signal()
dm_addr = Signal(32)
dm_data_s = Signal(32)
dm_data_l = Signal(32)
dm_data_select = Signal(4)
dm_store = Signal()
dm_load = Signal()
dm_load_done = Signal()
dm_store_done = Signal()
# uRV Instance. # uRV Instance.
# ------------- # -------------
@ -100,94 +184,27 @@ class uRV(CPU):
i_rst_i = ResetSignal("sys") | self.reset, i_rst_i = ResetSignal("sys") | self.reset,
# Instruction Mem Bus. # Instruction Mem Bus.
o_im_addr_o = im_addr, o_im_addr_o = im_bus.addr,
o_im_rd_o = im_rd, o_im_rd_o = im_bus.rd,
i_im_data_i = im_data, i_im_data_i = im_bus.data,
i_im_valid_i = im_valid, i_im_valid_i = im_bus.valid,
# Data Mem Bus. # Data Mem Bus.
o_dm_addr_o = dm_addr, o_dm_addr_o = dm_bus.addr,
o_dm_data_s_o = dm_data_s, o_dm_data_s_o = dm_bus.data_s,
i_dm_data_l_i = dm_data_l, i_dm_data_l_i = dm_bus.data_l,
o_dm_data_select_o = dm_data_select, o_dm_data_select_o = dm_bus.sel,
o_dm_store_o = dm_store, o_dm_store_o = dm_bus.store,
o_dm_load_o = dm_load, o_dm_load_o = dm_bus.load,
i_dm_load_done_i = dm_load_done, i_dm_load_done_i = dm_bus.load_done,
i_dm_store_done_i = dm_store_done, i_dm_store_done_i = dm_bus.store_done,
) )
# uRV Instruction Bus. # uRV Bus Adaptation.
# -------------------- # -------------------
self.i_fsm = i_fsm = FSM(reset_state="IDLE") self.submodules += InstructionBusToWishbone(im_bus, ibus)
i_fsm.act("IDLE", self.submodules += DataBusToWishbone(dm_bus, dbus)
If(im_rd,
NextValue(im_valid, 0),
NextState("READ")
)
)
i_fsm.act("READ",
ibus.stb.eq(1),
ibus.cyc.eq(1),
ibus.we.eq(0),
ibus.adr.eq(im_addr),
ibus.sel.eq(0b1111),
If(ibus.ack,
NextValue(im_valid, 1),
NextValue(im_data, ibus.dat_r),
NextState("IDLE")
)
)
# uRV Data Bus.
# -------------
self.dm_fifo = dm_fifo = stream.SyncFIFO(
layout = [("addr", 32), ("we", 1), ("data", 32), ("sel", 4)],
depth = 16,
)
self.comb += [
dm_fifo.sink.valid.eq(dm_store | dm_load),
dm_fifo.sink.we.eq(dm_store),
dm_fifo.sink.addr.eq(dm_addr),
dm_fifo.sink.data.eq(dm_data_s),
dm_fifo.sink.sel.eq(dm_data_select),
]
self.dm_fsm = dm_fsm = FSM(reset_state="IDLE")
dm_fsm.act("IDLE",
If(dm_fifo.source.valid,
If(dm_fifo.source.we,
NextState("WRITE")
).Else(
NextState("READ")
)
)
)
dm_fsm.act("WRITE",
dbus.stb.eq(1),
dbus.cyc.eq(1),
dbus.we.eq(1),
dbus.adr.eq(dm_fifo.source.addr),
dbus.sel.eq(dm_fifo.source.sel),
dbus.dat_w.eq(dm_fifo.source.data),
If(dbus.ack,
dm_fifo.source.ready.eq(1),
dm_store_done.eq(1),
NextState("IDLE")
)
)
dm_fsm.act("READ",
dbus.stb.eq(1),
dbus.cyc.eq(1),
dbus.we.eq(0),
dbus.adr.eq(dm_fifo.source.addr),
dbus.sel.eq(dm_fifo.source.sel),
If(dbus.ack,
dm_fifo.source.ready.eq(1),
dm_load_done.eq(1),
dm_data_l.eq(dbus.dat_r),
NextState("IDLE")
)
)
# Add Verilog sources. # Add Verilog sources.
# -------------------- # --------------------

View file

@ -318,7 +318,7 @@ class SoCBusHandler(LiteXModule):
is_in = True is_in = True
if not (region.origin >= container.origin): if not (region.origin >= container.origin):
is_in = False is_in = False
if not ((region.origin + region.size) < (container.origin + container.size)): if not ((region.origin + region.size) <= (container.origin + container.size)):
is_in = False is_in = False
return is_in return is_in