mirror of
https://github.com/pConst/basic_verilog.git
synced 2025-01-14 06:42:54 +08:00
Updated testbench template project
This commit is contained in:
parent
8f32dd53d9
commit
783c33e268
@ -1,48 +0,0 @@
|
||||
// Copyright 2007 Altera Corporation. All rights reserved.
|
||||
// Altera products are protected under numerous U.S. and foreign patents,
|
||||
// maskwork rights, copyrights and other intellectual property laws.
|
||||
//
|
||||
// This reference design file, and your use thereof, is subject to and governed
|
||||
// by the terms and conditions of the applicable Altera Reference Design
|
||||
// License Agreement (either as signed by you or found at www.altera.com). By
|
||||
// using this reference design file, you indicate your acceptance of such terms
|
||||
// and conditions between you and Altera Corporation. In the event that you do
|
||||
// not agree with such terms and conditions, you may not use the reference
|
||||
// design file and please promptly destroy any copies you have made.
|
||||
//
|
||||
// This reference design file is being provided on an "as-is" basis and as an
|
||||
// accommodation and therefore all warranties, representations or guarantees of
|
||||
// any kind (whether express, implied or statutory) including, without
|
||||
// limitation, warranties of merchantability, non-infringement, or fitness for
|
||||
// a particular purpose, are specifically disclaimed. By making this reference
|
||||
// design file available, Altera expressly does not recommend, suggest or
|
||||
// require that this reference design file be used in combination with any
|
||||
// other product not provided by Altera.
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// C runtime library random number generator
|
||||
//
|
||||
// uses 32 logic cells for DFF/ADD and 8 DSP blocks for the
|
||||
// 32x18=>32 multiply
|
||||
|
||||
module c_rand (clk,rst,reseed,seed_val,out);
|
||||
input clk,rst,reseed;
|
||||
input [31:0] seed_val;
|
||||
output [15:0] out;
|
||||
wire [15:0] out;
|
||||
|
||||
reg [31:0] state;
|
||||
|
||||
always @(posedge clk or posedge rst) begin
|
||||
if (rst) state <= 0;
|
||||
else begin
|
||||
if (reseed) state <= seed_val;
|
||||
else begin
|
||||
state <= state * 32'h343fd + 32'h269EC3;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assign out = (state >> 16) & 16'h7fff;
|
||||
|
||||
endmodule
|
@ -17,18 +17,17 @@
|
||||
set library_file_list {
|
||||
|
||||
work {main_tb.sv
|
||||
# main.sv
|
||||
c_rand.v
|
||||
main.sv
|
||||
clk_divider.sv
|
||||
edge_detect.sv
|
||||
delay.sv
|
||||
clk_divider.sv}
|
||||
delay.sv}
|
||||
}
|
||||
|
||||
set vsim_params "-L altera_mf_ver -L altera_mf -L lpm_ver -L lpm"
|
||||
|
||||
set top_level work.main_tb
|
||||
|
||||
set suppress_err_list ""
|
||||
set suppress_err_list 0
|
||||
|
||||
# Console commands:
|
||||
# r = Recompile changed and dependent files
|
||||
|
@ -60,42 +60,34 @@ end
|
||||
logic nrst_once;
|
||||
assign nrst_once = ~rst_once;
|
||||
|
||||
logic [31:0] DerivedClocks;
|
||||
logic [31:0] clk200_div;
|
||||
clk_divider #(
|
||||
.WIDTH( 32 )
|
||||
) cd1 (
|
||||
.clk( clk200 ),
|
||||
.nrst( nrst_once ),
|
||||
.ena( 1'b1 ),
|
||||
.out( DerivedClocks[31:0] )
|
||||
.out( clk200_div[31:0] )
|
||||
);
|
||||
|
||||
logic [31:0] E_DerivedClocks;
|
||||
logic [31:0] clk200_div_rise;
|
||||
edge_detect ed1[31:0] (
|
||||
.clk( {32{clk200}} ),
|
||||
.anrst( {32{nrst_once}} ),
|
||||
.in( DerivedClocks[31:0] ),
|
||||
.rising( E_DerivedClocks[31:0] ),
|
||||
.in( clk200_div[31:0] ),
|
||||
.rising( clk200_div_rise[31:0] ),
|
||||
.falling( ),
|
||||
.both( )
|
||||
);
|
||||
|
||||
logic [31:0] RandomNumber1;
|
||||
c_rand rng1 (
|
||||
.clk( clk200 ),
|
||||
.rst( 1'b0 ),
|
||||
.reseed( rst_once ),
|
||||
.seed_val( DerivedClocks[31:0] ^ (DerivedClocks[31:0] << 1) ),
|
||||
.out( RandomNumber1[15:0] )
|
||||
);
|
||||
|
||||
c_rand rng2 (
|
||||
.clk( clk200 ),
|
||||
.rst( 1'b0 ),
|
||||
.reseed( rst_once ),
|
||||
.seed_val( DerivedClocks[31:0] ^ (DerivedClocks[31:0] << 2) ),
|
||||
.out( RandomNumber1[31:16] )
|
||||
);
|
||||
logic [31:0] rnd_data;
|
||||
always_ff @(posedge clk200) begin
|
||||
if( ~nrst_once ) begin
|
||||
rnd_data[31:0] <= $random( 1 ); // seeding
|
||||
end else begin
|
||||
rnd_data[31:0] <= $random;
|
||||
end
|
||||
end
|
||||
|
||||
logic start;
|
||||
initial begin
|
||||
@ -104,7 +96,11 @@ initial begin
|
||||
#20 start = 1'b0;
|
||||
end
|
||||
|
||||
// Module under test ==========================================================
|
||||
//initial begin
|
||||
// #1000 $finish;
|
||||
//end
|
||||
|
||||
// Module under test ===========================================================
|
||||
|
||||
logic [15:0] seq_cntr = '0;
|
||||
|
||||
@ -121,7 +117,7 @@ always_ff @(posedge clk200) begin
|
||||
|
||||
if( seq_cntr[15:0]<300 ) begin
|
||||
id[31:0] <= '1;
|
||||
//id[31:0] <= {4{RandomNumber1[15:0]}};
|
||||
//id[31:0] <= {4{rnd_data[15:0]}};
|
||||
end else begin
|
||||
id[31:0] <= '0;
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user