// ********************************************************// 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 begini = 0;tn = 0;cp = 0;rd = 0;
/* fid=$fopen(\"./random_data.txt\while( rd<1000 ) begin
if(!$fscanf(fid,\"%d\\n\
$display(\"reading the random_data.txt file is error!\");random_array[rd]= value;
// $display(\"reading rd=%d ihe random_data%d\\n\rd = rd +1;end
$fclose(fid); */
$readmemh(\"random_data.txt\
@(negedge clk_i); // in order to prevent the my_x_i == unkown value x when the initial startdestxy_random.srandom(random_array[my_x_i_cast*my_y_i_cast]);// $display(\">>>random seed (y,x)(%d,%d) \\n\
$display(\">>>random seed (y,x)(%d,%d) from seed=%d \\n\// 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\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;endend
always @(posedge clk_i)begin
if(reset_i_rr) begini <= start%launch_N;tn <= 0;end
else begin
if (i==launch_N-1) begini <= 0;
if( out_ready_lo ) tn <= tn + 1;end
else begini <= i+1;endendend
always @(posedge clk_i)begin
if(reset_i_rr) begindestv_en <= 0;cp <= 0;end
else if(i==launch_N-1 && tn>=10 && tn < `packet_num && out_ready_lo )begin
destv_en <= 1'b1;cp <= ~cp;
// $display(\"cp=%d \\n\endelse
destv_en <= 1'b0;end
always @(posedge clk_i)begin
if(reset_i_rr) begin
dest_x_o_cast <= destx;end
else if(i==launch_N-1 && ~cp && out_ready_lo)begin
destxy_random.randomize(destxr);
dest_x_o_cast <= destx % `logic_add_x;endend
always @(posedge clk_i)begin
if(reset_i_rr) begin
dest_y_o_cast <= desty;end
else if(i==launch_N-1 && ~cp && out_ready_lo)begin
destxy_random.randomize(destyr);
dest_y_o_cast <= desty % `logic_add_y;endendendmodule
因篇幅问题不能全部显示,请点此查看更多更全内容