Use HomogenousBag to handle lists of peripherals
Previously we had to do weird things to make non-homogenous lists of items (e.g. PWM Peripherals where ncmp were different from one to the other) into a vector. But now Chisel supports a Record type, and we use the HomogenousBag utility to do this more naturally. This also deletes all the cruft which was introduced to get around the limitation which doesn't exist anymore.
This commit is contained in:
parent
348bbb97f4
commit
03be9aba67
@ -44,16 +44,6 @@ case class PWMConfig(
|
|||||||
regBytes: Int = 4,
|
regBytes: Int = 4,
|
||||||
ncmp: Int = 4,
|
ncmp: Int = 4,
|
||||||
cmpWidth: Int = 16)
|
cmpWidth: Int = 16)
|
||||||
{
|
|
||||||
val bc = new PWMBundleConfig(ncmp)
|
|
||||||
}
|
|
||||||
|
|
||||||
case class PWMBundleConfig(
|
|
||||||
ncmp: Int)
|
|
||||||
{
|
|
||||||
def union(that: PWMBundleConfig): PWMBundleConfig =
|
|
||||||
PWMBundleConfig(scala.math.max(ncmp, that.ncmp))
|
|
||||||
}
|
|
||||||
|
|
||||||
trait HasPWMParameters {
|
trait HasPWMParameters {
|
||||||
implicit val p: Parameters
|
implicit val p: Parameters
|
||||||
|
@ -6,19 +6,20 @@ import config._
|
|||||||
import diplomacy.LazyModule
|
import diplomacy.LazyModule
|
||||||
import rocketchip.{TopNetwork,TopNetworkModule}
|
import rocketchip.{TopNetwork,TopNetworkModule}
|
||||||
import uncore.tilelink2.TLFragmenter
|
import uncore.tilelink2.TLFragmenter
|
||||||
|
import util.HeterogeneousBag
|
||||||
|
|
||||||
import sifive.blocks.devices.gpio._
|
import sifive.blocks.devices.gpio._
|
||||||
|
|
||||||
class PWMPortIO(c: PWMBundleConfig)(implicit p: Parameters) extends Bundle {
|
class PWMPortIO(c: PWMConfig)(implicit p: Parameters) extends Bundle {
|
||||||
val port = Vec(c.ncmp, Bool()).asOutput
|
val port = Vec(c.ncmp, Bool()).asOutput
|
||||||
override def cloneType: this.type = new PWMPortIO(c).asInstanceOf[this.type]
|
override def cloneType: this.type = new PWMPortIO(c).asInstanceOf[this.type]
|
||||||
}
|
}
|
||||||
|
|
||||||
class PWMPinsIO(c: PWMBundleConfig)(implicit p: Parameters) extends Bundle {
|
class PWMPinsIO(c: PWMConfig)(implicit p: Parameters) extends Bundle {
|
||||||
val pwm = Vec(c.ncmp, new GPIOPin)
|
val pwm = Vec(c.ncmp, new GPIOPin)
|
||||||
}
|
}
|
||||||
|
|
||||||
class PWMGPIOPort(c: PWMBundleConfig)(implicit p: Parameters) extends Module {
|
class PWMGPIOPort(c: PWMConfig)(implicit p: Parameters) extends Module {
|
||||||
val io = new Bundle {
|
val io = new Bundle {
|
||||||
val pwm = new PWMPortIO(c).flip()
|
val pwm = new PWMPortIO(c).flip()
|
||||||
val pins = new PWMPinsIO(c)
|
val pins = new PWMPinsIO(c)
|
||||||
@ -43,8 +44,7 @@ trait PeripheryPWMBundle {
|
|||||||
val p: Parameters
|
val p: Parameters
|
||||||
val pwmConfigs: Seq[PWMConfig]
|
val pwmConfigs: Seq[PWMConfig]
|
||||||
} =>
|
} =>
|
||||||
val pwm_bc = pwmConfigs.map(_.bc).reduce(_.union(_))
|
val pwms = HeterogeneousBag(pwmConfigs.map(new PWMPortIO(_)(p)))
|
||||||
val pwms = Vec(pwmConfigs.size, new PWMPortIO(pwm_bc)(p))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trait PeripheryPWMModule {
|
trait PeripheryPWMModule {
|
||||||
|
@ -5,6 +5,7 @@ import Chisel._
|
|||||||
import diplomacy.LazyModule
|
import diplomacy.LazyModule
|
||||||
import uncore.tilelink2._
|
import uncore.tilelink2._
|
||||||
import rocketchip.{TopNetwork,TopNetworkModule}
|
import rocketchip.{TopNetwork,TopNetworkModule}
|
||||||
|
import util.HeterogeneousBag
|
||||||
|
|
||||||
trait PeripherySPI {
|
trait PeripherySPI {
|
||||||
this: TopNetwork { val spiConfigs: Seq[SPIConfig] } =>
|
this: TopNetwork { val spiConfigs: Seq[SPIConfig] } =>
|
||||||
@ -18,8 +19,7 @@ trait PeripherySPI {
|
|||||||
|
|
||||||
trait PeripherySPIBundle {
|
trait PeripherySPIBundle {
|
||||||
this: { val spiConfigs: Seq[SPIConfig] } =>
|
this: { val spiConfigs: Seq[SPIConfig] } =>
|
||||||
val spi_bc = spiConfigs.map(_.bc).reduce(_.union(_))
|
val spis = HeterogeneousBag(spiConfigs.map(new SPIPortIO(_)))
|
||||||
val spis = Vec(spiConfigs.size, new SPIPortIO(spi_bc.toSPIConfig))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trait PeripherySPIModule {
|
trait PeripherySPIModule {
|
||||||
|
@ -30,7 +30,6 @@ trait SPIConfigBase {
|
|||||||
lazy val txDepthBits = log2Floor(txDepth) + 1
|
lazy val txDepthBits = log2Floor(txDepth) + 1
|
||||||
lazy val rxDepthBits = log2Floor(rxDepth) + 1
|
lazy val rxDepthBits = log2Floor(rxDepth) + 1
|
||||||
|
|
||||||
lazy val bc = new SPIBundleConfig(csWidth)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case class SPIConfig(
|
case class SPIConfig(
|
||||||
@ -49,15 +48,6 @@ case class SPIConfig(
|
|||||||
require(sampleDelay >= 0)
|
require(sampleDelay >= 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class SPIBundleConfig(csWidth: Int)
|
|
||||||
{
|
|
||||||
def union(that: SPIBundleConfig): SPIBundleConfig =
|
|
||||||
SPIBundleConfig(scala.math.max(csWidth, that.csWidth))
|
|
||||||
|
|
||||||
def toSPIConfig: SPIConfig = new SPIConfig(rAddress = -1,
|
|
||||||
csWidth = csWidth)
|
|
||||||
}
|
|
||||||
|
|
||||||
class SPITopBundle(val i: Vec[Vec[Bool]], val r: Vec[TLBundle]) extends Bundle
|
class SPITopBundle(val i: Vec[Vec[Bool]], val r: Vec[TLBundle]) extends Bundle
|
||||||
|
|
||||||
class SPITopModule[B <: SPITopBundle](c: SPIConfigBase, bundle: => B, outer: TLSPIBase)
|
class SPITopModule[B <: SPITopBundle](c: SPIConfigBase, bundle: => B, outer: TLSPIBase)
|
||||||
|
Loading…
Reference in New Issue
Block a user