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 17b4cc98d2SZihao Yupackage device 18b4cc98d2SZihao Yu 19b4cc98d2SZihao Yuimport chisel3._ 20b4cc98d2SZihao Yuimport chisel3.util._ 21*8891a219SYinan Xuimport org.chipsalliance.cde.config.Parameters 22510ae4eeSJiuyang Liuimport chisel3.experimental.ExtModule 23956d83c0Slinjiaweiimport freechips.rocketchip.diplomacy.AddressSet 24b4cc98d2SZihao Yuimport utils._ 253c02ee8fSwakafaimport utility._ 26b4cc98d2SZihao Yu 27510ae4eeSJiuyang Liuclass FlashHelper extends ExtModule with HasExtModuleInline { 28510ae4eeSJiuyang Liu val clk = IO(Input(Clock())) 29510ae4eeSJiuyang Liu val ren = IO(Input(Bool())) 30510ae4eeSJiuyang Liu val data = IO(Output(UInt(64.W))) 31510ae4eeSJiuyang Liu val addr = IO(Input(UInt(32.W))) 324c494e36SJay 334c494e36SJay setInline("FlashHelper.v", 344c494e36SJay s""" 354c494e36SJay |import "DPI-C" function void flash_read 364c494e36SJay |( 374c494e36SJay | input int addr, 384c494e36SJay | output longint data 394c494e36SJay |); 404c494e36SJay | 414c494e36SJay |module FlashHelper ( 424c494e36SJay | input clk, 434c494e36SJay | input [31:0] addr, 444c494e36SJay | input ren, 454c494e36SJay | output reg [63:0] data 464c494e36SJay |); 474c494e36SJay | 484c494e36SJay | always @(posedge clk) begin 494c494e36SJay | if (ren) flash_read(addr, data); 504c494e36SJay | end 514c494e36SJay | 524c494e36SJay |endmodule 534c494e36SJay """.stripMargin) 544c494e36SJay} 554c494e36SJay 564c494e36SJay 57956d83c0Slinjiaweiclass AXI4Flash 58956d83c0Slinjiawei( 59a2e9bde6SAllen address: Seq[AddressSet] 60956d83c0Slinjiawei)(implicit p: Parameters) 61956d83c0Slinjiawei extends AXI4SlaveModule(address, executable = false) 62956d83c0Slinjiawei{ 63956d83c0Slinjiawei 64956d83c0Slinjiawei override lazy val module = new AXI4SlaveModuleImp(this){ 654c494e36SJay def getOffset(addr: UInt) = addr(15,0) 66b4cc98d2SZihao Yu 674c494e36SJay val flash = Module(new FlashHelper) 68510ae4eeSJiuyang Liu flash.clk := clock 69935edac4STang Haojin flash.ren := in.ar.fire 70510ae4eeSJiuyang Liu flash.addr := Cat(0.U(16.W), getOffset(raddr)) 71b4cc98d2SZihao Yu 72510ae4eeSJiuyang Liu in.r.bits.data := flash.data 73b4cc98d2SZihao Yu } 74956d83c0Slinjiawei} 75