SoC.scala 2.8 KB
Newer Older
Z
Zihao Yu 已提交
1 2
package system

3 4
import chipsalliance.rocketchip.config.Parameters
import device.{AXI4Timer, TLTimer}
Z
Zihao Yu 已提交
5
import chisel3._
Z
zhanglinjuan 已提交
6
import chisel3.util._
7 8
import freechips.rocketchip.diplomacy.{AddressSet, LazyModule, LazyModuleImp}
import freechips.rocketchip.tilelink.{TLFuzzer, TLIdentityNode, TLXbar}
9
import xiangshan.{HasXSParameter, XSCore}
L
LinJiawei 已提交
10 11 12 13 14 15 16 17


case class SoCParameters
(
  EnableILA: Boolean = false,
  HasL2Cache: Boolean = false,
  HasPrefetch: Boolean = false
)
Z
Zihao Yu 已提交
18

19
trait HasSoCParameter extends HasXSParameter{
20
  val soc = top.Parameters.get.socParameters
L
LinJiawei 已提交
21 22 23
  val EnableILA = soc.EnableILA
  val HasL2cache = soc.HasL2Cache
  val HasPrefetch = soc.HasPrefetch
24 25
}

L
LinJiawei 已提交
26
class ILABundle extends Bundle {}
27

Z
Zihao Yu 已提交
28

29 30 31
class DummyCore()(implicit p: Parameters) extends LazyModule {
  val mem = TLFuzzer(nOperations = 10)
  val mmio = TLFuzzer(nOperations = 10)
Z
zhanglinjuan 已提交
32

33
  lazy val module = new LazyModuleImp(this){
34

35 36 37 38 39 40
  }
}


class XSSoc()(implicit p: Parameters) extends LazyModule with HasSoCParameter {

L
linjiawei 已提交
41
  private val xsCore = LazyModule(new XSCore())
Z
zhanglinjuan 已提交
42

43 44 45
  // only mem and extDev visible externally
  val mem = xsCore.mem
  val extDev = TLIdentityNode()
Z
nothing  
zhanglinjuan 已提交
46

47 48 49 50 51
  private val mmioXbar = TLXbar()
  private val clint = LazyModule(new TLTimer(
    Seq(AddressSet(0x38000000L, 0x0000ffffL)),
    sim = !env.FPGAPlatform
  ))
52

53 54 55 56 57 58 59 60 61 62 63 64 65 66
  mmioXbar := xsCore.mmio
  clint.node := mmioXbar
  extDev := mmioXbar

  lazy val module = new LazyModuleImp(this){
    val io = IO(new Bundle{
      val meip = Input(Bool())
      val ila = if(env.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None
    })
    val mtipSync = WireInit(0.U(1.W)) //clint.module.mtip
    val meipSync = RegNext(RegNext(io.meip))
    ExcitingUtils.addSource(mtipSync, "mtip")
    ExcitingUtils.addSource(meipSync, "meip")
  }
Z
Zihao Yu 已提交
67

Y
Yinan Xu 已提交
68
}
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103


//class XSSoc extends Module with HasSoCParameter {
//  val io = IO(new Bundle{
//    val mem = new TLCached(l1BusParams)
//    val mmio = new TLCached(l1BusParams)
//    val frontend = Flipped(new AXI4) //TODO: do we need it ?
//    val meip = Input(Bool())
//    val ila = if (env.FPGAPlatform && EnableILA) Some(Output(new ILABundle)) else None
//  })
//
//  val xsCore = Module(new XSCore)
//
//  io.frontend <> DontCare
//
//  io.mem <> xsCore.io.mem
//
//  val addrSpace = List(
//    (0x40000000L, 0x40000000L), // external devices
//    (0x38000000L, 0x00010000L)  // CLINT
//  )
//  val mmioXbar = Module(new NaiveTL1toN(addrSpace, xsCore.io.mem.params))
//  mmioXbar.io.in <> xsCore.io.mmio
//
//  val extDev = mmioXbar.io.out(0)
//  val clint = Module(new AXI4Timer(sim = !env.FPGAPlatform))
//  clint.io.in <> AXI4ToAXI4Lite(MMIOTLToAXI4(mmioXbar.io.out(1)))
//
//  io.mmio <> extDev
//
//  val mtipSync = clint.io.extra.get.mtip
//  val meipSync = RegNext(RegNext(io.meip))
//  ExcitingUtils.addSource(mtipSync, "mtip")
//  ExcitingUtils.addSource(meipSync, "meip")
//}