Reformat all scala files in iocells

- Mostly this reformat comments and large argument lists to classes and methods
This commit is contained in:
chick
2021-02-03 17:49:14 -08:00
parent 19e51f3df5
commit 93f86a5bc6
2 changed files with 69 additions and 67 deletions

View File

@@ -6,8 +6,10 @@ import chisel3._
import chisel3.util.{HasBlackBoxResource} import chisel3.util.{HasBlackBoxResource}
import chisel3.experimental.{Analog, IntParam} import chisel3.experimental.{Analog, IntParam}
class AnalogConst(value: Int, width: Int = 1) extends BlackBox(Map("CONST" -> IntParam(value), "WIDTH" -> IntParam(width))) with HasBlackBoxResource{ class AnalogConst(value: Int, width: Int = 1)
val io = IO(new Bundle {val io = Analog(width.W) } ) extends BlackBox(Map("CONST" -> IntParam(value), "WIDTH" -> IntParam(width)))
with HasBlackBoxResource {
val io = IO(new Bundle { val io = Analog(width.W) })
addResource("/barstools/iocell/vsrc/Analog.v") addResource("/barstools/iocell/vsrc/Analog.v")
} }

View File

@@ -4,7 +4,7 @@ package barstools.iocell.chisel
import chisel3._ import chisel3._
import chisel3.util.{Cat, HasBlackBoxResource} import chisel3.util.{Cat, HasBlackBoxResource}
import chisel3.experimental.{Analog, DataMirror, IO, BaseModule} import chisel3.experimental.{Analog, BaseModule, DataMirror, IO}
// The following four IO cell bundle types are bare-minimum functional connections // The following four IO cell bundle types are bare-minimum functional connections
// for modeling 4 different IO cell scenarios. The intention is that the user // for modeling 4 different IO cell scenarios. The intention is that the user
@@ -13,24 +13,22 @@ import chisel3.experimental.{Analog, DataMirror, IO, BaseModule}
// (https://github.com/sifive/sifive-blocks/blob/master/src/main/scala/devices/pinctrl/PinCtrl.scala), // (https://github.com/sifive/sifive-blocks/blob/master/src/main/scala/devices/pinctrl/PinCtrl.scala),
// but we want to avoid a dependency on an external libraries. // but we want to avoid a dependency on an external libraries.
/** /** The base IO bundle for an analog signal (typically something with no digital buffers inside)
* The base IO bundle for an analog signal (typically something with no digital buffers inside) * pad: off-chip (external) connection
* pad: off-chip (external) connection * core: internal connection
* core: internal connection */
*/
class AnalogIOCellBundle extends Bundle { class AnalogIOCellBundle extends Bundle {
val pad = Analog(1.W) // Pad/bump signal (off-chip) val pad = Analog(1.W) // Pad/bump signal (off-chip)
val core = Analog(1.W) // core signal (on-chip) val core = Analog(1.W) // core signal (on-chip)
} }
/** /** The base IO bundle for a signal with runtime-controllable direction
* The base IO bundle for a signal with runtime-controllable direction * pad: off-chip (external) connection
* pad: off-chip (external) connection * i: input to chip logic (output from IO cell)
* i: input to chip logic (output from IO cell) * ie: enable signal for i
* ie: enable signal for i * o: output from chip logic (input to IO cell)
* o: output from chip logic (input to IO cell) * oe: enable signal for o
* oe: enable signal for o */
*/
class DigitalGPIOCellBundle extends Bundle { class DigitalGPIOCellBundle extends Bundle {
val pad = Analog(1.W) val pad = Analog(1.W)
val i = Output(Bool()) val i = Output(Bool())
@@ -39,24 +37,22 @@ class DigitalGPIOCellBundle extends Bundle {
val oe = Input(Bool()) val oe = Input(Bool())
} }
/** /** The base IO bundle for a digital output signal
* The base IO bundle for a digital output signal * pad: off-chip (external) connection
* pad: off-chip (external) connection * o: output from chip logic (input to IO cell)
* o: output from chip logic (input to IO cell) * oe: enable signal for o
* oe: enable signal for o */
*/
class DigitalOutIOCellBundle extends Bundle { class DigitalOutIOCellBundle extends Bundle {
val pad = Output(Bool()) val pad = Output(Bool())
val o = Input(Bool()) val o = Input(Bool())
val oe = Input(Bool()) val oe = Input(Bool())
} }
/** /** The base IO bundle for a digital input signal
* The base IO bundle for a digital input signal * pad: off-chip (external) connection
* pad: off-chip (external) connection * i: input to chip logic (output from IO cell)
* i: input to chip logic (output from IO cell) * ie: enable signal for i
* ie: enable signal for i */
*/
class DigitalInIOCellBundle extends Bundle { class DigitalInIOCellBundle extends Bundle {
val pad = Input(Bool()) val pad = Input(Bool())
val i = Output(Bool()) val i = Output(Bool())
@@ -102,11 +98,10 @@ class GenericDigitalOutIOCell extends GenericIOCell with DigitalOutIOCell {
val io = IO(new DigitalOutIOCellBundle) val io = IO(new DigitalOutIOCellBundle)
} }
trait IOCellTypeParams { trait IOCellTypeParams {
def analog(): AnalogIOCell def analog(): AnalogIOCell
def gpio(): DigitalGPIOCell def gpio(): DigitalGPIOCell
def input(): DigitalInIOCell def input(): DigitalInIOCell
def output(): DigitalOutIOCell def output(): DigitalOutIOCell
} }
@@ -118,47 +113,49 @@ case class GenericIOCellParams() extends IOCellTypeParams {
} }
object IOCell { object IOCell {
/**
* From within a RawModule or MultiIOModule context, generate new module IOs from a given /** From within a RawModule or MultiIOModule context, generate new module IOs from a given
* signal and return the new IO and a Seq containing all generated IO cells. * signal and return the new IO and a Seq containing all generated IO cells.
* @param coreSignal The signal onto which to add IO cells * @param coreSignal The signal onto which to add IO cells
* @param name An optional name or name prefix to use for naming IO cells * @param name An optional name or name prefix to use for naming IO cells
* @param abstractResetAsAsync When set, will coerce abstract resets to * @param abstractResetAsAsync When set, will coerce abstract resets to
* AsyncReset, and otherwise to Bool (sync reset) * AsyncReset, and otherwise to Bool (sync reset)
* @return A tuple of (the generated IO data node, a Seq of all generated IO cell instances) * @return A tuple of (the generated IO data node, a Seq of all generated IO cell instances)
*/ */
def generateIOFromSignal[T <: Data](coreSignal: T, name: String, def generateIOFromSignal[T <: Data](
typeParams: IOCellTypeParams = GenericIOCellParams(), coreSignal: T,
abstractResetAsAsync: Boolean = false): (T, Seq[IOCell]) = name: String,
{ typeParams: IOCellTypeParams = GenericIOCellParams(),
abstractResetAsAsync: Boolean = false
): (T, Seq[IOCell]) = {
val padSignal = IO(DataMirror.internal.chiselTypeClone[T](coreSignal)).suggestName(name) val padSignal = IO(DataMirror.internal.chiselTypeClone[T](coreSignal)).suggestName(name)
val resetFn = if (abstractResetAsAsync) toAsyncReset else toSyncReset val resetFn = if (abstractResetAsAsync) toAsyncReset else toSyncReset
val iocells = IOCell.generateFromSignal(coreSignal, padSignal, Some(s"iocell_$name"), typeParams, resetFn) val iocells = IOCell.generateFromSignal(coreSignal, padSignal, Some(s"iocell_$name"), typeParams, resetFn)
(padSignal, iocells) (padSignal, iocells)
} }
/** /** Connect two identical signals together by adding IO cells between them and return a Seq
* Connect two identical signals together by adding IO cells between them and return a Seq * containing all generated IO cells.
* containing all generated IO cells. * @param coreSignal The core-side (internal) signal onto which to connect/add IO cells
* @param coreSignal The core-side (internal) signal onto which to connect/add IO cells * @param padSignal The pad-side (external) signal onto which to connect IO cells
* @param padSignal The pad-side (external) signal onto which to connect IO cells * @param name An optional name or name prefix to use for naming IO cells
* @param name An optional name or name prefix to use for naming IO cells * @return A Seq of all generated IO cell instances
* @return A Seq of all generated IO cell instances */
*/ val toSyncReset: (Reset) => Bool = _.toBool
val toSyncReset: (Reset) => Bool = _.toBool
val toAsyncReset: (Reset) => AsyncReset = _.asAsyncReset val toAsyncReset: (Reset) => AsyncReset = _.asAsyncReset
def generateFromSignal[T <: Data, R <: Reset]( def generateFromSignal[T <: Data, R <: Reset](
coreSignal: T, coreSignal: T,
padSignal: T, padSignal: T,
name: Option[String] = None, name: Option[String] = None,
typeParams: IOCellTypeParams = GenericIOCellParams(), typeParams: IOCellTypeParams = GenericIOCellParams(),
concretizeResetFn : (Reset) => R = toSyncReset): Seq[IOCell] = concretizeResetFn: (Reset) => R = toSyncReset
{ ): Seq[IOCell] = {
def genCell[T <: Data]( def genCell[T <: Data](
castToBool: (T) => Bool, castToBool: (T) => Bool,
castFromBool: (Bool) => T)( castFromBool: (Bool) => T
coreSignal: T, )(coreSignal: T,
padSignal: T): Seq[IOCell] = { padSignal: T
): Seq[IOCell] = {
DataMirror.directionOf(coreSignal) match { DataMirror.directionOf(coreSignal) match {
case ActualDirection.Input => { case ActualDirection.Input => {
val iocell = typeParams.input() val iocell = typeParams.input()
@@ -188,7 +185,10 @@ object IOCell {
if (coreSignal.getWidth == 0) { if (coreSignal.getWidth == 0) {
Seq() Seq()
} else { } else {
require(coreSignal.getWidth == 1, "Analogs wider than 1 bit are not supported because we can't bit-select Analogs (https://github.com/freechipsproject/chisel3/issues/536)") require(
coreSignal.getWidth == 1,
"Analogs wider than 1 bit are not supported because we can't bit-select Analogs (https://github.com/freechipsproject/chisel3/issues/536)"
)
val iocell = typeParams.analog() val iocell = typeParams.analog()
name.foreach(n => iocell.suggestName(n)) name.foreach(n => iocell.suggestName(n))
iocell.io.core <> coreSignal iocell.io.core <> coreSignal
@@ -204,7 +204,7 @@ object IOCell {
// This dummy assignment will prevent invalid firrtl from being emitted // This dummy assignment will prevent invalid firrtl from being emitted
DataMirror.directionOf(coreSignal) match { DataMirror.directionOf(coreSignal) match {
case ActualDirection.Input => coreSignal := 0.U case ActualDirection.Input => coreSignal := 0.U
case _ => {} case _ => {}
} }
Seq() Seq()
} else { } else {