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

Commit

Permalink
refactor connectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed May 22, 2024
1 parent 16074b9 commit 70f421b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 27 deletions.
4 changes: 1 addition & 3 deletions src/main/scala/ee/hrzn/chryse/platform/ecp5/ECP5Top.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ object ECP5Top {
def apply[Top <: Module](
platform: BoardPlatform[_ <: BoardResources],
genTop: => Top,
) = {
platform.resources.setNames() // XXX: refactor setNames call
) =
new ECP5Top(platform, genTop)
}
}
10 changes: 0 additions & 10 deletions src/main/scala/ee/hrzn/chryse/platform/ice40/ICE40Top.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,3 @@ class ICE40Top[Top <: Module](

lastPCF = Some(PCF(ios.to(Map), freqs.to(Map)))
}

object ICE40Top {
def apply[Top <: Module](
platform: BoardPlatform[_ <: BoardResources],
genTop: => Top,
) = {
platform.resources.setNames() // XXX refactor setNames call
new ICE40Top(platform, genTop)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ final case class IceBreakerPlatform(ubtnReset: Boolean = false)

val resources = new IceBreakerResources

override def apply[Top <: Module](genTop: Platform => Top) =
ICE40Top(this, genTop(this))
override def apply[Top <: Module](genTop: Platform => Top) = {
resources.setNames()
new ICE40Top(this, genTop(this))
}
}

class IceBreakerResources extends BoardResources {
Expand All @@ -33,14 +35,17 @@ class IceBreakerResources extends BoardResources {
val ledg = resource.LED().inverted.onPin(37)
val ledr = resource.LED().inverted.onPin(11)

val pmod1a1 = resource.InOut().onPin(4)
val pmod1a2 = resource.InOut().onPin(2)
val pmod1a3 = resource.InOut().onPin(47)
val pmod1a4 = resource.InOut().onPin(45)
val pmod1a7 = resource.InOut().onPin(3)
val pmod1a8 = resource.InOut().onPin(48)
val pmod1a9 = resource.InOut().onPin(46)
val pmod1a10 = resource.InOut().onPin(44)
val pmod1a = resource.Connector(
resource.InOut(),
1 -> 4,
2 -> 2,
3 -> 47,
4 -> 45,
7 -> 3,
8 -> 48,
9 -> 46,
10 -> 44,
)

val pmod1b1 = resource.InOut().onPin(43)
val pmod1b2 = resource.InOut().onPin(38)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/ee/hrzn/chryse/platform/resource/Base.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ee.hrzn.chryse.platform.resource

import chisel3._

abstract class Base[HW <: Data](gen: => HW) extends Resource {
abstract class Base[HW <: Data](gen: => HW) extends SinglePinResource {
final private[chryse] var pinId: Option[Pin] = None
final var name: Option[String] = None

Expand Down
26 changes: 26 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/resource/Connector.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ee.hrzn.chryse.platform.resource

import chisel3._

class Connector[E <: SinglePinResource](
gen: => E,
private val ixToPin: (Int, Pin)*,
) extends Resource {
private val mappings: Map[Int, E] = ixToPin
.map { case (i, p) =>
i -> gen.onPin(p)
}
.to(Map)

def apply(ix: Int): E = mappings(ix)

def setName(name: String): Unit =
mappings.foreach { case (i, e) => e.setName(s"$name$i") }

def bases(): Seq[Base[_ <: Data]] = mappings.flatMap(_._2.bases()).toSeq
}

object Connector {
def apply[E <: SinglePinResource](gen: => E, ixToPin: (Int, Pin)*) =
new Connector(gen, ixToPin: _*)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ee.hrzn.chryse.platform.resource

import chisel3._

class InOut extends Resource {
class InOut extends Resource with SinglePinResource {
val i = new Base[Bool](Input(Bool())) {}
val o = new Base[Bool](Output(Bool())) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import ee.hrzn.chryse.platform.BoardResources

import scala.collection.mutable.ArrayBuffer

// XXX: This is more of a resource holder/container.
// It's one or possibly many (or no?) resources. Hrm.
trait Resource {
def setName(name: String): Unit
def bases(): Seq[Base[_ <: Data]]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ee.hrzn.chryse.platform.resource

trait SinglePinResource extends Resource {
def onPin(id: Pin): this.type
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ class InversionTop(platform: Platform) extends Module {
class InOutTop(platform: Platform) extends Module {
val plat = platform.asInstanceOf[IceBreakerPlatform]
// Treat pmod1a1 as output, 1a2 as input.
plat.resources.pmod1a1.o := plat.resources.uart.rx
plat.resources.uart.tx := plat.resources.pmod1a2.i
plat.resources.pmod1a(1).o := plat.resources.uart.rx
plat.resources.uart.tx := plat.resources.pmod1a(2).i

// Do the same with 1b1 and 1b2, but use inverted inputs/outputs.
plat.resources.pmod1b1.o := plat.resources.ubtn
Expand Down

0 comments on commit 70f421b

Please sign in to comment.