1
0

pinctrl: Create extendable Signal classes

This commit is contained in:
Megan Wachs 2017-09-22 13:17:31 -07:00
parent 38f537c438
commit 81e301f9f7
6 changed files with 42 additions and 60 deletions

View File

@ -9,18 +9,19 @@ import sifive.blocks.devices.pinctrl.{Pin}
// even though it looks like something that more directly talks to // even though it looks like something that more directly talks to
// a pin. It also makes it possible to change the exact // a pin. It also makes it possible to change the exact
// type of pad this connects to. // type of pad this connects to.
class GPIOPins[T <: Pin] (pingen: ()=> T, c: GPIOParams) extends Bundle { class GPIOSignals[T <: Data] (pingen: ()=> T, c: GPIOParams) extends Bundle {
val pins = Vec(c.width, pingen()) val pins = Vec(c.width, pingen())
}
override def cloneType: this.type = class GPIOPins[T <: Pin] (pingen: ()=> T, c: GPIOParams) extends GPIOSignals[T](pingen, c)
this.getClass.getConstructors.head.newInstance(pingen, c).asInstanceOf[this.type]
def fromPort(port: GPIOPortIO){ object GPIOPinsFromPort {
def apply[T <: Pin](pins: GPIOSignals[T], port: GPIOPortIO){
// This will just match up the components of the Bundle that // This will just match up the components of the Bundle that
// exist in both. // exist in both.
(pins zip port.pins) foreach {case (pin, port) => (pins.pins zip port.pins) foreach {case (pin, port) =>
pin <> port pin <> port
} }
} }

View File

@ -15,20 +15,20 @@ class I2CSignals[T <: Data](pingen: () => T) extends Bundle {
this.getClass.getConstructors.head.newInstance(pingen).asInstanceOf[this.type] this.getClass.getConstructors.head.newInstance(pingen).asInstanceOf[this.type]
} }
class I2CPins[T <: Pin](pingen: () => T) extends I2CSignals[T](pingen) { class I2CPins[T <: Pin](pingen: () => T) extends I2CSignals[T](pingen)
override def cloneType: this.type =
this.getClass.getConstructors.head.newInstance(pingen).asInstanceOf[this.type]
def fromPort(i2c: I2CPort, clock: Clock, reset: Bool, syncStages: Int = 0) = { object I2CPinsFromPort {
def apply[T <: Pin](pins: I2CSignals[T], i2c: I2CPort, clock: Clock, reset: Bool, syncStages: Int = 0) = {
withClockAndReset(clock, reset) { withClockAndReset(clock, reset) {
scl.outputPin(i2c.scl.out, pue=true.B, ie = true.B) pins.scl.outputPin(i2c.scl.out, pue=true.B, ie = true.B)
scl.o.oe := i2c.scl.oe pins.scl.o.oe := i2c.scl.oe
i2c.scl.in := SyncResetSynchronizerShiftReg(scl.i.ival, syncStages, init = Bool(true), i2c.scl.in := SyncResetSynchronizerShiftReg(pins.scl.i.ival, syncStages, init = Bool(true),
name = Some("i2c_scl_sync")) name = Some("i2c_scl_sync"))
sda.outputPin(i2c.sda.out, pue=true.B, ie = true.B) pins.sda.outputPin(i2c.sda.out, pue=true.B, ie = true.B)
sda.o.oe := i2c.sda.oe pins.sda.o.oe := i2c.sda.oe
i2c.sda.in := SyncResetSynchronizerShiftReg(sda.i.ival, syncStages, init = Bool(true), i2c.sda.in := SyncResetSynchronizerShiftReg(pins.sda.i.ival, syncStages, init = Bool(true),
name = Some("i2c_sda_sync")) name = Some("i2c_sda_sync"))
} }
} }

View File

@ -13,21 +13,25 @@ import freechips.rocketchip.config._
import freechips.rocketchip.jtag.{JTAGIO} import freechips.rocketchip.jtag.{JTAGIO}
import sifive.blocks.devices.pinctrl.{Pin, PinCtrl} import sifive.blocks.devices.pinctrl.{Pin, PinCtrl}
class JTAGPins[T <: Pin](pingen: () => T, hasTRSTn: Boolean = true) extends Bundle { class JTAGSignals[T <: Data](pingen: () => T, hasTRSTn: Boolean = true) extends Bundle {
val TCK = pingen() val TCK = pingen()
val TMS = pingen() val TMS = pingen()
val TDI = pingen() val TDI = pingen()
val TDO = pingen() val TDO = pingen()
val TRSTn = if (hasTRSTn) Option(pingen()) else None val TRSTn = if (hasTRSTn) Option(pingen()) else None
}
def fromPort(jtag: JTAGIO): Unit = { class JTAGPins[T <: Pin](pingen: () => T, hasTRSTn: Boolean = true) extends JTAGSignals[T](pingen, hasTRSTn)
jtag.TCK := TCK.inputPin (pue = Bool(true)).asClock
jtag.TMS := TMS.inputPin (pue = Bool(true))
jtag.TDI := TDI.inputPin(pue = Bool(true))
jtag.TRSTn.foreach{t => t := TRSTn.get.inputPin(pue = Bool(true))}
TDO.outputPin(jtag.TDO.data) object JTAGPinsFromPort {
TDO.o.oe := jtag.TDO.driven
def apply[T <: Pin] (pins: JTAGSignals[T], jtag: JTAGIO): Unit = {
jtag.TCK := pins.TCK.inputPin (pue = Bool(true)).asClock
jtag.TMS := pins.TMS.inputPin (pue = Bool(true))
jtag.TDI := pins.TDI.inputPin(pue = Bool(true))
jtag.TRSTn.foreach{t => t := pins.TRSTn.get.inputPin(pue = Bool(true))}
pins.TDO.outputPin(jtag.TDO.data)
pins.TDO.o.oe := jtag.TDO.driven
} }
} }

View File

@ -13,26 +13,6 @@ class PWMPortIO(val c: PWMParams) extends Bundle {
override def cloneType: this.type = new PWMPortIO(c).asInstanceOf[this.type] override def cloneType: this.type = new PWMPortIO(c).asInstanceOf[this.type]
} }
class PWMSignals[T <: Data] (pingen: ()=> T, val c: PWMParams) extends Bundle {
val pwm: Vec[T] = Vec(c.ncmp, pingen())
override def cloneType: this.type =
this.getClass.getConstructors.head.newInstance(pingen, c).asInstanceOf[this.type]
}
class PWMPins[T <: Pin] (pingen: ()=> T, val c: PWMParams) extends PWMSignals[T](pingen, c) {
override def cloneType: this.type =
this.getClass.getConstructors.head.newInstance(pingen, c).asInstanceOf[this.type]
def fromPort(port: PWMPortIO) {
(pwm zip port.port) foreach {case (pin, port) =>
pin.outputPin(port)
}
}
}
case object PeripheryPWMKey extends Field[Seq[PWMParams]] case object PeripheryPWMKey extends Field[Seq[PWMParams]]

View File

@ -16,25 +16,24 @@ class SPISignals[T <: Data] (pingen: ()=> T, c: SPIParamsBase) extends SPIBundle
} }
class SPIPins[T <: Pin] (pingen: ()=> T, c: SPIParamsBase) extends SPISignals(pingen, c) { class SPIPins[T <: Pin] (pingen: ()=> T, c: SPIParamsBase) extends SPISignals(pingen, c)
override def cloneType: this.type = object SPIPinsFromPort {
this.getClass.getConstructors.head.newInstance(pingen, c).asInstanceOf[this.type]
def apply[T <: Pin](pins: SPISignals[T], spi: SPIPortIO, clock: Clock, reset: Bool,
def fromPort(spi: SPIPortIO, clock: Clock, reset: Bool,
syncStages: Int = 0, driveStrength: Bool = Bool(false)) { syncStages: Int = 0, driveStrength: Bool = Bool(false)) {
withClockAndReset(clock, reset) { withClockAndReset(clock, reset) {
sck.outputPin(spi.sck, ds = driveStrength) pins.sck.outputPin(spi.sck, ds = driveStrength)
(dq zip spi.dq).foreach {case (p, s) => (pins.dq zip spi.dq).foreach {case (p, s) =>
p.outputPin(s.o, pue = Bool(true), ds = driveStrength) p.outputPin(s.o, pue = Bool(true), ds = driveStrength)
p.o.oe := s.oe p.o.oe := s.oe
p.o.ie := ~s.oe p.o.ie := ~s.oe
s.i := ShiftRegister(p.i.ival, syncStages) s.i := ShiftRegister(p.i.ival, syncStages)
} }
(cs zip spi.cs) foreach { case (c, s) => (pins.cs zip spi.cs) foreach { case (c, s) =>
c.outputPin(s, ds = driveStrength) c.outputPin(s, ds = driveStrength)
} }
} }

View File

@ -9,7 +9,6 @@ import freechips.rocketchip.coreplex.{HasPeripheryBus, PeripheryBusKey, HasInter
import freechips.rocketchip.diplomacy.{LazyModule, LazyMultiIOModuleImp} import freechips.rocketchip.diplomacy.{LazyModule, LazyMultiIOModuleImp}
import sifive.blocks.devices.pinctrl.{Pin} import sifive.blocks.devices.pinctrl.{Pin}
class UARTSignals[T <: Data] (pingen: () => T) extends Bundle { class UARTSignals[T <: Data] (pingen: () => T) extends Bundle {
val rxd = pingen() val rxd = pingen()
val txd = pingen() val txd = pingen()
@ -18,14 +17,13 @@ class UARTSignals[T <: Data] (pingen: () => T) extends Bundle {
this.getClass.getConstructors.head.newInstance(pingen).asInstanceOf[this.type] this.getClass.getConstructors.head.newInstance(pingen).asInstanceOf[this.type]
} }
class UARTPins[T <: Pin] (pingen: () => T) extends UARTSignals[T](pingen, c) { class UARTPins[T <: Pin] (pingen: () => T) extends UARTSignals[T](pingen)
override def cloneType: this.type =
this.getClass.getConstructors.head.newInstance(pingen).asInstanceOf[this.type]
def fromPort(uart: UARTPortIO, clock: Clock, reset: Bool, syncStages: Int = 0) { object UARTPinsFromPort {
def apply[T <: Pin](pins: UARTSignals[T], uart: UARTPortIO, clock: Clock, reset: Bool, syncStages: Int = 0) {
withClockAndReset(clock, reset) { withClockAndReset(clock, reset) {
txd.outputPin(uart.txd) pins.txd.outputPin(uart.txd)
val rxd_t = rxd.inputPin() val rxd_t = pins.rxd.inputPin()
uart.rxd := SyncResetSynchronizerShiftReg(rxd_t, syncStages, init = Bool(true), name = Some("uart_rxd_sync")) uart.rxd := SyncResetSynchronizerShiftReg(rxd_t, syncStages, init = Bool(true), name = Some("uart_rxd_sync"))
} }
} }