AXI4Timer.scala 999 字节
Newer Older
Z
Zihao Yu 已提交
1 2 3 4 5 6 7
// See LICENSE.SiFive for license details.

package device

import chisel3._
import chisel3.util._

8
import bus.axi4._
Z
Zihao Yu 已提交
9

Z
Zihao Yu 已提交
10
class AXI4Timer extends Module {
Z
Zihao Yu 已提交
11
  val io = IO(new Bundle{
Z
Zihao Yu 已提交
12
    val in = Flipped(new AXI4Lite)
Z
Zihao Yu 已提交
13 14 15 16 17 18 19 20
  })

  val in = io.in

  val clk = 50000 // 50MHz / 1000
  val tick = Counter(true.B, clk)._2
  val ms = Counter(tick, 0x40000000)._1

21 22 23 24 25 26 27
  // deal with non-rready master
  val rInflight = RegInit(false.B)
  when (in.ar.fire()) { rInflight := true.B }
  when (in. r.fire()) { rInflight := false.B }

  in.ar.ready := in.r.ready || !rInflight
  in.r.valid := rInflight
Z
Zihao Yu 已提交
28 29
  in.r.bits.data := ms
  in.r.bits.resp := AXI4Parameters.RESP_OKAY
30 31 32 33 34 35 36 37 38

  // deal with non-bready master
  val wInflight = RegInit(false.B)
  when (in.aw.fire()) { wInflight := true.B }
  when (in. b.fire()) { wInflight := false.B }

  in.aw.ready := in.w.valid && (in.b.ready || !wInflight)
  in.w.ready := in.aw.valid && (in.b.ready || !wInflight)
  in.b.valid := wInflight
Z
Zihao Yu 已提交
39 40
  in.b.bits.resp := AXI4Parameters.RESP_OKAY
}