2006-08-26 13:35:28 +02:00
// DESCRIPTION: Verilator: Verilog Test module
//
// Use this file as a template for submitting bugs, etc.
// This module takes a single clock input, and should either
2019-06-13 04:41:51 +02:00
// $write("*-* All Finished *-*\n");
// $finish;
2006-08-26 13:35:28 +02:00
// on success, or $stop.
//
2007-03-05 14:52:21 +01:00
// The code as shown applies a random vector to the Test
// module, then calculates a CRC on the Test module's outputs.
//
2006-08-26 13:35:28 +02:00
// **If you do not wish for your code to be released to the public
2007-03-05 14:52:21 +01:00
// please note it here, otherwise:**
//
2020-03-21 16:24:24 +01:00
// This file ONLY is placed under the Creative Commons Public Domain, for
2025-01-02 12:21:30 +01:00
// any use, without warranty, 2025 by Wilson Snyder.
2020-03-21 16:24:24 +01:00
// SPDX-License-Identifier: CC0-1.0
2006-08-26 13:35:28 +02:00
2024-11-27 04:27:32 +01:00
`define stop $stop
2025-01-05 23:10:04 +01:00
`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0x exp=%0x (%s !== %s)\n", `__FILE__,`__LINE__, (gotv), (expv), `"gotv`", `"expv`"); `stop; end while(0);
`define checks(gotv,expv) do if ((gotv) != (expv)) begin $write("%%Error: %s:%0d: got='%s' exp='%s'\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
2024-11-27 04:27:32 +01:00
2020-05-08 13:35:54 +02:00
module t ( /*AUTOARG*/
// Inputs
clk
) ;
input clk ;
2025-05-01 04:00:06 +02:00
int cyc ;
2020-05-08 13:35:54 +02:00
reg [ 63 : 0 ] crc ;
reg [ 63 : 0 ] sum ;
// Take CRC data and apply to testblock inputs
wire [ 31 : 0 ] in = crc [ 31 : 0 ] ;
/*AUTOWIRE*/
// Beginning of automatic wires (for undeclared instantiated-module outputs)
wire [ 31 : 0 ] out ; // From test of Test.v
// End of automatics
Test test ( /*AUTOINST*/
// Outputs
. out ( out [ 31 : 0 ] ) ,
// Inputs
. clk ( clk ) ,
. in ( in [ 31 : 0 ] ) ) ;
// Aggregate outputs into a single result vector
wire [ 63 : 0 ] result = { 32 'h0 , out } ;
// Test loop
2024-09-25 04:15:18 +02:00
always @ ( posedge clk ) begin
2020-05-08 13:35:54 +02:00
`ifdef TEST_VERBOSE
2021-11-13 16:46:25 +01:00
$write ( " [%0t] cyc==%0d crc=%x result=%x \n " , $time , cyc , crc , result ) ;
2020-05-08 13:35:54 +02:00
`endif
cyc < = cyc + 1 ;
2021-11-13 16:46:25 +01:00
crc < = { crc [ 62 : 0 ] , crc [ 63 ] ^ crc [ 2 ] ^ crc [ 0 ] } ;
sum < = result ^ { sum [ 62 : 0 ] , sum [ 63 ] ^ sum [ 2 ] ^ sum [ 0 ] } ;
2020-05-08 13:35:54 +02:00
if ( cyc = = 0 ) begin
// Setup
crc < = 64 'h5aef0c8d _d70a4497 ;
sum < = '0 ;
end
else if ( cyc < 10 ) begin
sum < = '0 ;
end
else if ( cyc < 90 ) begin
end
else if ( cyc = = 99 ) begin
2021-11-13 16:46:25 +01:00
$write ( " [%0t] cyc==%0d crc=%x sum=%x \n " , $time , cyc , crc , sum ) ;
2024-11-27 04:27:32 +01:00
`checkh ( crc , 64 'hc77bb9b3784ea091 ) ;
2020-05-08 13:35:54 +02:00
// What checksum will we end up with (above print should match)
2024-11-27 04:27:32 +01:00
`checkh ( sum , 64 'h4afe43fb79d7b71e ) ;
2020-05-08 13:35:54 +02:00
$write ( " *-* All Finished *-* \n " ) ;
$finish ;
end
2007-03-05 14:52:21 +01:00
end
endmodule
2020-05-08 13:35:54 +02:00
module Test ( /*AUTOARG*/
// Outputs
out ,
// Inputs
clk , in
) ;
// Replace this module with the device under test.
//
// Change the code in the t module to apply values to the inputs and
// merge the output values into the result vector.
input clk ;
input [ 31 : 0 ] in ;
output reg [ 31 : 0 ] out ;
always @ ( posedge clk ) begin
out < = in ;
end
endmodule