AxiMuxSuite.scala 3.08 KB
Newer Older
Jens Korinth's avatar
Jens Korinth committed
1
2
3
package chisel.axiutils.axi4
import  chisel.axiutils._
import  chisel.miscutils.Logging
Jens Korinth's avatar
Jens Korinth committed
4
5
6
7
8
import  chisel3._
import  chisel3.util._
import  chisel3.iotesters.{ChiselFlatSpec, Driver, PeekPokeTester}
import  chisel.axi._

9
10
11
12
13
14
/**
 * Read test module for AxiMux:
 * Checks parallel reads from multiple AXI-MM masters.
 * @param n Number of parallel masters.
 * @param axi Implicit AXI interface configuration.
 **/
Jens Korinth's avatar
Jens Korinth committed
15
16
17
class AxiMuxReadTestModule(val n: Int)
                          (implicit axi: Axi4.Configuration,
                           logLevel: Logging.Level) extends Module {
Jens Korinth's avatar
Jens Korinth committed
18
19
20
  val io = IO(new Bundle {
    val afa_deq_ready = Output(UInt(n.W))
    val afa_deq_valid = Output(UInt(n.W))
Jens Korinth's avatar
Jens Korinth committed
21
    val afa_deq_bits  = Input(Vec(n, UInt(axi.dataWidth)))
Jens Korinth's avatar
Jens Korinth committed
22
  })
23
  val mux = Module(new AxiMux(n))
Jens Korinth's avatar
Jens Korinth committed
24
25
  private val asmcfg = SlaveModel.Configuration(size = Some(n * 128))
  val saxi = Module(new SlaveModel(asmcfg))
26
  private val afacfg = AxiFifoAdapter.Configuration(fifoDepth = 8, burstSize = Some(4))
27
28
29
30
31
  val afa = for (i <- 0 until n) yield Module(new AxiFifoAdapter(afacfg))
  val bases = (0 until n) map (_ * 128 * (axi.dataWidth / 8))

  mux.io.maxi <> saxi.io.saxi
  ((afa zip mux.io.saxi) zip bases) map { case ((a, s), b) => {
Jens Korinth's avatar
Jens Korinth committed
32
33
34
    a.io.maxi      <> s
    a.io.base      := b.U
    a.io.deq.ready := true.B
35
  }}
Jens Korinth's avatar
Jens Korinth committed
36
37
38
39
40
  afa.zipWithIndex map { case (a, i) =>
    io.afa_deq_ready(i) := a.io.deq.ready
    io.afa_deq_valid(i) := a.io.deq.valid
    io.afa_deq_bits(i)  <> a.io.deq.bits
  }
41
42
43
44
45
}

/**
 * Unit test for reading across an AxiMux module:
 * Connects multiple AxiFifoAdapters with increasing base addresses 
Jens Korinth's avatar
Jens Korinth committed
46
 * to single SlaveModel and checks the data for correctness.
47
48
 * No performance measurement!
 * @param m Test module.
Jens Korinth's avatar
Jens Korinth committed
49
 * @param isTrace if true, will enable tracing in Chisel PeekPokeTester.
50
 **/
Jens Korinth's avatar
Jens Korinth committed
51
52
class AxiMuxReadTester(m: AxiMuxReadTestModule)
                      (implicit axi: Axi4.Configuration) extends PeekPokeTester(m) {
53
  implicit val tester = this
Jens Korinth's avatar
Jens Korinth committed
54
  SlaveModel.fillWithLinearSeq(m.saxi, axi.dataWidth)
55
56
57
58
  reset(10)

  var counter: Array[Int] = Array.fill[Int](m.n)(0)
  def finished: Boolean = counter map (_ >= 128) reduce (_&&_)
Jens Korinth's avatar
Jens Korinth committed
59
  def handshake(i: Int) = peek(m.io.afa_deq_ready) != 0 && peek(m.io.afa_deq_valid) != 0
60
61
62
  
  while (! finished) {
    for (i <- 0 until m.n if handshake(i)) {
Jens Korinth's avatar
Jens Korinth committed
63
      val ok = peek(m.io.afa_deq_bits(i)) == counter(i) + i * 128
64
65
66
67
68
69
70
71
72
73
      assert(ok)
      if (ok) counter(i) += 1
    }
    step(1)
  }
}

/**
 * Unit test suit for AxiMux.
 **/
Jens Korinth's avatar
Jens Korinth committed
74
class AxiMuxSuite extends ChiselFlatSpec {
Jens Korinth's avatar
Jens Korinth committed
75
  implicit val logLevel = Logging.Level.Info
Jens Korinth's avatar
Jens Korinth committed
76
77
  val chiselArgs = Array("--fint-write-vcd")
  implicit val axi = Axi4.Configuration(addrWidth = AddrWidth(32), dataWidth = DataWidth(64))
78
79

  private def testMuxRead(n: Int) = {
Jens Korinth's avatar
Jens Korinth committed
80
81
82
    val args = chiselArgs ++ Array("--target-dir", "test/AxiMuxSuite/%02d".format(n))
    Driver.execute(args, () => new AxiMuxReadTestModule(n))
      { m => new AxiMuxReadTester(m) }
83
84
  }

Jens Korinth's avatar
Jens Korinth committed
85
86
87
88
  "testMuxRead1" should "be ok" in  { testMuxRead( 1) }
  "testMuxRead2" should "be ok" in  { testMuxRead( 2) }
  "testMuxRead3" should "be ok" in  { testMuxRead( 3) }
  "testMuxRead10" should "be ok" in { testMuxRead(10) }
89
}