generated from chipsalliance/chisel-template
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2cfcb2
commit f3424b5
Showing
6 changed files
with
286 additions
and
23 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
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 |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package lltriscv.bus | ||
|
||
import chisel3._ | ||
import chisel3.util._ | ||
|
||
import lltriscv.core.execute.MemoryAccessLength | ||
|
||
/** Core M/MMIO aggregation interface | ||
* | ||
* Provide conversion from a set of SMA buses to AXI bus | ||
* | ||
* Misaligned address access not supported | ||
*/ | ||
class AXIMaster extends Module { | ||
val io = IO(new Bundle { | ||
val smaReader = Flipped(new SMAReaderIO()) | ||
val smaWriter = Flipped(new SMAWriterIO()) | ||
|
||
val axi = new AXIMasterIO() | ||
}) | ||
|
||
private object AXIStatus extends ChiselEnum { | ||
val idle, address, data, response = Value; | ||
} | ||
|
||
// Reader logic | ||
private val readerStatusReg = RegInit(AXIStatus.idle) | ||
|
||
when(readerStatusReg === AXIStatus.idle) { | ||
when(io.smaReader.valid) { | ||
readerStatusReg := AXIStatus.address | ||
} | ||
} | ||
|
||
when(readerStatusReg === AXIStatus.address) { | ||
// 32-bit address alignment | ||
io.axi.ARADDR := io.smaReader.address(31, 2) ## 0.U(2.W) | ||
io.axi.ARPORT := 0.U | ||
io.axi.ARVALID := true.B | ||
when(io.axi.ARREADY) { | ||
readerStatusReg := AXIStatus.response | ||
} | ||
} | ||
|
||
when(readerStatusReg === AXIStatus.response) { | ||
io.axi.RREADY := true.B | ||
|
||
when(io.axi.RVALID) { | ||
switch(io.smaReader.readType) { | ||
is(MemoryAccessLength.byte) { | ||
io.smaReader.data := MuxLookup(io.smaReader.address(1, 0), 0.U)( | ||
Seq( | ||
"b00".U -> io.axi.RDATA(7, 0), | ||
"b01".U -> io.axi.RDATA(15, 8), | ||
"b10".U -> io.axi.RDATA(23, 16), | ||
"b11".U -> io.axi.RDATA(31, 24) | ||
) | ||
) | ||
} | ||
is(MemoryAccessLength.half) { | ||
io.smaReader.data := Mux(io.smaReader.address(1), io.axi.RDATA(31, 16), io.axi.RDATA(15, 0)) | ||
} | ||
is(MemoryAccessLength.word) { | ||
io.smaReader.data := io.axi.RDATA | ||
} | ||
} | ||
|
||
io.smaReader.error := false.B | ||
io.smaReader.ready := true.B | ||
|
||
readerStatusReg := AXIStatus.idle | ||
} | ||
} | ||
|
||
// Writer logic | ||
private val writerStatusReg = RegInit(AXIStatus.idle) | ||
|
||
when(writerStatusReg === AXIStatus.idle) { | ||
when(io.smaWriter.valid) { | ||
writerStatusReg := AXIStatus.address | ||
} | ||
} | ||
|
||
when(writerStatusReg === AXIStatus.address) { | ||
// 32-bit address alignment | ||
io.axi.AWADDR := io.smaWriter.address(31, 2) ## 0.U(2.W) | ||
io.axi.AWPORT := 0.U | ||
io.axi.AWVALID := true.B | ||
when(io.axi.AWREADY) { | ||
writerStatusReg := AXIStatus.data | ||
} | ||
} | ||
|
||
when(writerStatusReg === AXIStatus.data) { | ||
switch(io.smaWriter.writeType) { | ||
is(MemoryAccessLength.byte) { | ||
io.axi.WDATA := MuxLookup(io.smaWriter.address(1, 0), 0.U)( | ||
Seq( | ||
"b00".U -> io.smaWriter.data(7, 0), | ||
"b01".U -> io.smaWriter.data(7, 0) ## 0.U(8.W), | ||
"b10".U -> io.smaWriter.data(7, 0) ## 0.U(16.W), | ||
"b11".U -> io.smaWriter.data(7, 0) ## 0.U(24.W) | ||
) | ||
) | ||
|
||
io.axi.WSTRB := MuxLookup(io.smaWriter.address(1, 0), 0.U)( | ||
Seq( | ||
"b00".U -> "b0001".U, | ||
"b01".U -> "b0010".U, | ||
"b10".U -> "b0100".U, | ||
"b11".U -> "b1000".U | ||
) | ||
) | ||
} | ||
|
||
is(MemoryAccessLength.half) { | ||
io.axi.WDATA := Mux(io.smaWriter.address(1), io.smaWriter.data(15, 0) ## 0.U(16.W), io.smaWriter.data(15, 0)) | ||
io.axi.WSTRB := Mux(io.smaWriter.address(1), "b1100".U, "b0011".U) | ||
} | ||
|
||
is(MemoryAccessLength.word) { | ||
io.axi.WDATA := io.smaWriter.data | ||
io.axi.WSTRB := "b1111".U | ||
} | ||
} | ||
|
||
io.axi.WVALID := true.B | ||
when(io.axi.WREADY) { | ||
writerStatusReg := AXIStatus.response | ||
} | ||
} | ||
|
||
when(writerStatusReg === AXIStatus.response) { | ||
io.axi.BREADY := true.B | ||
when(io.axi.BVALID) { | ||
io.smaWriter.ready := true.B | ||
io.smaWriter.error := 0.U | ||
writerStatusReg := AXIStatus.idle | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.