2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.Berkeley for license details.
|
|
|
|
|
2017-07-07 19:48:16 +02:00
|
|
|
package freechips.rocketchip.util
|
2016-09-22 05:17:32 +02:00
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
|
2017-02-17 19:34:44 +01:00
|
|
|
/** This black-boxes a Clock Divider by 2.
|
|
|
|
* The output clock is phase-aligned to the input clock.
|
|
|
|
* If you use this in synthesis, make sure your sdc
|
|
|
|
* declares that you want it to do the same.
|
|
|
|
*
|
|
|
|
* Because Chisel does not support
|
|
|
|
* blocking assignments, it is impossible
|
|
|
|
* to create a deterministic divided clock.
|
|
|
|
*/
|
2017-02-17 11:49:35 +01:00
|
|
|
class ClockDivider2 extends BlackBox {
|
2016-09-22 05:17:32 +02:00
|
|
|
val io = new Bundle {
|
2017-02-17 11:49:35 +01:00
|
|
|
val clk_out = Clock(OUTPUT)
|
|
|
|
val clk_in = Clock(INPUT)
|
2016-09-22 05:17:32 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-14 22:29:36 +02:00
|
|
|
class ClockDivider3 extends BlackBox {
|
|
|
|
val io = new Bundle {
|
|
|
|
val clk_out = Clock(OUTPUT)
|
|
|
|
val clk_in = Clock(INPUT)
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 05:17:32 +02:00
|
|
|
|
|
|
|
/** Divide the clock by power of 2 times.
|
|
|
|
* @param pow2 divides the clock 2 ^ pow2 times
|
|
|
|
* WARNING: This is meant for simulation use only. */
|
|
|
|
class Pow2ClockDivider(pow2: Int) extends Module {
|
|
|
|
val io = new Bundle {
|
|
|
|
val clock_out = Clock(OUTPUT)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pow2 == 0) {
|
|
|
|
io.clock_out := clock
|
|
|
|
} else {
|
|
|
|
val dividers = Seq.fill(pow2) { Module(new ClockDivider2) }
|
|
|
|
|
|
|
|
dividers.init.zip(dividers.tail).map { case (last, next) =>
|
2017-02-17 11:49:35 +01:00
|
|
|
next.io.clk_in := last.io.clk_out
|
2016-09-22 05:17:32 +02:00
|
|
|
}
|
|
|
|
|
2017-02-17 11:49:35 +01:00
|
|
|
dividers.head.io.clk_in := clock
|
|
|
|
io.clock_out := dividers.last.io.clk_out
|
2016-09-22 05:17:32 +02:00
|
|
|
}
|
|
|
|
}
|