Skip to content

Commit af6e1ea

Browse files
committed
iverilog: Towards iverilog support
1 parent 8636d52 commit af6e1ea

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

iverilog/test.v

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2025 ETH Zurich and University of Bologna.
2+
// Solderpad Hardware License, Version 0.51, see LICENSE for details.
3+
// SPDX-License-Identifier: SHL-0.51
4+
//
5+
// Authors:
6+
// - Thomas Benz <tbenz@iis.ee.ethz.ch>
7+
8+
`timescale 1ns/1ns
9+
module fbtb_croc_soc();
10+
11+
localparam time Period = 100ns;
12+
localparam time PeriodHalf = Period / 2;
13+
localparam time TAppl = 20ns;
14+
localparam time TTest = 80ns;
15+
16+
int fd = 0;
17+
int sim_time = 0;
18+
int ret = 0;
19+
string line;
20+
logic clk_sample = 0;
21+
22+
// chip signals from file
23+
logic clk_i;
24+
logic rst_ni;
25+
logic ref_clk_i;
26+
logic testmode_i;
27+
logic fetch_en_i;
28+
logic status_o, status_to;
29+
logic jtag_tck_i;
30+
logic jtag_tdi_i;
31+
logic jtag_tdo_o, jtag_tdo_to;
32+
logic jtag_tms_i;
33+
logic jtag_trst_ni;
34+
logic uart_rx_i;
35+
logic uart_tx_o, uart_tx_to;
36+
logic [15:0] gpio_i;
37+
logic [15:0] gpio_o, gpio_to;
38+
logic [15:0] gpio_out_en_o, gpio_out_en_to;
39+
40+
initial begin
41+
forever begin
42+
clk_sample = !clk_sample;
43+
#PeriodHalf;
44+
end
45+
end
46+
47+
initial begin
48+
fd = $fopen("../vsim/stimuli.txt", "r");
49+
while (!$feof(fd)) begin
50+
// fetch line
51+
ret = $fgets(line, fd);
52+
// parse line, apply data to chip
53+
#TAppl;
54+
ret = $fscanf(fd, "%010d.%01b%01b%01b%01b%01b%01b%01b%01b%01b%01b%16b.%01b%01b%01b%16b%16b",
55+
sim_time,
56+
clk_i,
57+
rst_ni,
58+
ref_clk_i,
59+
testmode_i,
60+
fetch_en_i,
61+
jtag_tck_i,
62+
jtag_tdi_i,
63+
jtag_tms_i,
64+
jtag_trst_ni,
65+
uart_rx_i,
66+
gpio_i,
67+
status_to,
68+
jtag_tdo_to,
69+
uart_tx_to,
70+
gpio_to,
71+
gpio_out_en_to
72+
);
73+
// test outputs
74+
#(TTest - TAppl);
75+
if (status_o !== status_to )$warning("Output mismatch status_o (%01b instead of %01b) at: %010d", status_o, status_to, sim_time);
76+
if (jtag_tdo_o !== jtag_tdo_to )$warning("Output mismatch jtag_tdo_o (%01b instead of %01b) at: %010d", jtag_tdo_o, jtag_tdo_to, sim_time);
77+
if (uart_tx_o !== uart_tx_to )$warning("Output mismatch uart_tx_o (%01b instead of %01b) at: %010d", uart_tx_o, uart_tx_to, sim_time);
78+
if (gpio_o !== gpio_to )$warning("Output mismatch gpio_o (%01b instead of %01b) at: %010d", gpio_o, gpio_to, sim_time);
79+
if (gpio_out_en_o !== gpio_out_en_to)$warning("Output mismatch gpio_out_en_o (%01b instead of %01b) at: %010d", gpio_out_en_o, gpio_out_en_to, sim_time);
80+
// next sample
81+
@(posedge clk_sample);
82+
end
83+
$finish;
84+
$fclose(fd);
85+
end
86+
endmodule

rtl/tb_croc_soc.sv

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,47 @@ module tb_croc_soc #(
399399
assign gpio_i[ 3:0] = '0;
400400
assign gpio_i[ 7:4] = gpio_out_en_o[3:0] & gpio_o[3:0];
401401

402+
int fd = 0;
403+
initial begin
404+
int i = 0;
405+
fd = $fopen ("stimuli.txt", "w");
406+
forever begin
407+
// wait one delta cycle
408+
#0;
409+
// write time
410+
$fwrite(fd, "%010d", $time);
411+
$fwrite(fd, ".");
412+
// write stimuli
413+
#TAppl;
414+
$fwrite(fd, "%01b%01b%01b%01b%01b%01b%01b%01b%01b%01b%16b",
415+
i_croc_soc.clk_i,
416+
i_croc_soc.rst_ni,
417+
i_croc_soc.ref_clk_i,
418+
i_croc_soc.testmode_i,
419+
i_croc_soc.fetch_en_i,
420+
i_croc_soc.jtag_tck_i,
421+
i_croc_soc.jtag_tdi_i,
422+
i_croc_soc.jtag_tms_i,
423+
i_croc_soc.jtag_trst_ni,
424+
i_croc_soc.uart_rx_i,
425+
i_croc_soc.gpio_i
426+
);
427+
$fwrite(fd, ".");
428+
// write responses
429+
#(TTest-TAppl);
430+
$fwrite(fd, "%01b%01b%01b%16b%16b",
431+
i_croc_soc.status_o,
432+
i_croc_soc.jtag_tdo_o,
433+
i_croc_soc.uart_tx_o,
434+
i_croc_soc.gpio_o,
435+
i_croc_soc.gpio_out_en_o
436+
);
437+
// wait for next clock
438+
$fwrite(fd, "\n");
439+
@(posedge clk);
440+
end
441+
end
442+
402443

403444
/////////////////
404445
// Testbench //

vsim/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ transcript
55
vsim.wlf
66
modelsim.ini
77
*.vcd
8+
stimuli.txt

0 commit comments

Comments
 (0)