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._ 25 26class StandAloneCLINT ( 27 useTL: Boolean = false, 28 baseAddress: BigInt, 29 addrWidth: Int, 30 dataWidth: Int = 64, 31 hartNum: Int 32)(implicit p: Parameters) extends StandAloneDevice( 33 useTL, baseAddress, addrWidth, dataWidth, hartNum 34) { 35 36 private def clintParam = CLINTParams(baseAddress) 37 def addressSet: AddressSet = clintParam.address 38 39 private val clint = LazyModule(new CLINT(clintParam, dataWidth / 8)) 40 clint.node := xbar 41 42 // interrupts 43 val clintIntNode = IntSinkNode(IntSinkPortSimple(hartNum, 2)) 44 clintIntNode :*= clint.intnode 45 val int = InModuleBody(clintIntNode.makeIOs()) 46 47 class StandAloneCLINTImp(outer: StandAloneCLINT)(implicit p: Parameters) extends StandAloneDeviceImp(outer) { 48 val io = IO(new Bundle { 49 val rtcTick = Input(Bool()) 50 val time = Output(ValidIO(UInt(64.W))) 51 }) 52 outer.clint.module.io.rtcTick := io.rtcTick 53 io.time := outer.clint.module.io.time 54 } 55 56 override lazy val module = new StandAloneCLINTImp(this) 57 58} 59