Add mapped address output and test

This commit is contained in:
Byron Lathi
2023-10-18 08:54:23 -07:00
parent 35d4ea968e
commit 69e443d223
2 changed files with 21 additions and 0 deletions

View File

@@ -63,6 +63,8 @@ int errors;
int rnd_values [16]; int rnd_values [16];
int rnd_addr;
initial begin initial begin
for (int i = 0; i < 16; i++) begin for (int i = 0; i < 16; i++) begin
rnd_values[i] = $urandom(); rnd_values[i] = $urandom();
@@ -95,6 +97,17 @@ initial begin
end end
end end
for (int i = 0; i < 16; i++) begin
rnd_addr = $urandom();
addr = i << 12 | rnd_addr[11:0];
#1 // Neccesary for this assertion to work
assert (map_addr == {rnd_values[i][12:0], rnd_addr[11:0]}) else begin
$error("Expected %x got %x", {rnd_values[i][12:0], rnd_addr[11:0]}, map_addr);
end
@(posedge r_clk_cpu);
end
if (errors != 0) begin if (errors != 0) begin
$finish_and_return(-1); $finish_and_return(-1);
end else begin end else begin

View File

@@ -13,12 +13,20 @@ logic [15:0] mm [16];
logic [31:0] we; logic [31:0] we;
// TODO These have basically the same name.
logic [15:0] mm_sel; logic [15:0] mm_sel;
logic [15:0] selected_mm;
always_comb begin always_comb begin
we = (i_we << i_cpu_addr[4:0]); we = (i_we << i_cpu_addr[4:0]);
mm_sel = (1 << i_cpu_addr[4:1]);
o_data = mm_sel[8*i_cpu_addr[0] +: 8]; o_data = mm_sel[8*i_cpu_addr[0] +: 8];
selected_mm = mm[i_cpu_addr[15:12]];
o_mapped_addr = {selected_mm[12:0], i_cpu_addr[11:0]};
end end
always_ff @(negedge i_clk or posedge i_reset) begin always_ff @(negedge i_clk or posedge i_reset) begin