随分間が空いたけど「Rocket Chipに自分のモジュールを追加してみる」の2回目。 今回は前回作成したPWMモジュールを組み込むRocket Chipとしてのシステムのトップモジュール部分を見ていく。
Top.scala
参照するソースコード自体は以下のもの。
src/main/scala/example/Top.scala
このファイルから必要な部分のみを適宜分割しながら、解説を加えていく。
必要なインポート
これは特に説明不要ですね。とりあえずインポートでこれだけ必要ということで。
package example import chisel3._ import freechips.rocketchip.diplomacy._ import freechips.rocketchip.subsystem._ import freechips.rocketchip.config.Parameters import freechips.rocketchip.devices.tilelink._ import freechips.rocketchip.util.DontTouch import freechips.rocketchip.tilelink.BankBinder import testchipip._ import icenet._
ExampleTop
次はExampleTop
。これはRocket Chipの時のものと一緒だが、v1.2-050719-SNAPSHOT時点のもの。
v1.2-073119-SNAPSHOT以降ではExampleTop
に関してもトレイトを継承するだけ、処理が完結するように変更が行われています。
class ExampleTop(implicit p: Parameters) extends RocketSubsystem with CanHaveMasterAXI4MemPort with HasPeripheryBootROM // with HasSystemErrorSlave with HasSyncExtInterrupts with HasNoDebug with HasPeripherySerial { override lazy val module = new ExampleTopModuleImp(this) // The sbus masters the cbus; here we convert TL-UH -> TL-UL sbus.crossToBus(cbus, NoCrossing) // The cbus masters the pbus; which might be clocked slower cbus.crossToBus(pbus, SynchronousCrossing()) // The fbus masters the sbus; both are TL-UH or TL-C FlipRendering { implicit p => sbus.crossFromBus(fbus, SynchronousCrossing()) } // The sbus masters the mbus; here we convert TL-C -> TL-UH private val BankedL2Params(nBanks, coherenceManager) = p(BankedL2Key) private val (in, out, halt) = coherenceManager(this) if (nBanks != 0) { sbus.coupleTo("coherence_manager") { in :*= _ } mbus.coupleFrom("coherence_manager") { _ :=* BankBinder(mbus.blockBytes * (nBanks-1)) :*= out } } } class ExampleTopModuleImp[+L <: ExampleTop](l: L) extends RocketSubsystemModuleImp(l) with HasRTCModuleImp with CanHaveMasterAXI4MemPortModuleImp with HasPeripheryBootROMModuleImp with HasExtInterruptsModuleImp with HasNoDebugModuleImp with HasPeripherySerialModuleImp with DontTouch
PWMを組み込んだExampleTop
で、こちらが作成しているPWMモジュールを組み込んだモジュール。
やること自体は非常に簡単で、作ったHasPeripheryPWM
/HasPeripheryPWMModuleImp
をMix-inするだけ。
これだけで後はRocket Chipの仕組みがHasPeripheryPWM
内でPWMTL
に与えたPWMParams
の情報を読み取って、TLへの組み込みを行ってくれる。
class ExampleTopWithPWM(implicit p: Parameters) extends ExampleTop with HasPeripheryPWM { override lazy val module = new ExampleTopWithPWMModule(this) } class ExampleTopWithPWMModule(l: ExampleTopWithPWM) extends ExampleTopModuleImp(l) with HasPeripheryPWMModuleImp
2回めはあっさりだけど、これで終了。