move tilelink-agnostic counters from uncore to util package
This commit is contained in:
parent
1882241493
commit
bdb7b1de36
@ -2,40 +2,9 @@ package uncore.util
|
||||
|
||||
import Chisel._
|
||||
import uncore.tilelink._
|
||||
import util.TwoWayCounter
|
||||
import cde.Parameters
|
||||
|
||||
// Produces 0-width value when counting to 1
|
||||
class ZCounter(val n: Int) {
|
||||
val value = Reg(init=UInt(0, log2Ceil(n)))
|
||||
def inc(): Bool = {
|
||||
if (n == 1) Bool(true)
|
||||
else {
|
||||
val wrap = value === UInt(n-1)
|
||||
value := Mux(Bool(!isPow2(n)) && wrap, UInt(0), value + UInt(1))
|
||||
wrap
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object ZCounter {
|
||||
def apply(n: Int) = new ZCounter(n)
|
||||
def apply(cond: Bool, n: Int): (UInt, Bool) = {
|
||||
val c = new ZCounter(n)
|
||||
var wrap: Bool = null
|
||||
when (cond) { wrap = c.inc() }
|
||||
(c.value, cond && wrap)
|
||||
}
|
||||
}
|
||||
|
||||
object TwoWayCounter {
|
||||
def apply(up: Bool, down: Bool, max: Int): UInt = {
|
||||
val cnt = Reg(init = UInt(0, log2Up(max+1)))
|
||||
when (up && !down) { cnt := cnt + UInt(1) }
|
||||
when (down && !up) { cnt := cnt - UInt(1) }
|
||||
cnt
|
||||
}
|
||||
}
|
||||
|
||||
class BeatCounterStatus extends Bundle {
|
||||
val idx = UInt()
|
||||
val done = Bool()
|
||||
|
36
src/main/scala/util/Counters.scala
Normal file
36
src/main/scala/util/Counters.scala
Normal file
@ -0,0 +1,36 @@
|
||||
package util
|
||||
|
||||
import Chisel._
|
||||
import cde.Parameters
|
||||
|
||||
// Produces 0-width value when counting to 1
|
||||
class ZCounter(val n: Int) {
|
||||
val value = Reg(init=UInt(0, log2Ceil(n)))
|
||||
def inc(): Bool = {
|
||||
if (n == 1) Bool(true)
|
||||
else {
|
||||
val wrap = value === UInt(n-1)
|
||||
value := Mux(Bool(!isPow2(n)) && wrap, UInt(0), value + UInt(1))
|
||||
wrap
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object ZCounter {
|
||||
def apply(n: Int) = new ZCounter(n)
|
||||
def apply(cond: Bool, n: Int): (UInt, Bool) = {
|
||||
val c = new ZCounter(n)
|
||||
var wrap: Bool = null
|
||||
when (cond) { wrap = c.inc() }
|
||||
(c.value, cond && wrap)
|
||||
}
|
||||
}
|
||||
|
||||
object TwoWayCounter {
|
||||
def apply(up: Bool, down: Bool, max: Int): UInt = {
|
||||
val cnt = Reg(init = UInt(0, log2Up(max+1)))
|
||||
when (up && !down) { cnt := cnt + UInt(1) }
|
||||
when (down && !up) { cnt := cnt - UInt(1) }
|
||||
cnt
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user