This repository has been archived by the owner on Jun 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base -> DataResource, Resource -> Base
- Loading branch information
Showing
12 changed files
with
81 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 21 additions & 28 deletions
49
src/main/scala/ee/hrzn/chryse/platform/resource/Base.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,30 @@ | ||
package ee.hrzn.chryse.platform.resource | ||
|
||
import chisel3._ | ||
import ee.hrzn.chryse.platform.BoardResources | ||
|
||
abstract class Base[HW <: Data](gen: => HW) extends SinglePinResource { | ||
final private[chryse] var pinId: Option[Pin] = None | ||
final var name: Option[String] = None | ||
import scala.collection.mutable.ArrayBuffer | ||
|
||
// Should return Chisel datatype with Input/Output attached. | ||
private[chryse] def makeIo(): HW = gen | ||
|
||
final private[chryse] var ioInst: Option[InstSides[HW]] = None | ||
// XXX: This is more of a resource holder/container. | ||
// It's one or possibly many (or no?) resources. Hrm. | ||
trait Base { | ||
def setName(name: String): Unit | ||
def bases(): Seq[DataResource[_ <: Data]] | ||
} | ||
|
||
/* Instantiate an IO in the module at the point of connecting to this | ||
* resource. These will be connected to in turn by the platform toplevel | ||
* (which implies they can only be used in the user toplevel). */ | ||
private[chryse] def ioInstOrMake(): InstSides[HW] = { | ||
ioInst match { | ||
case Some(r) => r | ||
case None => | ||
val r = IO(makeIo()).suggestName(s"${name.get}_int") | ||
ioInst = Some(InstSides(r, r)) | ||
ioInst.get | ||
object Base { | ||
def allFromBoardResources[T <: BoardResources]( | ||
br: T, | ||
): Seq[DataResource[_ <: Data]] = { | ||
var out = ArrayBuffer[DataResource[_ <: Data]]() | ||
for { f <- br.getClass().getDeclaredFields().iterator } { | ||
f.setAccessible(true) | ||
f.get(br) match { | ||
case res: Base => | ||
out.appendAll(res.bases()) | ||
case _ => | ||
} | ||
} | ||
out.toSeq | ||
} | ||
|
||
def setName(name: String): Unit = this.name = Some(name) | ||
|
||
def onPin(id: Pin): this.type = { | ||
pinId = Some(id) | ||
this | ||
} | ||
|
||
def bases(): Seq[Base[_ <: Data]] = Seq(this) | ||
} | ||
|
||
case class InstSides[HW](user: HW, top: HW) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/scala/ee/hrzn/chryse/platform/resource/DataResource.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ee.hrzn.chryse.platform.resource | ||
|
||
import chisel3._ | ||
|
||
abstract class DataResource[HW <: Data](gen: => HW) extends SinglePinResource { | ||
final private[chryse] var pinId: Option[Pin] = None | ||
final var name: Option[String] = None | ||
|
||
// Should return Chisel datatype with Input/Output attached. | ||
private[chryse] def makeIo(): HW = gen | ||
|
||
final private[chryse] var ioInst: Option[InstSides[HW]] = None | ||
|
||
/* Instantiate an IO in the module at the point of connecting to this | ||
* resource. These will be connected to in turn by the platform toplevel | ||
* (which implies they can only be used in the user toplevel). */ | ||
private[chryse] def ioInstOrMake(): InstSides[HW] = { | ||
ioInst match { | ||
case Some(r) => r | ||
case None => | ||
val r = IO(makeIo()).suggestName(s"${name.get}_int") | ||
ioInst = Some(InstSides(r, r)) | ||
ioInst.get | ||
} | ||
} | ||
|
||
def setName(name: String): Unit = this.name = Some(name) | ||
|
||
def onPin(id: Pin): this.type = { | ||
pinId = Some(id) | ||
this | ||
} | ||
|
||
def bases(): Seq[DataResource[_ <: Data]] = Seq(this) | ||
} | ||
|
||
case class InstSides[HW](user: HW, top: HW) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
src/main/scala/ee/hrzn/chryse/platform/resource/Resource.scala
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/main/scala/ee/hrzn/chryse/platform/resource/SinglePinResource.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package ee.hrzn.chryse.platform.resource | ||
|
||
trait SinglePinResource extends Resource { | ||
trait SinglePinResource extends Base { | ||
def onPin(id: Pin): this.type | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters