1
0
Fork 0
rocket-chip/src/main/scala/subsystem/RTC.scala

25 lines
866 B
Scala
Raw Normal View History

// See LICENSE.SiFive for license details.
2018-01-12 21:29:27 +01:00
package freechips.rocketchip.subsystem
import Chisel._
import freechips.rocketchip.diplomacy.{LazyModuleImp, DTSTimebase}
2018-01-12 21:29:27 +01:00
import freechips.rocketchip.devices.tilelink.HasPeripheryCLINT
trait HasRTCModuleImp extends LazyModuleImp {
val outer: BaseSubsystem with HasPeripheryCLINT
private val pbusFreq = outer.p(PeripheryBusKey).frequency
private val rtcFreq = outer.p(DTSTimebase)
private val internalPeriod: BigInt = pbusFreq / rtcFreq
// check whether pbusFreq >= rtcFreq
require(internalPeriod > 0)
// check wehther the integer division is within 5% of the real division
require((pbusFreq - rtcFreq * internalPeriod) * 100 / pbusFreq <= 5)
// Use the static period to toggle the RTC
val (_, int_rtc_tick) = Counter(true.B, internalPeriod.toInt)
2017-07-25 05:24:59 +02:00
outer.clint.module.io.rtcTick := int_rtc_tick
}