2021-12-31 20:17:16 +00:00
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2021 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
`define stop $stop
`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0)
2024-02-08 23:39:13 +00:00
`define checkr(gotv,expv) do if ((gotv) != (expv)) begin $write("%%Error: %s:%0d: got=%f exp=%f\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
2021-12-31 20:17:16 +00:00
module t ( /*AUTOARG*/
// Inputs
clk
) ;
input clk ;
integer cyc = 0 ;
reg [ 3 : 0 ] in ;
tri [ 3 : 0 ] bus = in ;
int never_driven ;
int never_forced ;
2023-02-05 01:37:36 +00:00
real r ;
2021-12-31 20:17:16 +00:00
task force_bus ;
force bus [ 1 : 0 ] = 2 'b10 ;
endtask
task release_bus ;
release bus ;
endtask
// Test loop
always @ ( posedge clk ) begin
cyc < = cyc + 1 ;
if ( cyc = = 0 ) begin
in < = 4 'b0101 ;
end
else if ( cyc = = 1 ) begin
`checkh ( in , 4 'b0101 ) ;
end
// Check forces with no driver
if ( cyc = = 1 ) begin
force never_driven = 32 'h888 ;
end
else if ( cyc = = 2 ) begin
`checkh ( never_driven , 32 'h888 ) ;
end
2022-12-13 02:32:45 +00:00
//
2021-12-31 20:17:16 +00:00
// Check release with no force
else if ( cyc = = 10 ) begin
never_forced < = 5432 ;
end
else if ( cyc = = 11 ) begin
`checkh ( never_forced , 5432 ) ;
end
else if ( cyc = = 12 ) begin
release never_forced ; // no-op
end
else if ( cyc = = 13 ) begin
`checkh ( never_forced , 5432 ) ;
end
//
// bus
2022-12-13 02:32:45 +00:00
else if ( cyc = = 20 ) begin
2021-12-31 20:17:16 +00:00
`checkh ( bus , 4 'b0101 ) ;
force bus = 4 'b0111 ;
end
2022-12-13 02:32:45 +00:00
else if ( cyc = = 21 ) begin
2021-12-31 20:17:16 +00:00
`checkh ( bus , 4 'b0111 ) ;
force bus = 4 'b1111 ;
end
2022-12-13 02:32:45 +00:00
else if ( cyc = = 22 ) begin
2021-12-31 20:17:16 +00:00
`checkh ( bus , 4 'b1111 ) ;
release bus ;
end
2022-12-13 02:32:45 +00:00
else if ( cyc = = 23 ) begin
2021-12-31 20:17:16 +00:00
`checkh ( bus , 4 'b0101 ) ;
end
2022-12-13 02:32:45 +00:00
//
else if ( cyc = = 30 ) begin
2021-12-31 20:17:16 +00:00
force_bus ( ) ;
end
2022-12-13 02:32:45 +00:00
else if ( cyc = = 31 ) begin
2021-12-31 20:17:16 +00:00
`checkh ( bus , 4 'b0110 ) ;
end
2022-12-13 02:32:45 +00:00
else if ( cyc = = 32 ) begin
2021-12-31 20:17:16 +00:00
release bus [ 0 ] ;
end
2022-12-13 02:32:45 +00:00
else if ( cyc = = 33 ) begin
2021-12-31 20:17:16 +00:00
`checkh ( bus , 4 'b0111 ) ;
release_bus ( ) ;
end
2022-12-13 02:32:45 +00:00
else if ( cyc = = 34 ) begin
2021-12-31 20:17:16 +00:00
`checkh ( in , 4 'b0101 ) ;
`checkh ( bus , 4 'b0101 ) ;
end
//
2023-02-05 01:37:36 +00:00
else if ( cyc = = 40 ) begin
r < = 1.25 ;
end
else if ( cyc = = 41 ) begin
`checkr ( r , 1.25 ) ;
end
else if ( cyc = = 42 ) begin
force r = 2.5 ;
end
else if ( cyc = = 43 ) begin
`checkr ( r , 2.5 ) ;
end
else if ( cyc = = 44 ) begin
release r ;
end
else if ( cyc = = 45 ) begin
`checkr ( r , 1.25 ) ;
end
//
2021-12-31 20:17:16 +00:00
else if ( cyc = = 99 ) begin
$write ( " *-* All Finished *-* \n " ) ;
$finish ;
end
end
endmodule