Skip to content

Commit 6d19da2

Browse files
authored
Merge pull request #6 from olofk/fusesoc
PoC: Add FuseSoC features
2 parents 9b9f47c + 6e5e589 commit 6d19da2

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

TinyFPGA-Bootloader.core

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ filesets:
3636
- tests/top_tb_header.vh : {is_include_file : true}
3737
- tests/top_tb_footer.vh : {is_include_file : true}
3838
file_type : verilogSource
39+
depend : [">=::vlog_tb_utils:1.1"]
3940

4041
address_device_test:
4142
files : [tests/address_device_test/test.v : {file_type : verilogSource}]
@@ -137,6 +138,7 @@ targets:
137138
address_device_test: &tc
138139
default_tool : icarus
139140
filesets : [common, test_common, address_device_test]
141+
parameters : [continue_on_fail]
140142
tools:
141143
modelsim:
142144
vlog_options : [-sv]
@@ -233,3 +235,9 @@ targets:
233235
win10_enumeration_test:
234236
<<: *tc
235237
filesets : [common, test_common, win10_enumeration_test]
238+
239+
parameters:
240+
continue_on_fail:
241+
datatype : bool
242+
description : Continue instead of exit on failed assertions
243+
paramtype : vlogdefine

tests/simple_spi_in_test/test.v

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
`include "top_tb_header.vh"
22
initial begin
3+
4+
//Tap generator needs to know the number of tests beforehand
5+
vtg.set_numtests(3);
6+
7+
/* File name can be set here to have a unique name for each
8+
target. Using this will however not allow run-time settings with
9+
the --tapfile= command-line argument */
10+
11+
//vtg.set_file("simple_spi_in_test.tap");
12+
13+
314
prepare_spi_xfer(
415
/* MOSI */ {8'h81, 8'h00},
516
/* MISO */ {8'h00, 8'h65},
@@ -10,17 +21,35 @@
1021
send_usb_data0({8'h81, 8'h00, 8'h01, 8'h00, 8'h01, 8'h01}, 6 * 8);
1122
expect_usb_ack();
1223

24+
/* We will only reach here if not the assert inside
25+
expect_usb_ack triggered. This means that successful runs will
26+
list all three ok lines in the tap file, while failed ones will
27+
only display as many lines as we have reached.
28+
29+
As an alternative, we could let expect_usb_ack and friends set
30+
an error signal instead of exit and use
31+
vtg.write_tc("6 bytes sent and acknowledged", !error); to
32+
continue running after a failed subtest. Of course, this only
33+
makes sense if there is a point to keep running after one subtest
34+
failed */
35+
36+
//Arbitrary chosen string as I don't really know what you test :)
37+
vtg.ok("6 bytes sent and acknowledged");
38+
1339
#10000000;
1440

1541
send_usb_in(0, 1);
1642
expect_usb_data0({8'h65}, 8);
1743
send_usb_ack();
1844

45+
vtg.ok("1 bytes sent and acknowledged");
46+
1947
#10000000;
2048

2149
send_usb_in(0, 1);
2250
expect_usb_nak();
2351

52+
vtg.ok("Received nak");
2453
$finish(0);
2554
end
2655
`include "top_tb_footer.vh"

tests/top_tb_header.vh

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
`timescale 1ps / 1ps
22

3-
`ifdef __ICARUS__
4-
`define finish_and_return(code) $finish_and_return(code)
3+
`ifdef continue_on_fail
4+
`define finish_and_return(code) #0
55
`else
6-
`define finish_and_return(code) $finish
6+
`ifdef __ICARUS__
7+
`define finish_and_return(code) $finish_and_return(code)
8+
`else
9+
`define finish_and_return(code) $finish
10+
`endif
711
`endif
812

913
`define assert(msg, signal, value) \
@@ -19,10 +23,23 @@
1923
end
2024

2125
module top_tb;
22-
initial begin
23-
$dumpfile("test.vcd");
24-
$dumpvars(0, dut);
25-
end
26+
/* By instantiating vlog_tb_utils we get access to some
27+
extra functionality that can be activated by plusargs at
28+
runtime.
29+
fusesoc run --target=simple_spi_in_test TinyFPGA-Bootloader --help
30+
will list all available options. Refer to this for details
31+
*/
32+
vlog_tb_utils vtu();
33+
34+
/* Set a default name for the tap file.
35+
Doesn't necessarily have to be unique as each target
36+
executes in a separate work directory
37+
Filename specified here can be overridden with the
38+
vtg.set_file("filename") function at compile-time
39+
or with a plusarg at run time by adding --tapfile=filename
40+
to the FuseSoC command line
41+
*/
42+
vlog_tap_generator #("test.tap") vtg();
2643

2744
reg clk_48mhz;
2845
reg reset = 0;

0 commit comments

Comments
 (0)