SV随机约束使用方法---测试例子说明
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
SV随机约束使⽤⽅法---测试例⼦说明// ********************************************************
// Copyright(c) 2018
// Author : gujiangtao
// File name : random_gen.v
// Module name : random_gen
// Created Time : 2018/8/14 20:25
// Last Modified : ---
// Abstract:
// ========================================================
// Revision Date Author Comment
// -------- --------- --------- ---------
// 1.0 2018/08/14 gujiangtao
//
// ********************************************************
`include "parameter.vh"
class Random_id;
rand bit[9:0] destxr;
rand bit[9:0] destyr;
rand bit[7:0] startr;
rand bit signed [7:0] noiser;
constraint start_N {startr<`per_cyc ;noiser<(`noise_per); noiser>-(`noise_per); }
function new(int seed);
this.srandom(seed);
endfunction
endclass//endclass*/
module random_gen
#(
parameter per_cyc = 10,
parameter x_cord_width_p = "inv",
parameter y_cord_width_p = "inv"
)(
input clk_i,
input reset_i,
input [x_cord_width_p-1:0] my_x_i,
input [y_cord_width_p-1:0] my_y_i,
input out_ready_lo,
output reg destv_en,
output [x_cord_width_p-1:0] dest_x_o,
output [y_cord_width_p-1:0] dest_y_o
);
// tile coordinates
wire [x_cord_width_p-1:0] my_x_i_cast;
wire [y_cord_width_p-1:0] my_y_i_cast;
logic [x_cord_width_p-1:0] dest_x_o_cast;
logic [y_cord_width_p-1:0] dest_y_o_cast;
assign my_x_i_cast = my_x_i;
assign my_y_i_cast = my_y_i;
assign dest_x_o = dest_x_o_cast;
assign dest_y_o = dest_y_o_cast;
logic cp;
int fid;
int random_array[2000-1:0];
int rd, value;
Random_id destxy_random = new(100);
int i, tn;
initial begin
i = 0;
tn = 0;
cp = 0;
rd = 0;
/* fid=$fopen("./random_data.txt","r");
while( rd<1000 ) begin
if(!$fscanf(fid,"%d\n",value))
$display("reading the random_data.txt file is error!");
random_array[rd]= value;
// $display("reading rd=%d ihe random_data%d\n", rd, random_array[rd]);
rd = rd +1;
end
$fclose(fid); */
$readmemh("random_data.txt", random_array);
@(negedge clk_i); // in order to prevent the my_x_i == unkown value x when the initial start
destxy_random.srandom(random_array[my_x_i_cast*my_y_i_cast]);
// $display(">>>random seed (y,x)(%d,%d) \n",my_y_i, my_x_i);
$display(">>>random seed (y,x)(%d,%d) from seed=%d \n",my_y_i, my_x_i, random_array[(my_x_i_cast+1)*(my_y_i_cast+1)]); // destxy_random.randomize();
end
int launch_N;
logic reset_i_r, reset_i_rr;
always_ff @(posedge clk_i)
begin
reset_i_r <= reset_i;
reset_i_rr <= reset_i_r;
end
logic [9:0] destx, desty;
logic [7:0] start;
logic signed [7:0] noise;
always_ff @(posedge clk_i )
begin
// destxy_random.randomize(destxr);
// destxy_random.randomize(destyr);
// destxy_random.randomize(startr);
// destxy_random.randomize(noiser);
destx <= destxy_random.destxr;
desty <= destxy_random.destyr;
start <= destxy_random.startr;
noise <= destxy_random.noiser;
// $display("(x,y,s,n)(%d,%d,%d,%d) \n",destx, desty, start, noise);
end
always @(posedge clk_i)
begin
if(reset_i_rr) begin
launch_N <= noise + `per_cyc;
end
else if(i==launch_N-1 && ~cp && out_ready_lo)
begin
destxy_random.randomize(noiser);
launch_N <= noise + `per_cyc;
end
end
always @(posedge clk_i)
begin
if(reset_i_rr) begin
i <= start%launch_N;
tn <= 0;
end
else begin