package.scala 1.85 KB
Newer Older
Jens Korinth's avatar
Jens Korinth committed
1
2
package chisel
import  chisel3._
Jens Korinth's avatar
Jens Korinth committed
3
import  chisel3.util.Enum
Jens Korinth's avatar
Jens Korinth committed
4
5
6
import  chisel3.internal.firrtl.Width

package object axi {
Jens Korinth's avatar
Jens Korinth committed
7
  private[axi] trait WidthLike { def width: Int; def toInt: Int = this }
Jens Korinth's avatar
Jens Korinth committed
8
9
10
11
12
13
14
15
16
  final case class AddrWidth(width: Int) extends WidthLike {
    require (width > 0 && width <= 64, "addrWidth (%d) must be 0 < addrWidth <= 64".format(width))
  }
  final case class IdWidth(width: Int) extends WidthLike
  final case class UserWidth(width: Int) extends WidthLike
  final case class RegionWidth(width: Int) extends WidthLike

  implicit def fromWidthLikeToWidth(wl: WidthLike): Width = wl.width.W
  implicit def fromWidthLikeToInt(wl: WidthLike): Int     = wl.width
Jens Korinth's avatar
Jens Korinth committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

  class Protection extends Bundle {
    val prot = UInt(3.W)
  }

  object Protection {
    sealed trait Flag extends Function[Int, Int]  { def apply(i: Int): Int }
    object Flag {
      final case object NON_PRIVILEGED extends Flag { def apply(i: Int): Int = i & ~(1 << 0) }
      final case object PRIVILEGED extends Flag     { def apply(i: Int): Int = i |  (1 << 0) }
      final case object SECURE extends Flag         { def apply(i: Int): Int = i & ~(1 << 1) }
      final case object NON_SECURE extends Flag     { def apply(i: Int): Int = i |  (1 << 1) }
      final case object DATA extends Flag           { def apply(i: Int): Int = i & ~(1 << 2) }
      final case object INSTRUCTION extends Flag    { def apply(i: Int): Int = i |  (1 << 2) }
    }
    def apply(fs: Flag*): Int = (fs fold (identity[Int] _)) (_ andThen _) (0)
  }

  object Response {
    val okay :: exokay :: slverr :: decerr :: Nil = Enum(4)
  }

  class Strobe(dataWidth: Int) extends Bundle {
    val strb = UInt((dataWidth / 8).W)

    override def cloneType = { new Strobe(dataWidth).asInstanceOf[this.type] }
  }

  object Strobe {
    def apply(byteEnables: Int*): UInt = ((byteEnables map (i => (1 << i)) fold 0) (_ | _)).U
  }
Jens Korinth's avatar
Jens Korinth committed
48
}