2017-07-23 17:31:04 +02:00
|
|
|
// See LICENSE.SiFive for license details.
|
|
|
|
|
2018-01-12 21:29:27 +01:00
|
|
|
package freechips.rocketchip.subsystem
|
2017-07-23 17:31:04 +02:00
|
|
|
|
|
|
|
import Chisel._
|
2017-09-14 03:06:03 +02:00
|
|
|
import freechips.rocketchip.diplomacy.{LazyModuleImp, DTSTimebase}
|
2018-01-12 21:29:27 +01:00
|
|
|
import freechips.rocketchip.devices.tilelink.HasPeripheryCLINT
|
2017-07-23 17:31:04 +02:00
|
|
|
|
2017-09-14 03:06:03 +02:00
|
|
|
trait HasRTCModuleImp extends LazyModuleImp {
|
2018-02-21 02:10:16 +01:00
|
|
|
val outer: BaseSubsystem with HasPeripheryCLINT
|
2017-09-09 03:33:44 +02:00
|
|
|
private val pbusFreq = outer.p(PeripheryBusKey).frequency
|
2017-07-25 09:55:55 +02:00
|
|
|
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)
|
2017-07-23 17:31:04 +02:00
|
|
|
|
|
|
|
// Use the static period to toggle the RTC
|
2017-07-25 09:55:55 +02:00
|
|
|
val (_, int_rtc_tick) = Counter(true.B, internalPeriod.toInt)
|
2017-07-23 17:31:04 +02:00
|
|
|
|
2017-07-25 05:24:59 +02:00
|
|
|
outer.clint.module.io.rtcTick := int_rtc_tick
|
2017-07-23 17:31:04 +02:00
|
|
|
}
|