generators.scala 2.38 KB
Newer Older
1
2
package chisel.axi
import  chisel.miscutils.generators._
3
4
5
import  org.scalacheck.{Arbitrary, Gen}

package object generators {
6
7
8
9
10
11
12
13
  val addrWidthGen: Gen[AddrWidth]     = genLimited(1, 64) map (AddrWidth(_))
  val userWidthGen: Gen[UserWidth]     = Gen.frequency(
    90 -> UserWidth(0),
    10 -> (genLimited(1, 15) map (UserWidth(_)))
  )
  val idWidthGen: Gen[IdWidth]         = genLimited(0, 15) map (IdWidth(_))
  val regionWidthGen: Gen[RegionWidth] = genLimited(0, 4) map (RegionWidth(_))

14
  object Axi4 {
15
16
17
    import chisel.axi.Axi4._
    val dataWidthGen: Gen[DataWidth]   = genLimited(1, 4096) map (DataWidth(_))

18
19
20
21
22
23
24
25
26
27
28
    val configurationGen: Gen[chisel.axi.Axi4.Configuration] = for {
      addrWidth   <- addrWidthGen
      dataWidth   <- dataWidthGen
      userWidth   <- userWidthGen
      idWidth     <- idWidthGen
      regionWidth <- regionWidthGen
      hasQoS      <- Arbitrary.arbBool.arbitrary
    } yield chisel.axi.Axi4.Configuration(addrWidth, dataWidth, idWidth, userWidth, regionWidth, hasQoS)
  }

  object Axi4Lite {
29
    import chisel.axi.Axi4Lite._
Jens Korinth's avatar
Jens Korinth committed
30
    import chisel.axi.axi4lite._ // FIXME
31
32
    import chisel3._

33
34
    scala.util.Random.setSeed(42)

35
    val dataWidthGen: Gen[DataWidth] = Gen.oneOf(Width32, Width64)
36
37
38
39
40
41
42

    val configurationGen: Gen[chisel.axi.Axi4Lite.Configuration] = for {
      addrWidth   <- addrWidthGen
      dataWidth   <- dataWidthGen
      userWidth   <- userWidthGen
      regionWidth <- regionWidthGen
    } yield chisel.axi.Axi4Lite.Configuration(addrWidth, dataWidth, userWidth, regionWidth)
43

44
45
46
    def valueGen(width: DataWidth): Gen[BigInt] = for {
      v <- Gen.choose(0L, (1L << width) - 1)
    } yield BigInt(v)
47
48
49
50
51

    def constRegGen(width: DataWidth): Gen[ConstantRegister] = for {
      v <- valueGen(width)
    } yield new ConstantRegister(value = v)

52
53
54
    def basicRegGen(width: DataWidth): Gen[Register] = for {
      x <- Gen.posNum[Int]
    } yield new Register(width = width)
55

56
57
    def maybeRegGen(width: DataWidth): () => Gen[Option[ControlRegister]] = () =>
      Gen.option(Gen.oneOf(basicRegGen(width), constRegGen(width)))
58

59
60
61
    def registerMapGen(width: DataWidth): Gen[Map[Int, Option[ControlRegister]]] =
      Gen.nonEmptyBuildableOf[Seq[Option[ControlRegister]], Option[ControlRegister]](maybeRegGen(width)()) 
        .map (_.zipWithIndex.map { case (r, i) => (i * (width / 8), r) }.toMap)
62
        .retryUntil (l => (l map (_._2.nonEmpty) fold false) (_ || _))
63
64
  }
}