summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorJim Lawson2016-09-30 12:13:58 -0700
committerGitHub2016-09-30 12:13:58 -0700
commitdb25e8180a53fb8f4912fd37b7a613e15a01564f (patch)
tree8bb5597746002ac98641f394cee4c94e1d154aff /src/main
parent785620b1403d827986bf60c2a001d8d6f71eed72 (diff)
parent6edbdf279257d656b5eac38d9de8645a068611bf (diff)
Merge pull request #265 from ucb-bar/gsdt
Gsdt - Fixup to Chisel connections and direction - PR 200 revisited.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/chisel3/Driver.scala2
-rw-r--r--src/main/scala/chisel3/compatibility.scala101
-rw-r--r--src/main/scala/chisel3/compatibility/debug.scala2
-rw-r--r--src/main/scala/chisel3/package.scala124
-rw-r--r--src/main/scala/chisel3/testers/BasicTester.scala5
-rw-r--r--src/main/scala/chisel3/util/Arbiter.scala10
-rw-r--r--src/main/scala/chisel3/util/BitPat.scala8
-rw-r--r--src/main/scala/chisel3/util/Bitwise.scala2
-rw-r--r--src/main/scala/chisel3/util/Counter.scala1
-rw-r--r--src/main/scala/chisel3/util/Decoupled.scala120
-rw-r--r--src/main/scala/chisel3/util/LFSR.scala1
-rw-r--r--src/main/scala/chisel3/util/Reg.scala5
-rw-r--r--src/main/scala/chisel3/util/TransitName.scala4
-rw-r--r--src/main/scala/chisel3/util/Valid.scala32
-rw-r--r--src/main/scala/chisel3/util/util.scala12
15 files changed, 288 insertions, 141 deletions
diff --git a/src/main/scala/chisel3/Driver.scala b/src/main/scala/chisel3/Driver.scala
index 5aeeef99..5e0a3a0f 100644
--- a/src/main/scala/chisel3/Driver.scala
+++ b/src/main/scala/chisel3/Driver.scala
@@ -47,7 +47,7 @@ trait BackendCompilationUtilities {
* C++ sources and headers as well as a makefile to compile them.
*
* @param dutFile name of the DUT .v without the .v extension
- * @param name of the top-level module in the design
+ * @param topModule of the top-level module in the design
* @param dir output directory
* @param vSources list of additional Verilog sources to compile
* @param cppHarness C++ testharness to compile/link against
diff --git a/src/main/scala/chisel3/compatibility.scala b/src/main/scala/chisel3/compatibility.scala
index 56c92d24..d13fcb06 100644
--- a/src/main/scala/chisel3/compatibility.scala
+++ b/src/main/scala/chisel3/compatibility.scala
@@ -3,13 +3,27 @@
// Allows legacy users to continue using Chisel (capital C) package name while
// moving to the more standard package naming convention chisel3 (lowercase c).
-package object Chisel {
+package object Chisel { // scalastyle:ignore package.object.name
+ implicit val defaultCompileOptions = chisel3.core.ExplicitCompileOptions.NotStrict
type Direction = chisel3.core.Direction
- val INPUT = chisel3.core.INPUT
- val OUTPUT = chisel3.core.OUTPUT
- val NO_DIR = chisel3.core.NO_DIR
+ val INPUT = chisel3.core.Direction.Input
+ val OUTPUT = chisel3.core.Direction.Output
+ val NODIR = chisel3.core.Direction.Unspecified
+ object Flipped {
+ def apply[T<:Data](target: T): T = chisel3.core.Flipped[T](target)
+ }
+ // TODO: Possibly move the AddDirectionToData class here?
+ implicit class AddDirMethodToData[T<:Data](val target: T) extends AnyVal {
+ def dir: Direction = {
+ target match {
+ case e: Element => e.dir
+ case _ => chisel3.core.Direction.Unspecified
+ }
+ }
+ }
+
+ type ChiselException = chisel3.internal.ChiselException
- type Flipped = chisel3.core.Flipped
type Data = chisel3.core.Data
val Wire = chisel3.core.Wire
val Clock = chisel3.core.Clock
@@ -54,6 +68,46 @@ package object Chisel {
val when = chisel3.core.when
type WhenContext = chisel3.core.WhenContext
+ import chisel3.internal.firrtl.Width
+ /**
+ * These implicit classes allow one to convert scala.Int|scala.BigInt to
+ * Chisel.UInt|Chisel.SInt by calling .asUInt|.asSInt on them, respectively.
+ * The versions .asUInt(width)|.asSInt(width) are also available to explicitly
+ * mark a width for the new literal.
+ *
+ * Also provides .asBool to scala.Boolean and .asUInt to String
+ *
+ * Note that, for stylistic reasons, one should avoid extracting immediately
+ * after this call using apply, ie. 0.asUInt(1)(0) due to potential for
+ * confusion (the 1 is a bit length and the 0 is a bit extraction position).
+ * Prefer storing the result and then extracting from it.
+ */
+ implicit class fromIntToLiteral(val x: Int) extends AnyVal {
+ def U: UInt = UInt(BigInt(x), Width()) // scalastyle:ignore method.name
+ def S: SInt = SInt(BigInt(x), Width()) // scalastyle:ignore method.name
+
+ def asUInt(): UInt = UInt(x, Width())
+ def asSInt(): SInt = SInt(x, Width())
+ def asUInt(width: Int): UInt = UInt(x, width)
+ def asSInt(width: Int): SInt = SInt(x, width)
+ }
+
+ implicit class fromBigIntToLiteral(val x: BigInt) extends AnyVal {
+ def U: UInt = UInt(x, Width()) // scalastyle:ignore method.name
+ def S: SInt = SInt(x, Width()) // scalastyle:ignore method.name
+
+ def asUInt(): UInt = UInt(x, Width())
+ def asSInt(): SInt = SInt(x, Width())
+ def asUInt(width: Int): UInt = UInt(x, width)
+ def asSInt(width: Int): SInt = SInt(x, width)
+ }
+ implicit class fromStringToLiteral(val x: String) extends AnyVal {
+ def U: UInt = UInt(x) // scalastyle:ignore method.name
+ }
+ implicit class fromBooleanToLiteral(val x: Boolean) extends AnyVal {
+ def B: Bool = Bool(x) // scalastyle:ignore method.name
+ }
+
type BackendCompilationUtilities = chisel3.BackendCompilationUtilities
val Driver = chisel3.Driver
@@ -62,7 +116,7 @@ package object Chisel {
val throwException = chisel3.compatibility.throwException
val debug = chisel3.compatibility.debug
- object testers {
+ object testers { // scalastyle:ignore object.name
type BasicTester = chisel3.testers.BasicTester
val TesterDriver = chisel3.testers.TesterDriver
}
@@ -102,10 +156,27 @@ package object Chisel {
val Counter = chisel3.util.Counter
type DecoupledIO[+T <: Data] = chisel3.util.DecoupledIO[T]
+ val DecoupledIO = chisel3.util.Decoupled
val Decoupled = chisel3.util.Decoupled
- type EnqIO[T <: Data] = chisel3.util.EnqIO[T]
- type DeqIO[T <: Data] = chisel3.util.DeqIO[T]
- type DecoupledIOC[+T <: Data] = chisel3.util.DecoupledIOC[T]
+ class EnqIO[+T <: Data](gen: T) extends DecoupledIO(gen) {
+ def init(): Unit = {
+ this.noenq()
+ }
+ override def cloneType: this.type = EnqIO(gen).asInstanceOf[this.type]
+ }
+ class DeqIO[+T <: Data](gen: T) extends DecoupledIO(gen) {
+ chisel3.core.Binding.bind(this, chisel3.core.FlippedBinder, "Error: Cannot flip ")
+ def init(): Unit = {
+ this.nodeq()
+ }
+ override def cloneType: this.type = DeqIO(gen).asInstanceOf[this.type]
+ }
+ object EnqIO {
+ def apply[T<:Data](gen: T): DecoupledIO[T] = DecoupledIO(gen)
+ }
+ object DeqIO {
+ def apply[T<:Data](gen: T): DecoupledIO[T] = Flipped(DecoupledIO(gen))
+ }
type QueueIO[T <: Data] = chisel3.util.QueueIO[T]
type Queue[T <: Data] = chisel3.util.Queue[T]
val Queue = chisel3.util.Queue
@@ -132,19 +203,9 @@ package object Chisel {
val RegEnable = chisel3.util.RegEnable
val ShiftRegister = chisel3.util.ShiftRegister
- type ValidIO[+T <: Data] = chisel3.util.ValidIO[T]
+ type ValidIO[+T <: Data] = chisel3.util.Valid[T]
val Valid = chisel3.util.Valid
val Pipe = chisel3.util.Pipe
type Pipe[T <: Data] = chisel3.util.Pipe[T]
-
- import chisel3.internal.firrtl.Width
- implicit def fromBigIntToLiteral(x: BigInt): chisel3.fromBigIntToLiteral =
- new chisel3.fromBigIntToLiteral(x)
- implicit def fromIntToLiteral(x: Int): chisel3.fromIntToLiteral=
- new chisel3.fromIntToLiteral(x)
- implicit def fromStringToLiteral(x: String): chisel3.fromStringToLiteral=
- new chisel3.fromStringToLiteral(x)
- implicit def fromBooleanToLiteral(x: Boolean): chisel3.fromBooleanToLiteral=
- new chisel3.fromBooleanToLiteral(x)
}
diff --git a/src/main/scala/chisel3/compatibility/debug.scala b/src/main/scala/chisel3/compatibility/debug.scala
index c3966dae..d9f6e4b0 100644
--- a/src/main/scala/chisel3/compatibility/debug.scala
+++ b/src/main/scala/chisel3/compatibility/debug.scala
@@ -1,3 +1,5 @@
+// See LICENSE for license details.
+
package chisel3.compatibility
import chisel3.core._
diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala
index 30e2b5c3..17ddd55a 100644
--- a/src/main/scala/chisel3/package.scala
+++ b/src/main/scala/chisel3/package.scala
@@ -1,16 +1,21 @@
-package object chisel3 {
+// See LICENSE for license details.
+
+package object chisel3 { // scalastyle:ignore package.object.name
import scala.language.experimental.macros
import internal.firrtl.Width
import internal.sourceinfo.{SourceInfo, SourceInfoTransform}
import util.BitPat
+ import chisel3.core.{Binding, FlippedBinder}
+ import chisel3.util._
+ import chisel3.internal.firrtl.Port
type Direction = chisel3.core.Direction
- val INPUT = chisel3.core.INPUT
- val OUTPUT = chisel3.core.OUTPUT
- val NO_DIR = chisel3.core.NO_DIR
- type Flipped = chisel3.core.Flipped
+ val Input = chisel3.core.Input
+ val Output = chisel3.core.Output
+ val Flipped = chisel3.core.Flipped
+
type Data = chisel3.core.Data
val Wire = chisel3.core.Wire
val Clock = chisel3.core.Clock
@@ -76,31 +81,6 @@ package object chisel3 {
val FullName = chisel3.core.FullName
val Percent = chisel3.core.Percent
- implicit class fromBigIntToLiteral(val x: BigInt) extends AnyVal {
- def U: UInt = UInt(x, Width())
- def S: SInt = SInt(x, Width())
- }
- implicit class fromIntToLiteral(val x: Int) extends AnyVal {
- def U: UInt = UInt(BigInt(x), Width())
- def S: SInt = SInt(BigInt(x), Width())
- }
- implicit class fromStringToLiteral(val x: String) extends AnyVal {
- def U: UInt = UInt(x)
- }
- implicit class fromBooleanToLiteral(val x: Boolean) extends AnyVal {
- def B: Bool = Bool(x)
- }
-
- implicit class fromUIntToBitPatComparable(val x: UInt) extends AnyVal {
- final def === (that: BitPat): Bool = macro SourceInfoTransform.thatArg
- final def != (that: BitPat): Bool = macro SourceInfoTransform.thatArg
- final def =/= (that: BitPat): Bool = macro SourceInfoTransform.thatArg
-
- def do_=== (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that === x
- def do_!= (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that != x
- def do_=/= (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that =/= x
- }
-
/** Implicit for custom Printable string interpolator */
implicit class PrintableHelper(val sc: StringContext) extends AnyVal {
/** Custom string interpolator for generating Printables: p"..."
@@ -130,4 +110,88 @@ package object chisel3 {
}
implicit def string2Printable(str: String): Printable = PString(str)
+
+ /**
+ * These implicit classes allow one to convert scala.Int|scala.BigInt to
+ * Chisel.UInt|Chisel.SInt by calling .asUInt|.asSInt on them, respectively.
+ * The versions .asUInt(width)|.asSInt(width) are also available to explicitly
+ * mark a width for the new literal.
+ *
+ * Also provides .asBool to scala.Boolean and .asUInt to String
+ *
+ * Note that, for stylistic reasons, one should avoid extracting immediately
+ * after this call using apply, ie. 0.asUInt(1)(0) due to potential for
+ * confusion (the 1 is a bit length and the 0 is a bit extraction position).
+ * Prefer storing the result and then extracting from it.
+ */
+ implicit class fromIntToLiteral(val x: Int) extends AnyVal {
+ def U: UInt = UInt(BigInt(x), Width()) // scalastyle:ignore method.name
+ def S: SInt = SInt(BigInt(x), Width()) // scalastyle:ignore method.name
+
+ def asUInt(): UInt = UInt(x, Width())
+ def asSInt(): SInt = SInt(x, Width())
+ def asUInt(width: Int): UInt = UInt(x, width)
+ def asSInt(width: Int): SInt = SInt(x, width)
+ }
+
+ implicit class fromBigIntToLiteral(val x: BigInt) extends AnyVal {
+ def U: UInt = UInt(x, Width()) // scalastyle:ignore method.name
+ def S: SInt = SInt(x, Width()) // scalastyle:ignore method.name
+
+ def asUInt(): UInt = UInt(x, Width())
+ def asSInt(): SInt = SInt(x, Width())
+ def asUInt(width: Int): UInt = UInt(x, width)
+ def asSInt(width: Int): SInt = SInt(x, width)
+ }
+ implicit class fromStringToLiteral(val x: String) extends AnyVal {
+ def U: UInt = UInt(x) // scalastyle:ignore method.name
+ }
+ implicit class fromBooleanToLiteral(val x: Boolean) extends AnyVal {
+ def B: Bool = Bool(x) // scalastyle:ignore method.name
+ }
+
+ implicit class fromUIntToBitPatComparable(val x: UInt) extends AnyVal {
+ final def === (that: BitPat): Bool = macro SourceInfoTransform.thatArg
+ final def != (that: BitPat): Bool = macro SourceInfoTransform.thatArg
+ final def =/= (that: BitPat): Bool = macro SourceInfoTransform.thatArg
+
+ def do_=== (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that === x // scalastyle:ignore method.name
+ def do_!= (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that != x // scalastyle:ignore method.name
+ def do_=/= (that: BitPat)(implicit sourceInfo: SourceInfo): Bool = that =/= x // scalastyle:ignore method.name
+ }
+
+ // Compatibility with existing code.
+ val INPUT = chisel3.core.Direction.Input
+ val OUTPUT = chisel3.core.Direction.Output
+ val NODIR = chisel3.core.Direction.Unspecified
+ type ChiselException = chisel3.internal.ChiselException
+
+ class EnqIO[+T <: Data](gen: T) extends DecoupledIO(gen) {
+ def init(): Unit = {
+ this.noenq()
+ }
+ override def cloneType: this.type = EnqIO(gen).asInstanceOf[this.type]
+ }
+ class DeqIO[+T <: Data](gen: T) extends DecoupledIO(gen) {
+ val Data = chisel3.core.Data
+ Data.setFirrtlDirection(this, Data.getFirrtlDirection(this).flip)
+ Binding.bind(this, FlippedBinder, "Error: Cannot flip ")
+ def init(): Unit = {
+ this.nodeq()
+ }
+ override def cloneType: this.type = DeqIO(gen).asInstanceOf[this.type]
+ }
+ object EnqIO {
+ def apply[T<:Data](gen: T): EnqIO[T] = new EnqIO(gen)
+ }
+ object DeqIO {
+ def apply[T<:Data](gen: T): DeqIO[T] = new DeqIO(gen)
+ }
+
+ // Debugger/Tester access to internal Chisel data structures and methods.
+ def getDataElements(a: Aggregate): Seq[Element] = {
+ a.allElements
+ }
+ def getModulePorts(m: Module): Seq[Port] = m.getPorts
+ def getFirrtlDirection(d: Data): Direction = chisel3.core.Data.getFirrtlDirection(d)
}
diff --git a/src/main/scala/chisel3/testers/BasicTester.scala b/src/main/scala/chisel3/testers/BasicTester.scala
index f91536d5..bd7d4027 100644
--- a/src/main/scala/chisel3/testers/BasicTester.scala
+++ b/src/main/scala/chisel3/testers/BasicTester.scala
@@ -9,10 +9,11 @@ import internal._
import internal.Builder.pushCommand
import internal.firrtl._
import internal.sourceinfo.SourceInfo
+//import chisel3.core.ExplicitCompileOptions.NotStrict
-class BasicTester extends Module {
+class BasicTester extends Module() {
// The testbench has no IOs, rather it should communicate using printf, assert, and stop.
- val io = new Bundle()
+ val io = IO(new Bundle())
def popCount(n: Long): Int = n.toBinaryString.count(_=='1')
diff --git a/src/main/scala/chisel3/util/Arbiter.scala b/src/main/scala/chisel3/util/Arbiter.scala
index 58ba1188..89bb644a 100644
--- a/src/main/scala/chisel3/util/Arbiter.scala
+++ b/src/main/scala/chisel3/util/Arbiter.scala
@@ -6,6 +6,8 @@
package chisel3.util
import chisel3._
+// TODO: remove this once we have CompileOptions threaded through the macro system.
+import chisel3.core.ExplicitCompileOptions.NotStrict
/** IO bundle definition for an Arbiter, which takes some number of ready-valid inputs and outputs
* (selects) at most one.
@@ -14,9 +16,9 @@ import chisel3._
* @param n number of inputs
*/
class ArbiterIO[T <: Data](gen: T, n: Int) extends Bundle {
- val in = Vec(n, Decoupled(gen)).flip
+ val in = Flipped(Vec(n, Decoupled(gen)))
val out = Decoupled(gen)
- val chosen = UInt(OUTPUT, log2Up(n))
+ val chosen = Output(UInt.width(log2Up(n)))
}
/** Arbiter Control determining which producer has access
@@ -32,7 +34,7 @@ private object ArbiterCtrl {
abstract class LockingArbiterLike[T <: Data](gen: T, n: Int, count: Int, needsLock: Option[T => Bool]) extends Module {
def grant: Seq[Bool]
def choice: UInt
- val io = new ArbiterIO(gen, n)
+ val io = IO(new ArbiterIO(gen, n))
io.chosen := choice
io.out.valid := io.in(io.chosen).valid
@@ -108,7 +110,7 @@ class RRArbiter[T <: Data](gen:T, n: Int) extends LockingRRArbiter[T](gen, n, 1)
* }}}
*/
class Arbiter[T <: Data](gen: T, n: Int) extends Module {
- val io = new ArbiterIO(gen, n)
+ val io = IO(new ArbiterIO(gen, n))
io.chosen := UInt(n-1)
io.out.bits := io.in(n-1).bits
diff --git a/src/main/scala/chisel3/util/BitPat.scala b/src/main/scala/chisel3/util/BitPat.scala
index 6c012583..972010a6 100644
--- a/src/main/scala/chisel3/util/BitPat.scala
+++ b/src/main/scala/chisel3/util/BitPat.scala
@@ -76,7 +76,7 @@ object BitPat {
// TODO: Break out of Core? (this doesn't involve FIRRTL generation)
/** Bit patterns are literals with masks, used to represent values with don't
* cares. Equality comparisons will ignore don't care bits (for example,
- * BitPat(0b10?1) === UInt(0b1001) and UInt(0b1011)).
+ * BitPat(0b10?1) === 0b1001.asUInt and 0b1011.asUInt.
*/
sealed class BitPat(val value: BigInt, val mask: BigInt, width: Int) {
def getWidth: Int = width
@@ -84,7 +84,7 @@ sealed class BitPat(val value: BigInt, val mask: BigInt, width: Int) {
def =/= (that: UInt): Bool = macro SourceInfoTransform.thatArg
def != (that: UInt): Bool = macro SourceInfoTransform.thatArg
- def do_=== (that: UInt)(implicit sourceInfo: SourceInfo): Bool = UInt(value, width) === (that & UInt(mask))
- def do_=/= (that: UInt)(implicit sourceInfo: SourceInfo): Bool = !(this === that)
- def do_!= (that: UInt)(implicit sourceInfo: SourceInfo): Bool = this =/= that
+ def do_=== (that: UInt)(implicit sourceInfo: SourceInfo): Bool = value.asUInt === (that & mask.asUInt) // scalastyle:ignore method.name
+ def do_=/= (that: UInt)(implicit sourceInfo: SourceInfo): Bool = !(this === that) // scalastyle:ignore method.name
+ def do_!= (that: UInt)(implicit sourceInfo: SourceInfo): Bool = this =/= that // scalastyle:ignore method.name
}
diff --git a/src/main/scala/chisel3/util/Bitwise.scala b/src/main/scala/chisel3/util/Bitwise.scala
index 7d5ffe09..289d27b1 100644
--- a/src/main/scala/chisel3/util/Bitwise.scala
+++ b/src/main/scala/chisel3/util/Bitwise.scala
@@ -38,7 +38,7 @@ object Fill {
*/
def apply(n: Int, x: UInt): UInt = {
n match {
- case 0 => UInt(width=0)
+ case 0 => UInt.width(0)
case 1 => x
case _ if x.isWidthKnown && x.getWidth == 1 =>
Mux(x.toBool, UInt((BigInt(1) << n) - 1, n), UInt(0, n))
diff --git a/src/main/scala/chisel3/util/Counter.scala b/src/main/scala/chisel3/util/Counter.scala
index 4b20158f..ba66d667 100644
--- a/src/main/scala/chisel3/util/Counter.scala
+++ b/src/main/scala/chisel3/util/Counter.scala
@@ -3,6 +3,7 @@
package chisel3.util
import chisel3._
+//import chisel3.core.ExplicitCompileOptions.Strict
/** A counter module
*
diff --git a/src/main/scala/chisel3/util/Decoupled.scala b/src/main/scala/chisel3/util/Decoupled.scala
index 65558aa9..a0cbf4f7 100644
--- a/src/main/scala/chisel3/util/Decoupled.scala
+++ b/src/main/scala/chisel3/util/Decoupled.scala
@@ -6,6 +6,8 @@
package chisel3.util
import chisel3._
+// TODO: remove this once we have CompileOptions threaded through the macro system.
+import chisel3.core.ExplicitCompileOptions.NotStrict
/** An I/O Bundle containing 'valid' and 'ready' signals that handshake
* the transfer of data stored in the 'bits' subfield.
@@ -15,10 +17,50 @@ import chisel3._
*/
abstract class ReadyValidIO[+T <: Data](gen: T) extends Bundle
{
- val ready = Bool(INPUT)
- val valid = Bool(OUTPUT)
- val bits = gen.cloneType.asOutput
- def fire(dummy: Int = 0): Bool = ready && valid
+ val ready = Input(Bool())
+ val valid = Output(Bool())
+ val bits = Output(gen.chiselCloneType)
+}
+
+object ReadyValidIO {
+
+ implicit class AddMethodsToReadyValid[T<:Data](val target: ReadyValidIO[T]) extends AnyVal {
+ def fire(): Bool = target.ready && target.valid
+
+ /** push dat onto the output bits of this interface to let the consumer know it has happened.
+ * @param dat the values to assign to bits.
+ * @return dat.
+ */
+ def enq(dat: T): T = {
+ target.valid := Bool(true)
+ target.bits := dat
+ dat
+ }
+
+ /** Indicate no enqueue occurs. Valid is set to false, and all bits are set to zero.
+ */
+ def noenq(): Unit = {
+ target.valid := Bool(false)
+ // We want the type from the following, not any existing binding.
+ target.bits := target.bits.cloneType.fromBits(0.asUInt)
+ }
+
+ /** Assert ready on this port and return the associated data bits.
+ * This is typically used when valid has been asserted by the producer side.
+ * @param b ignored
+ * @return the data for this device,
+ */
+ def deq(): T = {
+ target.ready := Bool(true)
+ target.bits
+ }
+
+ /** Indicate no dequeue occurs. Ready is set to false
+ */
+ def nodeq(): Unit = {
+ target.ready := Bool(false)
+ }
+ }
}
/** A concrete subclass of ReadyValidIO signaling that the user expects a
@@ -43,13 +85,16 @@ object Decoupled
* @note unsafe (and will error) on the producer (input) side of an IrrevocableIO
*/
def apply[T <: Data](irr: IrrevocableIO[T]): DecoupledIO[T] = {
- require(irr.bits.dir == OUTPUT, "Only safe to cast produced Irrevocable bits to Decoupled.")
+ require(irr.bits.flatten forall (_.dir == OUTPUT), "Only safe to cast produced Irrevocable bits to Decoupled.")
val d = Wire(new DecoupledIO(irr.bits))
d.bits := irr.bits
d.valid := irr.valid
irr.ready := d.ready
d
}
+// override def cloneType: this.type = {
+// DeqIO(gen).asInstanceOf[this.type]
+// }
}
/** A concrete subclass of ReadyValidIO that promises to not change
@@ -73,7 +118,7 @@ object Irrevocable
* @note unsafe (and will error) on the consumer (output) side of an DecoupledIO
*/
def apply[T <: Data](dec: DecoupledIO[T]): IrrevocableIO[T] = {
- require(dec.bits.dir == INPUT, "Only safe to cast consumed Decoupled bits to Irrevocable.")
+ require(dec.bits.flatten forall (_.dir == INPUT), "Only safe to cast consumed Decoupled bits to Irrevocable.")
val i = Wire(new IrrevocableIO(dec.bits))
dec.bits := i.bits
dec.valid := i.valid
@@ -82,58 +127,11 @@ object Irrevocable
}
}
-
-/** An I/O bundle for enqueuing data with valid/ready handshaking
- * Initialization must be handled, if necessary, by the parent circuit
- */
-class EnqIO[T <: Data](gen: T) extends DecoupledIO(gen)
-{
- /** push dat onto the output bits of this interface to let the consumer know it has happened.
- * @param dat the values to assign to bits.
- * @return dat.
- */
- def enq(dat: T): T = { valid := Bool(true); bits := dat; dat }
-
- /** Initialize this Bundle. Valid is set to false, and all bits are set to zero.
- * NOTE: This method of initialization is still being discussed and could change in the
- * future.
- */
- def init(): Unit = {
- valid := Bool(false)
- for (io <- bits.flatten)
- io := UInt(0)
- }
- override def cloneType: this.type = { new EnqIO(gen).asInstanceOf[this.type]; }
-}
-
-/** An I/O bundle for dequeuing data with valid/ready handshaking.
- * Initialization must be handled, if necessary, by the parent circuit
- */
-class DeqIO[T <: Data](gen: T) extends DecoupledIO(gen) with Flipped
-{
- /** Assert ready on this port and return the associated data bits.
- * This is typically used when valid has been asserted by the producer side.
- * @param b ignored
- * @return the data for this device,
- */
- def deq(b: Boolean = false): T = { ready := Bool(true); bits }
-
- /** Initialize this Bundle.
- * NOTE: This method of initialization is still being discussed and could change in the
- * future.
- */
- def init(): Unit = {
- ready := Bool(false)
- }
- override def cloneType: this.type = { new DeqIO(gen).asInstanceOf[this.type]; }
+object EnqIO {
+ def apply[T<:Data](gen: T): DecoupledIO[T] = Decoupled(gen)
}
-
-/** An I/O bundle for dequeuing data with valid/ready handshaking */
-class DecoupledIOC[+T <: Data](gen: T) extends Bundle
-{
- val ready = Bool(INPUT)
- val valid = Bool(OUTPUT)
- val bits = gen.cloneType.asOutput
+object DeqIO {
+ def apply[T<:Data](gen: T): DecoupledIO[T] = Flipped(Decoupled(gen))
}
/** An I/O Bundle for Queues
@@ -142,11 +140,11 @@ class DecoupledIOC[+T <: Data](gen: T) extends Bundle
class QueueIO[T <: Data](gen: T, entries: Int) extends Bundle
{
/** I/O to enqueue data, is [[Chisel.DecoupledIO]] flipped */
- val enq = Decoupled(gen.cloneType).flip()
+ val enq = DeqIO(gen)
/** I/O to enqueue data, is [[Chisel.DecoupledIO]]*/
- val deq = Decoupled(gen.cloneType)
+ val deq = EnqIO(gen)
/** The current amount of data in the queue */
- val count = UInt(OUTPUT, log2Up(entries + 1))
+ val count = Output(UInt.width(log2Up(entries + 1)))
}
/** A hardware module implementing a Queue
@@ -172,7 +170,7 @@ extends Module(override_reset=override_reset) {
def this(gen: T, entries: Int, pipe: Boolean, flow: Boolean, _reset: Bool) =
this(gen, entries, pipe, flow, Some(_reset))
- val io = new QueueIO(gen, entries)
+ val io = IO(new QueueIO(gen, entries))
val ram = Mem(entries, gen)
val enq_ptr = Counter(entries)
diff --git a/src/main/scala/chisel3/util/LFSR.scala b/src/main/scala/chisel3/util/LFSR.scala
index e4261c20..fedbf194 100644
--- a/src/main/scala/chisel3/util/LFSR.scala
+++ b/src/main/scala/chisel3/util/LFSR.scala
@@ -6,6 +6,7 @@
package chisel3.util
import chisel3._
+//import chisel3.core.ExplicitCompileOptions.Strict
// scalastyle:off magic.number
object LFSR16 {
diff --git a/src/main/scala/chisel3/util/Reg.scala b/src/main/scala/chisel3/util/Reg.scala
index 80a3f43e..713a3b2e 100644
--- a/src/main/scala/chisel3/util/Reg.scala
+++ b/src/main/scala/chisel3/util/Reg.scala
@@ -3,6 +3,8 @@
package chisel3.util
import chisel3._
+// TODO: remove this once we have CompileOptions threaded through the macro system.
+import chisel3.core.ExplicitCompileOptions.NotStrict
object RegNext {
/** Returns a register with the specified next and no reset initialization.
@@ -28,7 +30,8 @@ object RegEnable {
/** Returns a register with the specified next, update enable gate, and no reset initialization.
*/
def apply[T <: Data](updateData: T, enable: Bool): T = {
- val r = Reg(updateData)
+ val clonedUpdateData = updateData.chiselCloneType
+ val r = Reg(clonedUpdateData)
when (enable) { r := updateData }
r
}
diff --git a/src/main/scala/chisel3/util/TransitName.scala b/src/main/scala/chisel3/util/TransitName.scala
index f36f926f..ce6cb60f 100644
--- a/src/main/scala/chisel3/util/TransitName.scala
+++ b/src/main/scala/chisel3/util/TransitName.scala
@@ -1,3 +1,5 @@
+// See LICENSE for license details.
+
package chisel3.util
import chisel3._
@@ -16,7 +18,7 @@ object TransitName {
from
}
def withSuffix[T<:HasId](suffix: String)(from: T, to: HasId): T = {
- from.addPostnameHook((given_name: String) => {to.suggestName(given_name+suffix)})
+ from.addPostnameHook((given_name: String) => {to.suggestName(given_name + suffix)})
from
}
}
diff --git a/src/main/scala/chisel3/util/Valid.scala b/src/main/scala/chisel3/util/Valid.scala
index 78187ff6..3d153a2a 100644
--- a/src/main/scala/chisel3/util/Valid.scala
+++ b/src/main/scala/chisel3/util/Valid.scala
@@ -6,21 +6,21 @@
package chisel3.util
import chisel3._
+// TODO: remove this once we have CompileOptions threaded through the macro system.
+import chisel3.core.ExplicitCompileOptions.NotStrict
-/** An I/O Bundle containing data and a signal determining if it is valid */
-class ValidIO[+T <: Data](gen2: T) extends Bundle
+/** An Bundle containing data and a signal determining if it is valid */
+class Valid[+T <: Data](gen: T) extends Bundle
{
- val valid = Bool(OUTPUT)
- val bits = gen2.cloneType.asOutput
+ val valid = Output(Bool())
+ val bits = Output(gen.chiselCloneType)
def fire(dummy: Int = 0): Bool = valid
- override def cloneType: this.type = new ValidIO(gen2).asInstanceOf[this.type]
+ override def cloneType: this.type = Valid(gen).asInstanceOf[this.type]
}
-/** Adds a valid protocol to any interface. The standard used is
- that the consumer uses the flipped interface.
-*/
+/** Adds a valid protocol to any interface */
object Valid {
- def apply[T <: Data](gen: T): ValidIO[T] = new ValidIO(gen)
+ def apply[T <: Data](gen: T): Valid[T] = new Valid(gen)
}
/** A hardware module that delays data coming down the pipeline
@@ -34,7 +34,7 @@ object Valid {
*/
object Pipe
{
- def apply[T <: Data](enqValid: Bool, enqBits: T, latency: Int): ValidIO[T] = {
+ def apply[T <: Data](enqValid: Bool, enqBits: T, latency: Int): Valid[T] = {
if (latency == 0) {
val out = Wire(Valid(enqBits))
out.valid <> enqValid
@@ -46,16 +46,16 @@ object Pipe
apply(v, b, latency-1)
}
}
- def apply[T <: Data](enqValid: Bool, enqBits: T): ValidIO[T] = apply(enqValid, enqBits, 1)
- def apply[T <: Data](enq: ValidIO[T], latency: Int = 1): ValidIO[T] = apply(enq.valid, enq.bits, latency)
+ def apply[T <: Data](enqValid: Bool, enqBits: T): Valid[T] = apply(enqValid, enqBits, 1)
+ def apply[T <: Data](enq: Valid[T], latency: Int = 1): Valid[T] = apply(enq.valid, enq.bits, latency)
}
class Pipe[T <: Data](gen: T, latency: Int = 1) extends Module
{
- val io = new Bundle {
- val enq = Valid(gen).flip
- val deq = Valid(gen)
- }
+ val io = IO(new Bundle {
+ val enq = Input(Valid(gen))
+ val deq = Output(Valid(gen))
+ })
io.deq <> Pipe(io.enq, latency)
}
diff --git a/src/main/scala/chisel3/util/util.scala b/src/main/scala/chisel3/util/util.scala
new file mode 100644
index 00000000..812af21c
--- /dev/null
+++ b/src/main/scala/chisel3/util/util.scala
@@ -0,0 +1,12 @@
+// See LICENSE for license details.
+
+package chisel3
+
+package object util {
+
+ /** Synonyms, moved from main package object - maintain scope. */
+ type ValidIO[+T <: Data] = chisel3.util.Valid[T]
+ val ValidIO = chisel3.util.Valid
+ val DecoupledIO = chisel3.util.Decoupled
+
+}