Skip to content

Commit

Permalink
support vivado simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
taichi-ishitani committed May 30, 2022
1 parent e80046a commit 1a88d9f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 33 deletions.
5 changes: 2 additions & 3 deletions rggen_backdoor.sv
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
`ifdef RGGEN_ENABLE_BACKDOOR
module rggen_backdoor #(
parameter int DATA_WIDTH = 32,
parameter bit INSIDE_VHDL_DESIGN = 0
parameter int DATA_WIDTH = 32
)(
input logic i_clk,
input logic i_rst_n,
Expand Down Expand Up @@ -39,7 +38,7 @@ module rggen_backdoor #(
end

initial begin
rggen_backdoor_pkg::set_backdoor_vif($sformatf("%m"), INSIDE_VHDL_DESIGN, backdoor_if);
rggen_backdoor_pkg::set_backdoor_vif($sformatf("%m"), backdoor_if);
end
endmodule
`endif
90 changes: 60 additions & 30 deletions rggen_backdoor_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,73 @@
`ifdef RGGEN_ENABLE_BACKDOOR
package rggen_backdoor_pkg;
typedef virtual rggen_backdoor_if rggen_backdoor_vif;
rggen_backdoor_vif backdoor_vif[string];

function automatic void set_backdoor_vif(
string hdl_path,
bit inside_vhdl_design,
rggen_backdoor_vif vif
);
string path;
class rggen_backdoor_if_store;
`ifndef XILINX_SIMULATOR
protected rggen_backdoor_vif vif[string];

if (inside_vhdl_design) begin
path = normalize_hdl_path(hdl_path);
end
else begin
path = hdl_path;
end
function void set(string hdl_path, rggen_backdoor_vif vif);
string path;
path = normalize_hdl_path(hdl_path);
this.vif[path] = vif;
endfunction

backdoor_vif[path] = vif;
endfunction
function rggen_backdoor_vif get(string hdl_path);
return vif[hdl_path];
endfunction
`else
class rggen_backdoor_if_wrapper;
rggen_backdoor_vif vif;
function new(rggen_backdoor_vif vif);
this.vif = vif;
endfunction
endclass

protected rggen_backdoor_if_wrapper vif_wrapper[string];

function automatic string normalize_hdl_path(
string original_path
function void set(string hdl_path, rggen_backdoor_vif vif);
string path;
path = normalize_hdl_path(hdl_path);
this.vif_wrapper[path] = new(vif);
endfunction

function rggen_backdoor_vif get(string hdl_path);
return vif_wrapper[hdl_path].vif;
endfunction
`endif
protected function string normalize_hdl_path(string path);
string normalized_path;
for (int i = 0;i < path.len();++i) begin
if ((path[i] != "\\") && (path[i] != " ")) begin
normalized_path = {normalized_path, path[i]};
end
end
return normalized_path.tolower();
endfunction

static protected rggen_backdoor_if_store store;

static function rggen_backdoor_if_store get_store();
if (store == null) begin
store = new;
end
return store;
endfunction
endclass

function automatic void set_backdoor_vif(
string hdl_path,
rggen_backdoor_vif vif
);
string path;
path = original_path;
if (path[0] == "\\") begin
path = path.substr(1, path.len() - 1);
end
if (path[path.len()-1] == " ") begin
path = path.substr(0, path.len() - 2);
end
return path.tolower();
rggen_backdoor_if_store store;
store = rggen_backdoor_if_store::get_store();
store.set(hdl_path, vif);
endfunction

function automatic rggen_backdoor_vif get_backdoor_vif(
string hdl_path
);
return backdoor_vif[hdl_path];
function automatic rggen_backdoor_vif get_backdoor_vif(string hdl_path);
rggen_backdoor_if_store store;
store = rggen_backdoor_if_store::get_store();
return store.get(hdl_path);
endfunction
endpackage
`endif
Expand Down

0 comments on commit 1a88d9f

Please sign in to comment.