xref: /XiangShan/src/main/scala/device/AXI4UART.scala (revision a3e876088a970fa1ef84da031edd9363593d0e9f)
1c6d43980SLemover/***************************************************************************************
2c6d43980SLemover* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
3f320e0f0SYinan Xu* Copyright (c) 2020-2021 Peng Cheng Laboratory
4c6d43980SLemover*
5c6d43980SLemover* XiangShan is licensed under Mulan PSL v2.
6c6d43980SLemover* You can use this software according to the terms and conditions of the Mulan PSL v2.
7c6d43980SLemover* You may obtain a copy of Mulan PSL v2 at:
8c6d43980SLemover*          http://license.coscl.org.cn/MulanPSL2
9c6d43980SLemover*
10c6d43980SLemover* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11c6d43980SLemover* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12c6d43980SLemover* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13c6d43980SLemover*
14c6d43980SLemover* See the Mulan PSL v2 for more details.
15c6d43980SLemover***************************************************************************************/
16c6d43980SLemover
17d7763dc0SZihao Yupackage device
18d7763dc0SZihao Yu
19d7763dc0SZihao Yuimport chisel3._
20d7763dc0SZihao Yuimport chisel3.util._
21956d83c0Slinjiaweiimport chipsalliance.rocketchip.config.Parameters
22956d83c0Slinjiaweiimport freechips.rocketchip.diplomacy.AddressSet
23d7763dc0SZihao Yuimport utils._
24*a3e87608SWilliam Wangimport difftest._
25d18aeea6SLinJiawei
26956d83c0Slinjiaweiclass AXI4UART
27956d83c0Slinjiawei(
28a2e9bde6SAllen  address: Seq[AddressSet]
29956d83c0Slinjiawei)(implicit p: Parameters)
30956d83c0Slinjiawei  extends AXI4SlaveModule(address, executable = false, _extra = new UARTIO)
31956d83c0Slinjiawei{
32956d83c0Slinjiawei  override lazy val module = new AXI4SlaveModuleImp[UARTIO](this){
33d7763dc0SZihao Yu    val rxfifo = RegInit(0.U(32.W))
34d7763dc0SZihao Yu    val txfifo = Reg(UInt(32.W))
35d7763dc0SZihao Yu    val stat = RegInit(1.U(32.W))
36d7763dc0SZihao Yu    val ctrl = RegInit(0.U(32.W))
37d7763dc0SZihao Yu
38a428082bSLinJiawei    io.extra.get.out.valid := (waddr(3,0) === 4.U && in.w.fire())
39a428082bSLinJiawei    io.extra.get.out.ch := in.w.bits.data(7,0)
40efc6a777Slinjiawei    io.extra.get.in.valid := (raddr(3,0) === 0.U && in.r.fire())
41d7763dc0SZihao Yu
42d7763dc0SZihao Yu    val mapping = Map(
43a428082bSLinJiawei      RegMap(0x0, io.extra.get.in.ch, RegMap.Unwritable),
44d18aeea6SLinJiawei      RegMap(0x4, txfifo),
45d7763dc0SZihao Yu      RegMap(0x8, stat),
46d7763dc0SZihao Yu      RegMap(0xc, ctrl)
47d7763dc0SZihao Yu    )
48d7763dc0SZihao Yu
49d7763dc0SZihao Yu    RegMap.generate(mapping, raddr(3,0), in.r.bits.data,
50956d83c0Slinjiawei      waddr(3,0), in.w.fire(), in.w.bits.data, MaskExpand(in.w.bits.strb >> waddr(2,0))
51956d83c0Slinjiawei    )
52956d83c0Slinjiawei  }
53d7763dc0SZihao Yu}
54