Skip to content

Commit

Permalink
Merge pull request #212 from ucb-bar/chip-id-pin
Browse files Browse the repository at this point in the history
Add Chip ID Pin
  • Loading branch information
jerryz123 authored Jan 16, 2024
2 parents 249567f + 28a4d01 commit edacb21
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/main/scala/soc/ChipIdPin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package testchipip.soc

import chisel3._
import chisel3.util._
import org.chipsalliance.cde.config._
import freechips.rocketchip.tilelink._
import freechips.rocketchip.diplomacy._
import freechips.rocketchip.regmapper._
import freechips.rocketchip.subsystem._

case class ChipIdPinParams (
width: Int = 1,
chipIdAddr: BigInt = 0x2000,
slaveWhere: TLBusWrapperLocation = CBUS
)

case object ChipIdPinKey extends Field[Option[ChipIdPinParams]](None)

trait CanHavePeripheryChipIdPin { this: BaseSubsystem =>
val chip_id_pin = p(ChipIdPinKey).map { params =>
val tlbus = locateTLBusWrapper(params.slaveWhere)
val device = new SimpleDevice("chip-id-reg", Nil)

val inner_io = tlbus {
val node = TLRegisterNode(
address = Seq(AddressSet(params.chipIdAddr, 4096 - 1)),
device = device,
beatBytes=tlbus.beatBytes)
tlbus.coupleTo(s"chip-id-reg"){ node := TLFragmenter(tlbus.beatBytes, tlbus.blockBytes) := _ }
InModuleBody {
val chip_id = IO(Input(UInt(params.width.W))).suggestName("chip_id")
node.regmap(0 -> Seq(RegField.r(64, chip_id)))
chip_id
}
}
val outer_io = InModuleBody {
val chip_id = IO(Input(UInt(params.width.W))).suggestName("chip_id")
inner_io := chip_id
chip_id
}
outer_io
}
}
13 changes: 13 additions & 0 deletions src/main/scala/soc/Configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ class WithOffchipBusClient(
OffchipBusTopologyConnectionParams(location, blockRange, replicationBase)
})

//-------------------------
// ChipIdPin Configs
//-------------------------

class WithChipIdPin(params: ChipIdPinParams = ChipIdPinParams()) extends Config((site, here, up) => {
case ChipIdPinKey => Some(params)
})

// Used for setting pin width
class WithChipIdPinWidth(width: Int) extends Config((site, here, up) => {
case ChipIdPinKey => up(ChipIdPinKey, site).map(p => p.copy(width = width))
})

// Deprecated: use Constellation's network-on-chip generators instead of this
class WithRingSystemBus(
buffer: TLNetworkBufferParams = TLNetworkBufferParams.default)
Expand Down

0 comments on commit edacb21

Please sign in to comment.