summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3/util/Counter.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/chisel3/util/Counter.scala')
-rw-r--r--src/main/scala/chisel3/util/Counter.scala10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/main/scala/chisel3/util/Counter.scala b/src/main/scala/chisel3/util/Counter.scala
index f6f99f67..dbfd5bdd 100644
--- a/src/main/scala/chisel3/util/Counter.scala
+++ b/src/main/scala/chisel3/util/Counter.scala
@@ -5,10 +5,13 @@ package chisel3.util
import chisel3._
import chisel3.internal.naming.chiselName // can't use chisel3_ version because of compile order
-/** A counter module
+/** Used to generate an inline (logic directly in the containing Module, no internal Module is created)
+ * hardware counter.
*
* Typically instantiated with apply methods in [[Counter$ object Counter]]
*
+ * Does not create a new Chisel Module
+ *
* @example {{{
* val countOn = true.B // increment counter every clock cycle
* val (counterValue, counterWrap) = Counter(countOn, 4)
@@ -59,6 +62,11 @@ object Counter
@chiselName
def apply(cond: Bool, n: Int): (UInt, Bool) = {
val c = new Counter(n)
+ // Note this use of var is generally frowned upon! Don't use this as an example.
+ // This is done because we wanted the hardware generated by c.inc() to be wrapped
+ // in a when statement, but still needed to refer to the final value returned by
+ // c.inc() so we could return cond && wrap. Unless you really, really know what
+ // you are doing, IGNORE THIS CODE!!!!!
var wrap: Bool = null
when (cond) { wrap = c.inc() }
(c.value, cond && wrap)