diff options
Diffstat (limited to 'src/main/scala/chisel3/util/Counter.scala')
| -rw-r--r-- | src/main/scala/chisel3/util/Counter.scala | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/main/scala/chisel3/util/Counter.scala b/src/main/scala/chisel3/util/Counter.scala index 5910c703..ef1eff9f 100644 --- a/src/main/scala/chisel3/util/Counter.scala +++ b/src/main/scala/chisel3/util/Counter.scala @@ -3,7 +3,7 @@ package chisel3.util import chisel3._ -import chisel3.internal.naming.chiselName // can't use chisel3_ version because of compile order +import chisel3.internal.naming.chiselName // can't use chisel3_ version because of compile order /** Used to generate an inline (logic directly in the containing Module, no internal Module is created) * hardware counter. @@ -42,11 +42,13 @@ class Counter private (r: Range, oldN: Option[Int] = None) { */ def n: Int = oldN match { case Some(x) => x - case None => + case None => // Reasonable for typical ranges - require(r.start == 0 && r.step == 1, + require( + r.start == 0 && r.step == 1, s"Counter.n only defined on ranges starting at 0 with step == 1, got $r. " + - "Use underlying range.") + "Use underlying range." + ) r.last + 1 } @@ -98,14 +100,14 @@ class Counter private (r: Range, oldN: Option[Int] = None) { } } -object Counter -{ +object Counter { + /** Instantiate a [[Counter! counter]] with the specified number of counts. */ def apply(n: Int): Counter = new Counter(n) /** Instantiate a [[Counter! counter]] with the specified number of counts and a gate. - * + * * @param cond condition that controls whether the counter increments this cycle * @param n number of counts before the counter resets * @return tuple of the counter value and whether the counter will wrap (the value is at @@ -115,7 +117,7 @@ object Counter def apply(cond: Bool, n: Int): (UInt, Bool) = { val c = new Counter(n) val wrap = WireInit(false.B) - when (cond) { wrap := c.inc() } + when(cond) { wrap := c.inc() } (c.value, wrap) } |
