Skip to content

Commit

Permalink
Finishing touches to connect functions.
Browse files Browse the repository at this point in the history
Run formatting.
  • Loading branch information
ccromjongh committed Sep 9, 2024
1 parent b1f9666 commit ec48f85
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
27 changes: 24 additions & 3 deletions library/src/main/scala/nl/tudelft/tydi_chisel/TydiLib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,9 @@ sealed abstract class PhysicalStreamBase(private val e: TydiEl, val n: Int, val
/**
* Meta-connect function. Connects all metadata signals but not the data or user signals.
* @param bundle Source stream to drive this stream with.
* @param compatCheckResult Whether to report stream compatibility issues as errors or warnings.
*/
def :~=(
def :@=(
bundle: PhysicalStreamBase
)(implicit compatCheckResult: CompatCheckResult.Value = CompatCheckResult.Error): Unit = {
paramCheck(bundle, compatCheckResult)
Expand All @@ -448,18 +449,38 @@ sealed abstract class PhysicalStreamBase(private val e: TydiEl, val n: Int, val
}
}

/**
* Shortcut for stream mounting with weak type check.
* @param bundle Source stream to drive this stream with.
* @param errorReporting Whether to report stream compatibility issues as errors or warnings.
*/
def :~=(
bundle: PhysicalStreamBase
)(implicit errorReporting: CompatCheckResult.Value = CompatCheckResult.Error): Unit = {
implicit val errorReporting: CompatCheck.Value = CompatCheck.Params
this := bundle
}

/**
* Stream mounting function.
* @param bundle Source stream to drive this stream with.
* @param errorReporting Whether to report stream compatibility issues as errors or warnings.
* @param typeCheck Whether to conduct a strong or weak type check. A weak type check only verifies the number of bits.
*/
def :=(bundle: PhysicalStreamBase)(implicit
typeCheck: CompatCheck.Value = CompatCheck.Strict,
errorReporting: CompatCheckResult.Value = CompatCheckResult.Error
): Unit = {
this :~= bundle
elementCheckTyped(bundle, typeCheck, errorReporting)
this :@= bundle // Connect meta signals and check parameters
elementCheckTyped(bundle, typeCheck, errorReporting) // Check data types
// Call the right connect method
(this, bundle) match {
case (x: PhysicalStream, y: PhysicalStream) => x.connectSimple(y, typeCheck, errorReporting)
case (x: PhysicalStream, y: PhysicalStreamDetailed[_, _]) => x.connectDetailed(y, typeCheck, errorReporting)
case (x: PhysicalStreamDetailed[_, _], y: PhysicalStream) => x.connectSimple(y, typeCheck, errorReporting)
case (x: PhysicalStreamDetailed[_, _], y: PhysicalStreamDetailed[_, _]) =>
x.connectDetailed(y, typeCheck, errorReporting)
case _ => throw new Exception("Could not determine data connection method.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StreamCompatCheckTest extends AnyFlatSpec with ChiselScalatestTester {
val outStream: PhysicalStream = IO(out)

{
implicit val typeCheckImplicit: CompatCheck.Value = typeCheckSelect
implicit val typeCheckImplicit: CompatCheck.Value = typeCheckSelect
implicit val typeCheckResultImplicit: CompatCheckResult.Value = errorReporting
outStream := inStream
}
Expand Down Expand Up @@ -64,7 +64,13 @@ class StreamCompatCheckTest extends AnyFlatSpec with ChiselScalatestTester {

it should "weak check type" in {
test(new DetailedStreamConnectMod(myBundleStream, myBundle2Stream, CompatCheck.Params)) { _ => }
test(new StreamConnectMod(PhysicalStream(new MyBundle, c = 1), PhysicalStream(new MyBundle2, c = 1), CompatCheck.Params)) { _ => }
test(
new StreamConnectMod(
PhysicalStream(new MyBundle, c = 1),
PhysicalStream(new MyBundle2, c = 1),
CompatCheck.Params
)
) { _ => }
}

it should "check parameters" in {
Expand Down Expand Up @@ -100,7 +106,7 @@ class StreamCompatCheckTest extends AnyFlatSpec with ChiselScalatestTester {
new StreamConnectMod(
baseStream,
PhysicalStream(new MyBundle, n = 2, d = 1, c = 1, new DataBundle),
errorReporting=CompatCheckResult.Warning
errorReporting = CompatCheckResult.Warning
)
) { _ => }
}
Expand Down

0 comments on commit ec48f85

Please sign in to comment.