Skip to content

Commit

Permalink
Merge pull request #2146 from ucb-bar/i2c-fix
Browse files Browse the repository at this point in the history
Add I2C peripheral example
  • Loading branch information
jerryz123 authored Dec 6, 2024
2 parents d4ebf93 + af63872 commit dd2ce08
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AbstractConfig extends Config(
new chipyard.harness.WithSimDMI ++ /** add SimJTAG if DMI exposed */
new chipyard.harness.WithGPIOPinsTiedOff ++ /** tie-off chiptop GPIO-pins, if GPIO-punchthrough is used */
new chipyard.harness.WithGPIOTiedOff ++ /** tie-off chiptop GPIOs, if GPIOs are present */
new chipyard.harness.WithI2CTiedOff ++ /** tie-off i2c ports if present */
new chipyard.harness.WithSimSPIFlashModel ++ /** add simulated SPI flash memory, if SPI is enabled */
new chipyard.harness.WithSimAXIMMIO ++ /** add SimAXIMem for axi4 mmio port, if enabled */
new chipyard.harness.WithTieOffInterrupts ++ /** tie-off interrupt ports, if present */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class SmallSPIFlashRocketConfig extends Config(
new freechips.rocketchip.rocket.WithNHugeCores(1) ++
new chipyard.config.AbstractConfig)

class I2CRocketConfig extends Config(
new chipyard.harness.WithI2CTiedOff ++ // Tie off the I2C port in the harness
new chipyard.config.WithI2C ++ // Add I2C peripheral
new freechips.rocketchip.rocket.WithNHugeCores(1) ++
new chipyard.config.AbstractConfig)

class SimBlockDeviceRocketConfig extends Config(
new chipyard.harness.WithSimBlockDevice ++ // drive block-device IOs with SimBlockDevice
new testchipip.iceblk.WithBlockDevice ++ // add block-device module to peripherybus
Expand Down Expand Up @@ -71,12 +77,15 @@ class dmiCospikeCheckpointingRocketConfig extends Config(


class ManyPeripheralsRocketConfig extends Config(
new chipyard.harness.WithI2CTiedOff ++ // Tie off the I2C port in the harness
new chipyard.harness.WithSimSPIFlashModel(true) ++ // add the SPI flash model in the harness (read-only)
new chipyard.harness.WithSimBlockDevice ++ // drive block-device IOs with SimBlockDevice

new testchipip.iceblk.WithBlockDevice ++ // add block-device module to peripherybus
new testchipip.soc.WithOffchipBusClient(MBUS) ++ // OBUS provides backing memory to the MBUS
new testchipip.soc.WithOffchipBus ++ // OBUS must exist for serial-tl to master off-chip memory
new testchipip.serdes.WithSerialTLMem(isMainMemory=true) ++ // set lbwif memory base to DRAM_BASE, use as main memory
new chipyard.harness.WithSimSPIFlashModel(true) ++ // add the SPI flash model in the harness (read-only)
new chipyard.harness.WithSimBlockDevice ++ // drive block-device IOs with SimBlockDevice
new chipyard.config.WithI2C ++ // Add I2C peripheral
new chipyard.config.WithPeripheryTimer ++ // add the pwm timer device
new chipyard.config.WithSPIFlash ++ // add the SPI flash controller
new freechips.rocketchip.subsystem.WithDefaultMMIOPort ++ // add default external master port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class WithSimSPIFlashModel(rdOnly: Boolean = true) extends HarnessBinder({
}
})

class WithI2CTiedOff extends HarnessBinder({
case (th: HasHarnessInstantiators, port: I2CPort, chipId: Int) => {
port.io <> DontCare
}
})

class WithSimBlockDevice extends HarnessBinder({
case (th: HasHarnessInstantiators, port: BlockDevicePort, chipId: Int) => {
val sim_blkdev = Module(new SimBlockDevice(port.params))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class WithI2CPunchthrough extends OverrideIOBinder({
val ports = system.i2c.zipWithIndex.map { case (i2c, i) =>
val io_i2c = IO(i2c.cloneType).suggestName(s"i2c_$i")
io_i2c <> i2c
I2CPort(() => i2c)
I2CPort(() => io_i2c)
}
(ports, Nil)
}
Expand Down

0 comments on commit dd2ce08

Please sign in to comment.