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.
work on "InOut" (essentially a Bundle (!)), drop Analog; resource can…
… have multiple bases.
- Loading branch information
Showing
9 changed files
with
157 additions
and
55 deletions.
There are no files selected for viewing
12 changes: 9 additions & 3 deletions
12
src/main/scala/ee/hrzn/chryse/platform/BoardResources.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,17 +1,23 @@ | ||
package ee.hrzn.chryse.platform | ||
|
||
import ee.hrzn.chryse.platform.resource | ||
import chisel3._ | ||
import ee.hrzn.chryse.platform.resource.Base | ||
import ee.hrzn.chryse.platform.resource.Resource | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
|
||
abstract class BoardResources { | ||
private[chryse] def setNames() = | ||
for { f <- this.getClass().getDeclaredFields() } { | ||
f.setAccessible(true) | ||
f.get(this) match { | ||
case res: resource.Base[_] => | ||
res.name = Some(f.getName()) | ||
case res: Resource => | ||
res.setName(f.getName()) | ||
case _ => | ||
} | ||
} | ||
|
||
val clock: resource.ClockSource | ||
|
||
def all: List[Base[_ <: Data]] = Resource.allFromBoardResources(this) | ||
} |
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
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
19 changes: 17 additions & 2 deletions
19
src/main/scala/ee/hrzn/chryse/platform/resource/InOut.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
29 changes: 29 additions & 0 deletions
29
src/main/scala/ee/hrzn/chryse/platform/resource/Resource.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,29 @@ | ||
package ee.hrzn.chryse.platform.resource | ||
|
||
import chisel3._ | ||
import ee.hrzn.chryse.platform.BoardResources | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
|
||
trait Resource { | ||
def setName(name: String): Unit | ||
def onPin(id: Pin): this.type | ||
def bases(): List[Base[_ <: Data]] | ||
} | ||
|
||
object Resource { | ||
def allFromBoardResources[T <: BoardResources]( | ||
br: T, | ||
): List[Base[_ <: Data]] = { | ||
var out = ArrayBuffer[Base[_ <: Data]]() | ||
for { f <- br.getClass().getDeclaredFields().iterator } { | ||
f.setAccessible(true) | ||
f.get(br) match { | ||
case res: Resource => | ||
out.appendAll(res.bases()) | ||
case _ => | ||
} | ||
} | ||
out.toList | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/scala/ee/hrzn/chryse/platform/resource/implicits.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,26 @@ | ||
package ee.hrzn.chryse.platform.resource | ||
|
||
import chisel3._ | ||
import chisel3.experimental.dataview._ | ||
|
||
import scala.language.implicitConversions | ||
|
||
object implicits { | ||
// Note that the DataView doesn't really need or care about the generated | ||
// data's direction or lack thereof. | ||
|
||
implicit def BaseProduct[HW <: Data]: DataProduct[Base[HW]] = | ||
new DataProduct[Base[HW]] { | ||
def dataIterator( | ||
res: Base[HW], | ||
path: String, | ||
): Iterator[(Data, String)] = | ||
List(res.ioInst.get.user -> path).iterator | ||
} | ||
|
||
implicit def viewBool: DataView[Base[Bool], Bool] = | ||
DataView(res => Bool(), _.ioInstOrMake().user -> _) | ||
|
||
implicit def base2Bool(res: Base[Bool]): Bool = | ||
res.viewAs[Bool] | ||
} |
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