From 8b790b79d9525aff2a3e03e4ee11396f377f679b Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 1 Jun 2023 09:48:35 +0200 Subject: [PATCH] frontend/avalon: Consider single access as a 1 word burst and simplify. --- litedram/frontend/avalon.py | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/litedram/frontend/avalon.py b/litedram/frontend/avalon.py index 7fc2e85..3f66770 100644 --- a/litedram/frontend/avalon.py +++ b/litedram/frontend/avalon.py @@ -50,10 +50,10 @@ class LiteDRAMAvalonMM2Native(LiteXModule): # # # # Internal Signals. - burst_count = Signal(9) - burst_write = Signal() - address = Signal(port.address_width) - address_offset = Signal(port.address_width) + burst_count = Signal(9) + burst_read = Signal() + burst_address = Signal(port.address_width) + address_offset = Signal(port.address_width) self.comb += address_offset.eq(base_address >> log2_int(port.data_width//8)) # Write Data-path. @@ -81,47 +81,36 @@ class LiteDRAMAvalonMM2Native(LiteXModule): ] # Control-Path. - self.fsm = fsm = FSM(reset_state="IDLE") - fsm.act("IDLE", + self.fsm = fsm = FSM(reset_state="SINGLE-ACCESS") + fsm.act("SINGLE-ACCESS", avalon.waitrequest.eq(1), - # Start of Access. - If(avalon.read | avalon.write, - NextValue(burst_count, avalon.burstcount), - NextValue(burst_write, avalon.write), - NextValue(address, avalon.address - address_offset), - # Burst Access. - If(avalon.burstcount > 1, - If(avalon.read, - avalon.waitrequest.eq(0) - ), - NextState("BURST") - # Single Access. - ).Else( - port.cmd.addr.eq(avalon.address - address_offset), - port.cmd.we.eq(avalon.write), - port.cmd.valid.eq(avalon.read | (avalon.write & wdata_fifo.sink.ready)), - port.cmd.last.eq(1), - If(port.cmd.valid & port.cmd.ready, - avalon.waitrequest.eq(0), - ) + port.cmd.addr.eq(avalon.address - address_offset), + port.cmd.we.eq(avalon.write), + port.cmd.valid.eq(avalon.read | (avalon.write & wdata_fifo.sink.ready)), + port.cmd.last.eq(avalon.burstcount <= 1), + If(port.cmd.valid & port.cmd.ready, + avalon.waitrequest.eq(0), + # If access is a burst, continue it in BURST-ACCESS. + If(~port.cmd.last, + NextValue(burst_count, avalon.burstcount - 1), + NextValue(burst_read, avalon.read), + NextValue(burst_address, port.cmd.addr + burst_increment), + NextState("BURST-ACCESS") ) ) ) - fsm.act("BURST", + fsm.act("BURST-ACCESS", avalon.waitrequest.eq(1), - port.cmd.addr.eq(address), + port.cmd.addr.eq(burst_address), port.cmd.we.eq(avalon.write), - port.cmd.valid.eq(~burst_write | (avalon.write & wdata_fifo.sink.ready)), + port.cmd.valid.eq(burst_read | (avalon.write & wdata_fifo.sink.ready)), port.cmd.last.eq(burst_count == 1), If(port.cmd.valid & port.cmd.ready, - If(burst_write, - avalon.waitrequest.eq(0) - ), + avalon.waitrequest.eq(~avalon.write), + NextValue(burst_count, burst_count - 1), + NextValue(burst_address, burst_address + burst_increment), If(port.cmd.last, - NextState("IDLE") - ).Else( - NextValue(burst_count, burst_count - 1), - NextValue(address, address + burst_increment) + NextState("SINGLE-ACCESS") ) ) )