1*c6d43980SLemover/*************************************************************************************** 2*c6d43980SLemover* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3*c6d43980SLemover* 4*c6d43980SLemover* XiangShan is licensed under Mulan PSL v2. 5*c6d43980SLemover* You can use this software according to the terms and conditions of the Mulan PSL v2. 6*c6d43980SLemover* You may obtain a copy of Mulan PSL v2 at: 7*c6d43980SLemover* http://license.coscl.org.cn/MulanPSL2 8*c6d43980SLemover* 9*c6d43980SLemover* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 10*c6d43980SLemover* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 11*c6d43980SLemover* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 12*c6d43980SLemover* 13*c6d43980SLemover* See the Mulan PSL v2 for more details. 14*c6d43980SLemover***************************************************************************************/ 15*c6d43980SLemover 16b4cc98d2SZihao Yupackage device 17b4cc98d2SZihao Yu 18b4cc98d2SZihao Yuimport chisel3._ 19b4cc98d2SZihao Yuimport chisel3.util._ 20956d83c0Slinjiaweiimport chipsalliance.rocketchip.config.Parameters 21956d83c0Slinjiaweiimport freechips.rocketchip.diplomacy.AddressSet 22b4cc98d2SZihao Yuimport utils._ 23b4cc98d2SZihao Yu 244c494e36SJayclass FlashHelper extends BlackBox with HasBlackBoxInline { 254c494e36SJay val io = IO(new Bundle { 264c494e36SJay val clk = Input(Clock()) 274c494e36SJay val ren = Input(Bool()) 284c494e36SJay val data = Output(UInt(64.W)) 294c494e36SJay val addr = Input(UInt(32.W)) 304c494e36SJay }) 314c494e36SJay 324c494e36SJay setInline("FlashHelper.v", 334c494e36SJay s""" 344c494e36SJay |import "DPI-C" function void flash_read 354c494e36SJay |( 364c494e36SJay | input int addr, 374c494e36SJay | output longint data 384c494e36SJay |); 394c494e36SJay | 404c494e36SJay |module FlashHelper ( 414c494e36SJay | input clk, 424c494e36SJay | input [31:0] addr, 434c494e36SJay | input ren, 444c494e36SJay | output reg [63:0] data 454c494e36SJay |); 464c494e36SJay | 474c494e36SJay | always @(posedge clk) begin 484c494e36SJay | if (ren) flash_read(addr, data); 494c494e36SJay | end 504c494e36SJay | 514c494e36SJay |endmodule 524c494e36SJay """.stripMargin) 534c494e36SJay} 544c494e36SJay 554c494e36SJay 56956d83c0Slinjiaweiclass AXI4Flash 57956d83c0Slinjiawei( 58a2e9bde6SAllen address: Seq[AddressSet] 59956d83c0Slinjiawei)(implicit p: Parameters) 60956d83c0Slinjiawei extends AXI4SlaveModule(address, executable = false) 61956d83c0Slinjiawei{ 62956d83c0Slinjiawei 63956d83c0Slinjiawei override lazy val module = new AXI4SlaveModuleImp(this){ 644c494e36SJay def getOffset(addr: UInt) = addr(15,0) 65b4cc98d2SZihao Yu 664c494e36SJay val flash = Module(new FlashHelper) 674c494e36SJay flash.io.clk := clock 684c494e36SJay flash.io.ren := in.ar.fire() 694c494e36SJay flash.io.addr := Cat(0.U(16.W), getOffset(raddr)) 70b4cc98d2SZihao Yu 714c494e36SJay in.r.bits.data := flash.io.data 72b4cc98d2SZihao Yu } 73956d83c0Slinjiawei} 74