xref: /XiangShan/src/main/scala/device/standalone/StandAloneCLINT.scala (revision 2f9ea9542b31fdf8754121721dddb83b21f14e88)
1/***************************************************************************************
2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3* Copyright (c) 2020-2021 Peng Cheng Laboratory
4*
5* XiangShan is licensed under Mulan PSL v2.
6* You can use this software according to the terms and conditions of the Mulan PSL v2.
7* You may obtain a copy of Mulan PSL v2 at:
8*          http://license.coscl.org.cn/MulanPSL2
9*
10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13*
14* See the Mulan PSL v2 for more details.
15***************************************************************************************/
16
17package device.standalone
18
19import chisel3._
20import chisel3.util._
21import freechips.rocketchip.diplomacy._
22import org.chipsalliance.cde.config.Parameters
23import freechips.rocketchip.devices.tilelink._
24import freechips.rocketchip.interrupts._
25import utility.IntBuffer
26
27class StandAloneCLINT (
28  useTL: Boolean = false,
29  baseAddress: BigInt,
30  addrWidth: Int,
31  dataWidth: Int = 64,
32  hartNum: Int
33)(implicit p: Parameters) extends StandAloneDevice(
34  useTL, baseAddress, addrWidth, dataWidth, hartNum
35) {
36
37  private def clintParam = CLINTParams(baseAddress)
38  def addressSet: AddressSet = clintParam.address
39
40  private val clint = LazyModule(new CLINT(clintParam, dataWidth / 8))
41  clint.node := xbar
42
43  // interrupts
44  val clintIntNode = IntSinkNode(IntSinkPortSimple(hartNum, 2))
45  clintIntNode :*= IntBuffer() :*= clint.intnode
46  val int = InModuleBody(clintIntNode.makeIOs())
47
48  class StandAloneCLINTImp(outer: StandAloneCLINT)(implicit p: Parameters) extends StandAloneDeviceImp(outer) {
49    val io = IO(new Bundle {
50      val rtcTick = Input(Bool())
51      val time = Output(ValidIO(UInt(64.W)))
52    })
53    outer.clint.module.io.rtcTick := io.rtcTick
54    io.time := outer.clint.module.io.time
55  }
56
57  override lazy val module = new StandAloneCLINTImp(this)
58
59}
60