2015-08-13 06:23:17 +02:00
|
|
|
package uncore
|
|
|
|
|
|
|
|
import Chisel._
|
2015-09-25 21:07:03 +02:00
|
|
|
import junctions._
|
2015-08-13 06:23:17 +02:00
|
|
|
|
2015-09-25 21:07:03 +02:00
|
|
|
class RTC(pcr_MTIME: Int) extends Module with HTIFParameters {
|
2015-09-25 01:58:20 +02:00
|
|
|
val io = new NASTIIO
|
2015-08-13 06:23:17 +02:00
|
|
|
|
|
|
|
private val addrMap = params(NASTIAddrHashMap)
|
|
|
|
|
|
|
|
val addrTable = Vec.tabulate(nCores) { i =>
|
2015-09-25 21:07:03 +02:00
|
|
|
UInt(addrMap(s"conf:csr$i").start + pcr_MTIME * scrDataBytes)
|
2015-08-13 06:23:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
val rtc = Reg(init=UInt(0,64))
|
|
|
|
val rtc_tick = Counter(params(RTCPeriod)).inc()
|
|
|
|
|
|
|
|
val sending_addr = Reg(init = Bool(false))
|
|
|
|
val sending_data = Reg(init = Bool(false))
|
|
|
|
val send_acked = Reg(init = Vec(nCores, Bool(true)))
|
2015-09-25 21:07:27 +02:00
|
|
|
val coreId = Wire(UInt(width = log2Up(nCores)))
|
2015-08-13 06:23:17 +02:00
|
|
|
|
|
|
|
when (rtc_tick) {
|
|
|
|
rtc := rtc + UInt(1)
|
|
|
|
send_acked := Vec(nCores, Bool(false))
|
|
|
|
sending_addr := Bool(true)
|
|
|
|
sending_data := Bool(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nCores > 1) {
|
2015-09-25 21:07:27 +02:00
|
|
|
val (addr_send_cnt, addr_send_done) = Counter(io.aw.fire(), nCores)
|
2015-08-13 06:23:17 +02:00
|
|
|
val (_, data_send_done) = Counter(io.w.fire(), nCores)
|
|
|
|
|
|
|
|
when (addr_send_done) { sending_addr := Bool(false) }
|
|
|
|
when (data_send_done) { sending_data := Bool(false) }
|
|
|
|
|
2015-09-25 21:07:27 +02:00
|
|
|
coreId := addr_send_cnt
|
2015-08-13 06:23:17 +02:00
|
|
|
} else {
|
|
|
|
when (io.aw.fire()) { sending_addr := Bool(false) }
|
|
|
|
when (io.w.fire()) { sending_addr := Bool(false) }
|
|
|
|
|
2015-09-25 21:07:27 +02:00
|
|
|
coreId := UInt(0)
|
2015-08-13 06:23:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
when (io.b.fire()) { send_acked(io.b.bits.id) := Bool(true) }
|
|
|
|
|
|
|
|
io.aw.valid := sending_addr
|
2015-09-25 21:07:27 +02:00
|
|
|
io.aw.bits := NASTIWriteAddressChannel(
|
|
|
|
id = coreId,
|
|
|
|
addr = addrTable(coreId),
|
|
|
|
size = UInt(log2Up(scrDataBytes)))
|
2015-08-13 06:23:17 +02:00
|
|
|
|
|
|
|
io.w.valid := sending_data
|
2015-09-25 21:07:27 +02:00
|
|
|
io.w.bits := NASTIWriteDataChannel(data = rtc)
|
2015-08-13 06:23:17 +02:00
|
|
|
|
|
|
|
io.b.ready := Bool(true)
|
|
|
|
io.ar.valid := Bool(false)
|
|
|
|
io.r.ready := Bool(false)
|
|
|
|
|
2015-09-25 21:07:27 +02:00
|
|
|
assert(!rtc_tick || send_acked.reduce(_ && _),
|
2015-08-13 06:23:17 +02:00
|
|
|
s"Not all clocks were updated for rtc tick")
|
|
|
|
}
|