📄 mem_access.sv
字号:
// // -------------------------------------------------------------// Copyright 2004-2008 Synopsys, Inc.// All Rights Reserved Worldwide// // Licensed under the Apache License, Version 2.0 (the// "License"); you may not use this file except in// compliance with the License. You may obtain a copy of// the License at// // http://www.apache.org/licenses/LICENSE-2.0// // Unless required by applicable law or agreed to in// writing, software distributed under the License is// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR// CONDITIONS OF ANY KIND, either express or implied. See// the License for the specific language governing// permissions and limitations under the License.// -------------------------------------------------------------// `include "ral_env.svh"`ifndef RAL_TB_ENV`define RAL_TB_ENV tb_env`endifprogram mem_access;vmm_log log = new("Mem Access", "Test");`RAL_TB_ENV env = new;initialbegin vmm_ral_block_or_sys ral_model; vmm_ral_mem mems[]; ral_model = env.ral.get_model(); if (ral_model == null) begin `vmm_fatal(log, "No RAL abstraction model was specified"); end env.reset_dut(); ral_model.reset(); // Access each location in all memories ral_model.get_memories(mems); foreach (mems[i]) begin vmm_ral::access_e mode; string domains[]; int n_bits; // Can only deal with memories with backdoor access if (mems[i].get_backdoor() == null) begin `vmm_warning(log, $psprintf("Memory \"%s\" does not have a backdoor mechanism available", mems[i].get_fullname())); continue; end n_bits = mems[i].get_n_bits(); // Memories may be accessible from multiple physical interfaces (domains) mems[i].get_domains(domains); // Walk the memory via each domain foreach (domains[j]) begin vmm_rw::status_e status; bit [`VMM_RAL_DATA_WIDTH-1:0] val, exp, v; `vmm_note(log, $psprintf("Accessing memory %s in domain \"%s\"...\n", mems[i].get_fullname(), domains[j])); mode = mems[i].get_access(domains[j]); // The access process is, for address k: // - Write random value via front door // - Read via backdoor and expect same random value if RW // - Write complement of random value via back door // - Read via front door and expect inverted random value for (int k = 0; k < mems[i].get_size(); k++) begin val = $random & ((1'b1<<n_bits)-1); if (mode == vmm_ral::RO) begin mems[i].peek(status, k, exp); if (status != vmm_rw::IS_OK) begin `vmm_error(log, $psprintf("Status was %s when reading \"%s[%0d]\" through backdoor.", status.name(), mems[i].get_fullname(), k)); end end else exp = val; mems[i].write(status, k, val, vmm_ral::BFM, domains[j]); if (status != vmm_rw::IS_OK) begin `vmm_error(log, $psprintf("Status was %s when writing \"%s[%0d]\" through domain \"%s\".", status.name(), mems[i].get_fullname(), k, domains[j])); end val = 'x; mems[i].peek(status, k, val); if (status != vmm_rw::IS_OK) begin `vmm_error(log, $psprintf("Status was %s when reading \"%s[%0d]\" through backdoor.", status.name(), mems[i].get_fullname(), k)); end else begin if (val !== exp) begin `vmm_error(log, $psprintf("Backdoor \"%s[%0d]\" read back as 'h%h instead of 'h%h.", mems[i].get_fullname(), k, val, exp)); end end exp = ~exp & ((1'b1<<n_bits)-1); mems[i].poke(status, k, exp); if (status != vmm_rw::IS_OK) begin `vmm_error(log, $psprintf("Status was %s when writing \"%s[%0d-1]\" through backdoor.", status.name(), mems[i].get_fullname(), k)); end mems[i].read(status, k, val, vmm_ral::BFM, domains[j]); if (status != vmm_rw::IS_OK) begin `vmm_error(log, $psprintf("Status was %s when reading \"%s[%0d]\" through domain \"%s\".", status.name(), mems[i].get_fullname(), k, domains[j])); end else begin if (mode == vmm_ral::WO) begin if (val !== '0) begin `vmm_error(log, $psprintf("Front door \"%s[%0d]\" read back as 'h%h instead of 'h%h.", mems[i].get_fullname(), k, val, 0)); end end else begin if (val !== exp) begin `vmm_error(log, $psprintf("Front door \"%s[%0d]\" read back as 'h%h instead of 'h%h.", mems[i].get_fullname(), k, val, exp)); end end end end end end env.log.report();endendprogram: mem_access
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -