Skip to content

Commit a1436de

Browse files
committed
Added mechanism for loading instructions in RAM
1 parent 426ce89 commit a1436de

File tree

8 files changed

+103
-17
lines changed

8 files changed

+103
-17
lines changed

build.tcl

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# "C:/Users/A/tis100/data/seq_gen/seq_gen_ina.mem"
3333
# "C:/Users/A/tis100/src/ip/tis100_1.0/src/my_params.vh"
3434
# "C:/Users/A/tis100/data/dir_manager_tv.mem"
35-
# "C:/Users/A/tis100/data/instr_rom_tv.mem"
35+
# "C:/Users/A/tis100/data/instr_ram_tv.mem"
3636
# "C:/Users/A/tis100/data/seq_gen/seq_gen_node2.mem"
3737
# "C:/Users/A/tis100/data/test_mult.mem"
3838
# "C:/Users/A/tis100/data/registers_tv.mem"
@@ -50,9 +50,9 @@
5050
# "C:/Users/A/tis100/src/sim/alu_tb.v"
5151
# "C:/Users/A/tis100/src/ip/tis100_1.0/src/op_decode.v"
5252
# "C:/Users/A/tis100/src/sim/registers_tb.v"
53-
# "C:/Users/A/tis100/src/sim/instr_rom_tb.v"
53+
# "C:/Users/A/tis100/src/sim/instr_ram_tb.v"
5454
# "C:/Users/A/tis100/src/sim/dir_manager_tb.v"
55-
# "C:/Users/A/tis100/src/ip/tis100_1.0/src/instr_rom.v"
55+
# "C:/Users/A/tis100/src/ip/tis100_1.0/src/instr_ram.v"
5656
# "C:/Users/A/tis100/src/ip/tis100_1.0/src/registers.v"
5757
#
5858
#*****************************************************************************************
@@ -223,9 +223,10 @@ set files [list \
223223
[file normalize "${origin_dir}/src/sim/alu_tb.v"] \
224224
[file normalize "${origin_dir}/src/ip/tis100_1.0/src/op_decode.v"] \
225225
[file normalize "${origin_dir}/src/sim/registers_tb.v"] \
226+
[file normalize "${origin_dir}/src/sim/instr_ram_tb.v"] \
226227
[file normalize "${origin_dir}/src/sim/instr_rom_tb.v"] \
227228
[file normalize "${origin_dir}/src/sim/dir_manager_tb.v"] \
228-
[file normalize "${origin_dir}/src/ip/tis100_1.0/src/instr_rom.v"] \
229+
[file normalize "${origin_dir}/src/ip/tis100_1.0/src/instr_ram.v"] \
229230
[file normalize "${origin_dir}/src/ip/tis100_1.0/src/registers.v"] \
230231
]
231232
add_files -norecurse -fileset $obj $files

scripts/run_tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ source scripts/env.sh
66
# xsim op_decode_tb_behav -key {Behavioral:sim_1:Functional:op_decode_tb} -tclbatch $SCRIPT_PATH/run_tests.tcl -log simulate1.log
77

88
vivado -mode batch -source scripts/run_tests.tcl | tee simulation.log
9-
python scripts/check_sim_logs.py simulation.log 7
9+
python scripts/check_sim_logs.py simulation.log 8

scripts/run_tests.tcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ open_project tis100/tis100.xpr
22

33
set_property -name {xsim.simulate.runtime} -value {100us} -objects [get_filesets sim_1]
44

5-
set test_benches {"alu_tb" "op_decode_tb" "registers_tb" "instr_rom_tb" "dir_manager_tb" "t21_node_tb" "t21_2_node_tb" }
5+
set test_benches {"alu_tb" "op_decode_tb" "registers_tb" "instr_rom_tb" "instr_ram_tb" "dir_manager_tb" "t21_node_tb" "t21_2_node_tb" }
66

77
foreach test_bench $test_benches {
88
set_property top $test_bench [get_filesets sim_1]

src/ip/tis100_1.0/component.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@
13251325
<spirit:fileType>verilogSource</spirit:fileType>
13261326
</spirit:file>
13271327
<spirit:file>
1328-
<spirit:name>src/instr_rom.v</spirit:name>
1328+
<spirit:name>src/instr_ram.v</spirit:name>
13291329
<spirit:fileType>verilogSource</spirit:fileType>
13301330
</spirit:file>
13311331
<spirit:file>
@@ -1374,7 +1374,7 @@
13741374
<spirit:fileType>verilogSource</spirit:fileType>
13751375
</spirit:file>
13761376
<spirit:file>
1377-
<spirit:name>src/instr_rom.v</spirit:name>
1377+
<spirit:name>src/instr_ram.v</spirit:name>
13781378
<spirit:fileType>verilogSource</spirit:fileType>
13791379
</spirit:file>
13801380
<spirit:file>

src/ip/tis100_1.0/src/instr_rom.v renamed to src/ip/tis100_1.0/src/instr_ram.v

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
`timescale 1ns / 1ps
22

3-
// module to read instructions from rom and control program counter jumps
3+
// module to read/write instructions from ram and control program counter jumps
44

5-
module instr_rom(
5+
module instr_ram(
66
// synchronize with posedge of clk
77
input clk,
88
// only update values when clk_en is high
@@ -15,17 +15,26 @@ module instr_rom(
1515
input signed [10:0] acc,
1616
// address to jump to if jump is performed
1717
input signed [10:0] jmp_off,
18+
// controls whether to write a new instruction
19+
input write_en,
20+
// address to write new instruction
21+
input [4:0] write_addr,
22+
// new instruction to write.
23+
//Writes must end with highest address instruction.
24+
input [20:0] write_data,
1825
// instruction at current program counter
1926
output [20:0] opcode
2027
);
2128
`include "my_params.vh"
22-
// memory file to initialize ROM with
29+
// memory file to initialize RAM with
2330
parameter MEM_INIT_FILE = "";
24-
// number of valid instructions in ROM
31+
// number of valid instructions in MEM_INIT_FILE
2532
parameter NUM_ENTRIES = 5'd10;
2633

2734
// memory for storing instructinos
2835
reg [20:0] ram[31:0];
36+
// number of valid instructions in RAM
37+
reg [4:0] num_entries;
2938

3039
// program counter pointing to current instruction
3140
reg [4:0] pc;
@@ -51,6 +60,7 @@ module instr_rom(
5160
initial begin
5261
if (MEM_INIT_FILE != "") begin
5362
$readmemb(MEM_INIT_FILE, ram);
63+
num_entries = NUM_ENTRIES;
5464
end
5565
end
5666

@@ -68,9 +78,9 @@ module instr_rom(
6878
begin
6979
pc <= 0;
7080
end
71-
else if (pc_jmp >= NUM_ENTRIES)
81+
else if (pc_jmp >= num_entries)
7282
begin
73-
pc <= NUM_ENTRIES - 1;
83+
pc <= num_entries - 1;
7484
end
7585
else
7686
begin
@@ -79,7 +89,7 @@ module instr_rom(
7989
end
8090
else
8191
begin
82-
if (pc == NUM_ENTRIES - 1)
92+
if (pc == num_entries - 1)
8393
begin
8494
pc <= 0;
8595
end
@@ -89,6 +99,11 @@ module instr_rom(
8999
end
90100
end
91101
end
102+
if (write_en)
103+
begin
104+
ram[write_addr] <= write_data;
105+
num_entries <= write_addr + 5'd1;
106+
end
92107
end
93108

94109
endmodule

src/ip/tis100_1.0/src/t21_node.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ module t21_node(
8989
op_decode op_decode_0(op_code, src, const, dst, pc_instr, alu_instr, registers_instr, in_mux_sel, out_mux_sel);
9090

9191
alu alu_0(alu_instr, acc_reg, src_input, alu_output);
92-
instr_rom #(MEM_INIT_FILE, NUM_ENTRIES) instr_rom_0(clk, clk_en, reset, pc_instr, acc_reg, src_input, op_code);
92+
instr_ram #(MEM_INIT_FILE, NUM_ENTRIES) instr_ram_0(clk, clk_en, reset, pc_instr, acc_reg, src_input, 1'd0, 5'd0, 21'd0, op_code);
9393
registers registers_0(clk, clk_en, reset, registers_instr, dst_output, acc_reg);
9494

9595
assign src_input = (in_mux_sel == IN_MUX_SEL_CONST) ? const :

src/sim/instr_ram_tb.v

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
`timescale 1ns / 1ps
2+
3+
module instr_ram_tb();
4+
reg clk, reset, clk_en;
5+
reg write_en;
6+
reg [4:0] write_addr;
7+
reg [20:0] write_data;
8+
reg [3:0] op;
9+
reg signed [10:0] acc, jmp_off;
10+
reg [20:0] out_expected;
11+
wire [20:0] out;
12+
reg [31:0] vectornum, errors;
13+
reg [20:0] testinstrs [31:0];
14+
reg [46:0] testvectors [10000:0];
15+
16+
// instantiate device under test
17+
instr_ram dut(clk, clk_en, reset, op, acc, jmp_off, write_en, write_addr, write_data, out);
18+
19+
// generate clock
20+
always
21+
begin
22+
clk = 1; #5; clk = 0; #5;
23+
end
24+
25+
// at start of test, load vectors
26+
// and pulse reset
27+
initial
28+
begin
29+
$readmemb("instr_rom_tv.mem", testvectors);
30+
$readmemb("test_opcodes.mem", testinstrs);
31+
vectornum = 0; errors = 0;
32+
33+
write_en = 0;
34+
#5;
35+
write_addr = 0;
36+
write_en = 1;
37+
38+
for (write_addr=0; testinstrs[write_addr] !== 21'bx; write_addr = write_addr + 5'd1)
39+
begin
40+
write_data = testinstrs[write_addr];
41+
#10;
42+
end
43+
write_en = 0;
44+
45+
clk_en = 0;
46+
reset = 1;
47+
#10; reset = 0;
48+
#12; clk_en = 1;
49+
end
50+
51+
// check results at falling edge of clock
52+
always @ (negedge clk)
53+
begin
54+
if (clk_en) begin
55+
if (out !== out_expected) begin
56+
$display ("Error: input %d", vectornum);
57+
$display (" outputs = %d (%d expected)", out, out_expected);
58+
errors = errors + 1;
59+
end
60+
//$display (" %b %b %b %b %b ", a, b, c, d, yexpected);
61+
vectornum = vectornum + 1;
62+
if (testvectors[vectornum] === 47'bx) begin
63+
$display ("%d tests completed with %d errors", vectornum, errors);
64+
$finish;
65+
end
66+
end
67+
{op, acc, jmp_off, out_expected} = testvectors[vectornum];
68+
end
69+
70+
endmodule

src/sim/instr_rom_tb.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ reg [46:0] testvectors [10000:0];
1111

1212

1313
// instantiate device under test
14-
instr_rom #("test_opcodes.mem", 10) dut(clk, clk_en, reset, op, acc, jmp_off, out);
14+
instr_ram #("test_opcodes.mem", 10) dut(clk, clk_en, reset, op, acc, jmp_off, 1'd0, 5'd0, 21'd0, out);
1515

1616
// generate clock
1717
always

0 commit comments

Comments
 (0)