Skip to content

Instantly share code, notes, and snippets.

@tzechienchu
Created July 17, 2021 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzechienchu/7d16f341b049f4ea66f1cbc58524ffc3 to your computer and use it in GitHub Desktop.
Save tzechienchu/7d16f341b049f4ea66f1cbc58524ffc3 to your computer and use it in GitHub Desktop.
Test for UART
import chisel3.iotesters.PeekPokeTester
import chisel3.iotesters.Driver
import org.scalatest._
class TestTX(dut: BufferTx) extends PeekPokeTester(dut) {
poke(dut.io.channel.data, 0x55)
poke(dut.io.channel.valid, 0)
step(500)
poke(dut.io.channel.valid, 1)
step(10)
poke(dut.io.channel.valid, 0)
step(100)
poke(dut.io.channel.data, 0x33)
poke(dut.io.channel.valid, 1)
step(10)
poke(dut.io.channel.valid, 0)
step(400)
poke(dut.io.channel.data, 0xAA)
poke(dut.io.channel.valid, 0)
step(500)
poke(dut.io.channel.valid, 1)
step(10)
poke(dut.io.channel.valid, 0)
step(100)
poke(dut.io.channel.data, 0x33)
poke(dut.io.channel.valid, 1)
step(10)
poke(dut.io.channel.valid, 0)
step(800)
step(800)
}
// class TestTXSpec extends FlatSpec with Matchers {
// "TestTX" should "pass" in {
// Driver.execute(
// Array("--generate-vcd-output","on"),
// () => new BufferTx(50*1000*1000,115200*10)) {
// c => new TestTX(c)
// } should be (true)
// }
// }
class TestSender(dut: Sender) extends PeekPokeTester(dut) {
step(1000)
step(1000)
step(1000)
step(1000)
step(1000)
step(1000)
}
// class SenderTXSpec extends FlatSpec with Matchers {
// "SenderTX" should "pass" in {
// Driver.execute(
// Array("--generate-vcd-output","on"),
// () => new Sender(50*1000*1000,115200*10)) {
// c => new TestSender(c)
// } should be (true)
// }
// }
class TestRx(dut: Echo) extends PeekPokeTester(dut) {
poke(dut.io.rxd, 1)
step(12*43)
poke(dut.io.rxd,0)
step(43)
poke(dut.io.rxd,0) //1
step(43)
poke(dut.io.rxd,1) //2
step(43)
poke(dut.io.rxd,0) //3
step(43)
poke(dut.io.rxd,1) //4
step(43)
poke(dut.io.rxd,1) //5
step(43)
poke(dut.io.rxd,1) //6
step(43)
poke(dut.io.rxd,0) //7
step(43)
poke(dut.io.rxd,0) //8
step(43)
poke(dut.io.rxd,1) //S1
step(43)
poke(dut.io.rxd,1) //S2
step(43)
step(12*43)
}
// class TestRxSpec extends FlatSpec with Matchers {
// "TestRX" should "pass" in {
// Driver.execute(
// Array("--generate-vcd-output","on"),
// () => new Rx(50*1000*1000,115200*10)) {
// c => new TestRx(c)
// } should be (true)
// }
// }
class TestEchoSpec extends FlatSpec with Matchers {
"TestEcho" should "pass" in {
Driver.execute(
Array("--generate-vcd-output","on"),
() => new Echo(50*1000*1000,115200*10)) {
c => new TestRx(c)
} should be (true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment