From 09c3d9b58e018fea3dd0b2bcc95c249815c32542 Mon Sep 17 00:00:00 2001 From: Daniel Jobson Date: Thu, 21 Nov 2024 14:21:36 +0100 Subject: [PATCH 1/5] tb: Make tb_tk1.v selftesting - Exit with the right error code --- hw/application_fpga/core/tk1/tb/tb_tk1.v | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/hw/application_fpga/core/tk1/tb/tb_tk1.v b/hw/application_fpga/core/tk1/tb/tb_tk1.v index 640a7144..23448499 100644 --- a/hw/application_fpga/core/tk1/tb/tb_tk1.v +++ b/hw/application_fpga/core/tk1/tb/tb_tk1.v @@ -714,6 +714,22 @@ module tb_tk1 (); end endtask // test10 + //---------------------------------------------------------------- + // exit_with_error_code() + // + // Exit with the right error code + //---------------------------------------------------------------- + task exit_with_error_code; + begin + if (error_ctr == 0) begin + $finish(0); + end + else begin + $fatal(1); + end + end + endtask // exit_with_error_code + //---------------------------------------------------------------- // tk1_test @@ -744,7 +760,7 @@ module tb_tk1 (); $display(" -= Testbench for tk1 completed =-"); $display(" ============================="); $display(""); - $finish; + exit_with_error_code(); end // tk1_test endmodule // tb_tk1 From c547042553867b7d89f7472480081e518a28b29a Mon Sep 17 00:00:00 2001 From: Daniel Jobson Date: Thu, 21 Nov 2024 15:07:27 +0100 Subject: [PATCH 2/5] tb: Make tb_tk1_spi_master.v selftesting - Compare against expected value - Exit with the correct error code --- .../core/tk1/tb/tb_tk1_spi_master.v | 73 ++++++++++++++++++- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/hw/application_fpga/core/tk1/tb/tb_tk1_spi_master.v b/hw/application_fpga/core/tk1/tb/tb_tk1_spi_master.v index b94f03ab..6eced69e 100644 --- a/hw/application_fpga/core/tk1/tb/tb_tk1_spi_master.v +++ b/hw/application_fpga/core/tk1/tb/tb_tk1_spi_master.v @@ -395,6 +395,21 @@ module tb_tk1_spi_master (); end endtask // read_status + //---------------------------------------------------------------- + // check_byte() + // + // The function checks that the input_data byte matches with the expected. + //---------------------------------------------------------------- + task check_byte(input [7 : 0] input_data, input [7 : 0] expected); + begin : check_byte + if (input_data != expected) begin + $display("--- Error: Got 0x%02x, expected 0x%02x", input_data, expected); + error_ctr = error_ctr + 1; + end + end + endtask // check_byte + + //---------------------------------------------------------------- // tc_get_device_id() @@ -474,10 +489,15 @@ module tb_tk1_spi_master (); // Send dummy bytes and get response back. xfer_byte(8'h00, rx_byte); $display("--- tc_get_jedec_id: Got manufacture ID 0x%02x", rx_byte); + check_byte(rx_byte, 8'hef); + xfer_byte(8'h00, rx_byte); $display("--- tc_get_jedec_id: Got memory type 0x%02x", rx_byte); + check_byte(rx_byte, 8'h40); + xfer_byte(8'h00, rx_byte); $display("--- tc_get_jedec_id: Got memory capacity 0x%02x", rx_byte); + check_byte(rx_byte, 8'h14); disable_spi(); #(2 * CLK_PERIOD); @@ -498,12 +518,22 @@ module tb_tk1_spi_master (); //---------------------------------------------------------------- task tc_get_unique_device_id; begin : tc_get_id + reg [7 : 0] expected[0 : 7]; reg [7 : 0] rx_byte; integer i; - tc_ctr = tc_ctr + 1; + tc_ctr = tc_ctr + 1; monitor = 0; verbose = 0; + expected[0] = 8'hdc; + expected[1] = 8'h02; + expected[2] = 8'h03; + expected[3] = 8'h04; + expected[4] = 8'h05; + expected[5] = 8'h06; + expected[6] = 8'h07; + expected[7] = 8'h08; + $display(""); $display("--- tc_get_unique_device_id: Read out unique id from the memory"); $display("--- tc_get_unique_device_id: Expected result: 0xdc02030405060708"); @@ -527,6 +557,7 @@ module tb_tk1_spi_master (); for (i = 0; i < 8; i = i + 1) begin xfer_byte(8'h00, rx_byte); $display("--- tc_get_unique_device_id: 0x%02x", rx_byte); + check_byte(rx_byte, expected[i]); end disable_spi(); @@ -592,12 +623,30 @@ module tb_tk1_spi_master (); //---------------------------------------------------------------- task tc_read_mem; begin : tc_get_id + reg [7 : 0] expected[0 : 15]; reg [7 : 0] rx_byte; integer i; - tc_ctr = tc_ctr + 1; + tc_ctr = tc_ctr + 1; monitor = 0; verbose = 0; + expected[0] = 8'hde; + expected[1] = 8'had; + expected[2] = 8'hbe; + expected[3] = 8'hef; + expected[4] = 8'hde; + expected[5] = 8'had; + expected[6] = 8'hbe; + expected[7] = 8'hef; + expected[8] = 8'hde; + expected[9] = 8'had; + expected[10] = 8'hbe; + expected[11] = 8'hef; + expected[12] = 8'hde; + expected[13] = 8'had; + expected[14] = 8'hbe; + expected[15] = 8'hef; + $display(""); $display("--- tc_read_mem: Read out the first 16 bytes from the memory."); @@ -609,7 +658,7 @@ module tb_tk1_spi_master (); $display("--- tc_read_mem: Sending 0x03 command."); xfer_byte(8'h03, rx_byte); - // Send adress 0x000000. + // Send address 0x000000. $display("--- tc_read_mem: Sending 24 bit address 0x000000."); xfer_byte(8'h00, rx_byte); xfer_byte(8'h00, rx_byte); @@ -620,6 +669,7 @@ module tb_tk1_spi_master (); for (i = 1; i < 17; i = i + 1) begin xfer_byte(8'h00, rx_byte); $display("--- tc_read_mem: Byte %d: 0x%02x", i, rx_byte); + check_byte(rx_byte, expected[i-1]); end disable_spi(); @@ -684,6 +734,21 @@ module tb_tk1_spi_master (); end endtask // tc_rmr_mem + //---------------------------------------------------------------- + // exit_with_error_code() + // + // Exit with the right error code + //---------------------------------------------------------------- + task exit_with_error_code; + begin + if (error_ctr == 0) begin + $finish(0); + end + else begin + $fatal(1); + end + end + endtask // exit_with_error_code //---------------------------------------------------------------- // tk1_spi_master_test @@ -712,7 +777,7 @@ module tb_tk1_spi_master (); $display(" -= Testbench for tk1_spi_master completed =-"); $display(" ========================================="); $display(""); - $finish; + exit_with_error_code(); end // tk1_spi_master_test endmodule // tb_tk1_spi_master From ac853c87ecd66650da2f6ccbe789b24ddbf89d83 Mon Sep 17 00:00:00 2001 From: Daniel Jobson Date: Thu, 21 Nov 2024 15:23:39 +0100 Subject: [PATCH 3/5] tb: Make touch_sense selftesting - Check for expected word - Exit with the right error code --- .../core/touch_sense/tb/tb_touch_sense.v | 66 +++++++++++++++++-- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/hw/application_fpga/core/touch_sense/tb/tb_touch_sense.v b/hw/application_fpga/core/touch_sense/tb/tb_touch_sense.v index df023732..ad8e4ed9 100644 --- a/hw/application_fpga/core/touch_sense/tb/tb_touch_sense.v +++ b/hw/application_fpga/core/touch_sense/tb/tb_touch_sense.v @@ -206,6 +206,43 @@ module tb_touch_sense (); endtask // read_word + //---------------------------------------------------------------- + // read_check_word() + // + // Read a data word from the given address in the DUT. + // the word read will be available in the global variable + // read_data. + // + // The function also checks that the data read matches + // the expected value or not. + //---------------------------------------------------------------- + task read_check_word(input [7 : 0] address, input [31 : 0] expected); + begin : read_check_word + + tb_address = address; + tb_cs = 1'h1; + + #(CLK_PERIOD); + read_data = tb_read_data; + + #(CLK_PERIOD); + tb_cs = 1'h0; + + if (DEBUG) begin + if (read_data == expected) begin + $display("--- Reading 0x%08x from 0x%02x.", read_data, address); + end + else begin + $display("--- Error: Got 0x%08x when reading from 0x%02x, expected 0x%08x", read_data, + address, expected); + error_ctr = error_ctr + 1; + end + $display(""); + end + end + endtask // read_check_word + + //---------------------------------------------------------------- // wait_ready() // @@ -242,7 +279,7 @@ module tb_touch_sense (); // Check status. #(CLK_PERIOD); - read_word(8'h09); + read_check_word(ADDR_STATUS, 32'h00); // Set touch event input to high. $display("--- test1: Creating a touch event."); @@ -250,21 +287,21 @@ module tb_touch_sense (); $display("--- test1: Waiting for the event to be caught."); wait_ready(); + read_check_word(ADDR_STATUS, 32'h01); $display("--- test1: Event has been seen."); - $display("--- test1: Dropping the event input."); tb_touch_event = 1'h0; #(CLK_PERIOD); $display("--- test1: Clearing the event."); - write_word(8'h09, 32'h0); + write_word(ADDR_STATUS, 32'h0); #(CLK_PERIOD); // Check that the event is now removed. - read_word(8'h09); + read_check_word(ADDR_STATUS, 32'h00); #(CLK_PERIOD); $display("--- test1: Event has been cleared."); - read_word(8'h09); + read_check_word(ADDR_STATUS, 32'h00); #(CLK_PERIOD); $display("--- test1: completed."); @@ -273,6 +310,23 @@ module tb_touch_sense (); endtask // test1 + //---------------------------------------------------------------- + // exit_with_error_code() + // + // Exit with the right error code + //---------------------------------------------------------------- + task exit_with_error_code; + begin + if (error_ctr == 0) begin + $finish(0); + end + else begin + $fatal(1); + end + end + endtask // exit_with_error_code + + //---------------------------------------------------------------- // touch_sense_test //---------------------------------------------------------------- @@ -292,7 +346,7 @@ module tb_touch_sense (); $display(" -= Testbench for touch_sense completed =-"); $display(" ======================================"); $display(""); - $finish; + exit_with_error_code(); end // touch_sense_test endmodule // tb_touch_sense From c637c745cccd80ae8b634d413166cf766d974a4e Mon Sep 17 00:00:00 2001 From: Daniel Jobson Date: Thu, 21 Nov 2024 15:28:20 +0100 Subject: [PATCH 4/5] tb: Make trng selftesting - Exit with the right error code --- hw/application_fpga/core/trng/tb/tb_trng.v | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/hw/application_fpga/core/trng/tb/tb_trng.v b/hw/application_fpga/core/trng/tb/tb_trng.v index 8c7f6d47..82292f1a 100644 --- a/hw/application_fpga/core/trng/tb/tb_trng.v +++ b/hw/application_fpga/core/trng/tb/tb_trng.v @@ -177,7 +177,7 @@ module tb_trng (); // the word read will be available in the global variable // read_data. //---------------------------------------------------------------- - task read_word(input [ 7 : 0] address, input [31 : 0] expected); + task read_word(input [7 : 0] address, input [31 : 0] expected); begin : read_word reg [31 : 0] read_data; @@ -221,6 +221,22 @@ module tb_trng (); end endtask // test1 + //---------------------------------------------------------------- + // exit_with_error_code() + // + // Exit with the right error code + //---------------------------------------------------------------- + task exit_with_error_code; + begin + if (error_ctr == 0) begin + $finish(0); + end + else begin + $fatal(1); + end + end + endtask // exit_with_error_code + //---------------------------------------------------------------- // trng_test @@ -240,7 +256,7 @@ module tb_trng (); $display(" -= Testbench for trng completed =-"); $display(" =============================="); $display(""); - $finish; + exit_with_error_code(); end // trng_test endmodule // tb_trng From 66888a3756ac3587b7d35e222d1da7f50045df69 Mon Sep 17 00:00:00 2001 From: Daniel Jobson Date: Thu, 21 Nov 2024 15:32:26 +0100 Subject: [PATCH 5/5] tb: Make uart selftesting - Exit with the right exit code --- hw/application_fpga/core/uart/tb/tb_uart.v | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/hw/application_fpga/core/uart/tb/tb_uart.v b/hw/application_fpga/core/uart/tb/tb_uart.v index 0019ff5d..4d67656e 100644 --- a/hw/application_fpga/core/uart/tb/tb_uart.v +++ b/hw/application_fpga/core/uart/tb/tb_uart.v @@ -324,6 +324,23 @@ module tb_uart (); endtask // display_test_result + //---------------------------------------------------------------- + // exit_with_error_code() + // + // Exit with the right error code + //---------------------------------------------------------------- + task exit_with_error_code; + begin + if (error_ctr == 0) begin + $finish(0); + end + else begin + $fatal(1); + end + end + endtask // exit_with_error_code + + //---------------------------------------------------------------- // uart_test // The main test functionality. @@ -340,7 +357,7 @@ module tb_uart (); display_test_result(); $display("*** Simulation done."); - $finish; + exit_with_error_code(); end // uart_test endmodule // tb_uart