Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
ChryseTop: clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed May 23, 2024
1 parent d795aed commit e3a5f1e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
18 changes: 7 additions & 11 deletions src/main/scala/ee/hrzn/chryse/platform/ChryseTop.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package ee.hrzn.chryse.platform

import chisel3._
import chisel3.experimental.noPrefix

import scala.collection.mutable

trait ChryseTop extends RawModule {
override def desiredName = "ice40top"
override def desiredName = "chrysetop"

case class ConnectedResource(pin: resource.Pin, frequencyHz: Option[Int])
case class ConnectionResult(
connectedResources: Map[String, ConnectedResource],
clockIo: Clock,
)

protected def connectResources(
platform: PlatformBoard[_ <: PlatformBoardResources],
): ConnectionResult = {
val connected = mutable.Map[String, ConnectedResource]()
var clockIo: Option[Clock] = None
clock: Clock,
): Map[String, ConnectedResource] = {
val connected = mutable.Map[String, ConnectedResource]()

for { res <- platform.resources.all } {
val name = res.name.get
Expand All @@ -33,8 +30,7 @@ trait ChryseTop extends RawModule {
res.pinId.get,
Some(platform.clockHz),
)
val io = IO(Input(Clock())).suggestName(name)
clockIo = Some(io)
clock := noPrefix(IO(Input(Clock())).suggestName(name))

case _ =>
if (platformConnect(name, res)) {
Expand All @@ -46,7 +42,7 @@ trait ChryseTop extends RawModule {
}
}

ConnectionResult(connected.to(Map), clockIo.get)
connected.to(Map)
}

protected def platformConnect(
Expand Down
6 changes: 2 additions & 4 deletions src/main/scala/ee/hrzn/chryse/platform/ice40/ICE40Top.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ class ICE40Top[Top <: Module](

// TODO (iCE40): allow clock source override.

private val ConnectionResult(connectedResources, clockIo) =
connectResources(platform)

clki := clockIo
private val connectedResources =
connectResources(platform, clki)

override protected def platformConnect(
name: String,
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/ee/hrzn/chryse/tasks/BuildTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object BuildTask extends BaseTask {
writePath(
yosysScriptPath,
s"""read_verilog -sv $verilogPath
|synth_ice40 -top ice40top
|synth_ice40 -top chrysetop
|write_json $jsonPath""".stripMargin,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PlatformBoardResourcesSpec
(rtl should include).regex(raw"\.view__ubtn_int\s*\(~ubtn\),")

verilog.InterfaceExtractor(rtl) should contain(
"ice40top" -> verilog.InterfaceExtractor.Module(
"chrysetop" -> verilog.InterfaceExtractor.Module(
inputs = Seq("clock", "ubtn"),
outputs = Seq("uart_tx", "ledg"),
),
Expand Down Expand Up @@ -111,7 +111,7 @@ class PlatformBoardResourcesSpec
(rtl should include).regex(raw"assign ledr = ~_top_ledr_int;")

verilog.InterfaceExtractor(rtl) should contain(
"ice40top" -> verilog.InterfaceExtractor.Module(
"chrysetop" -> verilog.InterfaceExtractor.Module(
inputs = Seq("clock", "ubtn", "uart_rx", "pmod1a2", "pmod1b2"),
outputs = Seq("uart_tx", "ledr", "pmod1a1", "pmod1b1"),
),
Expand Down

0 comments on commit e3a5f1e

Please sign in to comment.