提交 891d22aa 编写于 作者: Z Zihao Yu

device,AXI4Timer: support mtime and mtimecmp

上级 0b7e82e7
...@@ -6,9 +6,25 @@ import chisel3.util._ ...@@ -6,9 +6,25 @@ import chisel3.util._
import bus.axi4._ import bus.axi4._
import utils._ import utils._
class AXI4Timer extends AXI4SlaveModule(new AXI4Lite) { class TimerIO extends Bundle {
val clk = 40000 // 40MHz / 1000 val mtip = Output(Bool())
}
class AXI4Timer(sim: Boolean = false) extends AXI4SlaveModule(new AXI4Lite, new TimerIO) {
val mtime = RegInit(0.U(64.W)) // unit: ms
val mtimecmp = RegInit(0.U(64.W))
val clk = (if (!sim) 40000 /* 40MHz / 1000 */ else 2000)
val tick = Counter(true.B, clk)._2 val tick = Counter(true.B, clk)._2
val ms = Counter(tick, 0x40000000)._1 when (tick) { mtime := mtime + 1.U }
in.r.bits.data := ms
val mapping = Map(
RegMap(0x0, mtime),
RegMap(0x8, mtimecmp)
)
RegMap.generate(mapping, raddr(3,0), in.r.bits.data,
waddr(3,0), in.w.fire(), in.w.bits.data, MaskExpand(in.w.bits.strb))
io.extra.get.mtip := mtime >= mtimecmp
} }
...@@ -35,7 +35,7 @@ class SimMMIO extends Module { ...@@ -35,7 +35,7 @@ class SimMMIO extends Module {
xbar.io.in(0) <> io.rw xbar.io.in(0) <> io.rw
val uart = Module(new AXI4UART) val uart = Module(new AXI4UART)
val timer = Module(new AXI4Timer) val timer = Module(new AXI4Timer(sim = true))
val vga = Module(new AXI4VGA(sim = true)) val vga = Module(new AXI4VGA(sim = true))
uart.io.in <> xbar.io.out(0).toAXI4Lite() uart.io.in <> xbar.io.out(0).toAXI4Lite()
timer.io.in <> xbar.io.out(1).toAXI4Lite() timer.io.in <> xbar.io.out(1).toAXI4Lite()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册