-
Notifications
You must be signed in to change notification settings - Fork 0
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
530d5b6
commit be70f5e
Showing
5 changed files
with
161 additions
and
8 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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
import chisel3._ | ||
import chisel3.util._ | ||
|
||
class ResetSync extends HasBlackBoxResource { | ||
trait ResetSyncBase { | ||
val io = IO(new Bundle{ | ||
val clock = Input(Clock()) | ||
val resetIn = Input(Bool()) | ||
val resetOut = Output(Bool()) | ||
}) | ||
} | ||
|
||
class ResetSync extends HasBlackBoxResource with ResetSyncBase { | ||
addResource("ResetSync.sv") | ||
} | ||
|
||
|
||
class ResetSyncTest extends Module with ResetSyncBase { | ||
io.resetOut := io.resetIn | ||
} |
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,34 @@ | ||
import chisel3._ | ||
import chisel3.util.experimental.BoringUtils | ||
|
||
import leros._ | ||
|
||
class DtuTopTest(prog:String) extends Module { | ||
val dtuTop = Module(new DtuTop(prog = prog, resetSyncFact = () => Module(new ResetSyncTest()))) | ||
// val programmer = Module(new Programmer(dtuTop.lerosClockFreq, dtuTop.lerosUartBaudrate, prog)) | ||
val io = IO(new Debug(dtuTop.lerosSize, dtuTop.lerosMemAddrWidth)) | ||
|
||
// Boring Utils for debugging | ||
io.accu := DontCare | ||
io.pc := DontCare | ||
io.instr := DontCare | ||
io.exit := DontCare | ||
BoringUtils.bore(dtuTop.leros.accu, Seq(io.accu)) | ||
BoringUtils.bore(dtuTop.leros.pcReg, Seq(io.pc)) | ||
BoringUtils.bore(dtuTop.leros.instr, Seq(io.instr)) | ||
BoringUtils.bore(dtuTop.leros.exit, Seq(io.exit)) | ||
|
||
|
||
dtuTop.io.apb.paddr := 0.U | ||
dtuTop.io.apb.pwrite := false.B | ||
dtuTop.io.apb.psel := false.B | ||
dtuTop.io.apb.penable := false.B | ||
dtuTop.io.apb.pwdata := 0.U | ||
|
||
// dtuTop.io.pmod0.gpi := programmer.io.txd ## 0.U | ||
dtuTop.io.pmod0.gpi := 0.U | ||
dtuTop.io.pmod1.gpi := 0.U | ||
dtuTop.io.irqEn1 := false.B | ||
dtuTop.io.ssCtrl1 := 0.U | ||
} | ||
|
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,40 @@ | ||
import scala.sys._ | ||
import chisel3._ | ||
import chiseltest._ | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import chisel3.util.experimental.BoringUtils | ||
|
||
import leros._ | ||
|
||
class DtuTopTester extends AnyFlatSpec with ChiselScalatestTester { | ||
System.setProperty("testpath", "leros/asm/test") | ||
val progs = leros.shared.Util.getProgs() | ||
progs.foreach(p => { | ||
val program = p + ".s" | ||
|
||
def testFun(dut: DtuTopTest): Unit = { | ||
|
||
var run = true | ||
var maxCycles = 1000 | ||
while (run) { | ||
val pc = dut.io.pc.peekInt() | ||
val accu = dut.io.accu.peekInt() | ||
val instr = dut.io.instr.peekInt() | ||
// Predef.printf("pc: 0x%04x instr: 0x%04x accu: 0x%08x\n", pc, instr, accu) | ||
dut.clock.step(1) | ||
maxCycles -= 1 | ||
run = dut.io.exit.peekInt() == 0 && maxCycles > 0 | ||
assert(maxCycles > 0, "Running out of cycles") | ||
} | ||
val res = dut.io.accu.expect(1.U, "Accu shall be one at the end of a test case.\n") | ||
} | ||
|
||
"Leros HW " should s"pass $program" in { | ||
test(new DtuTopTest(prog = program)) | ||
.withAnnotations(Seq(WriteVcdAnnotation)) { dut => | ||
testFun(dut) | ||
} | ||
} | ||
|
||
}) | ||
} |
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,39 @@ | ||
package leros | ||
|
||
import chisel3._ | ||
import chisel3.util._ | ||
import java.nio.file._ | ||
import leros.shared.Constants._ | ||
import leros.uart._ | ||
|
||
/** | ||
* Sends content of a file over uart | ||
* frequency: clock frequency in hz | ||
* baudrate: baudrate in baud/s | ||
* txFile: path to file to be sent | ||
*/ | ||
class Programmer(frequency: Int, baudRate: Int, txFile : String) extends Module { | ||
val io = IO(new Bundle { | ||
val txd = Output(UInt(1.W)) | ||
}) | ||
|
||
val tx = Module(new BufferedTx(frequency, baudRate)) | ||
|
||
io.txd := tx.io.txd | ||
|
||
val txDataFile = Files.readAllBytes(Paths.get(txFile)) | ||
val txData = VecInit(txDataFile.map(_.S(8.W))) | ||
val len = txData.length | ||
val cntReg = RegInit(0.U(log2Ceil(len).W)) | ||
|
||
val instr = txData(cntReg).asUInt ## txData(cntReg-1.U).asUInt | ||
val enable = RegInit(true.B) | ||
enable := cntReg =/= len.U | ||
|
||
tx.io.channel.bits := txData(cntReg).asUInt | ||
tx.io.channel.valid := cntReg =/= len.U || enable | ||
|
||
when(tx.io.channel.ready && cntReg =/= len.U) { | ||
cntReg := cntReg + 1.U | ||
} | ||
} |