`ifndef ROUTER_INTERFACE_SV
`define ROUTER_INTERFACE_SV
interface router_interface(input logic [0:0] clock);
logic reset_n;
logic [15:0] din;
logic [15:0] frame_n;
logic [15:0] valid_n;
logic [15:0] dout;
logic [15:0] valido_n;
logic [15:0] busy_n;
logic [15:0] frameo_n;
clocking cb @(posedge clock);
output din;
output frame_n;
output valid_n;
output reset_n;
input dout;
input valido_n;
input busy_n;
input frameo_n;
endclocking : cb
modport TB(clocking cb, output reset_n);
endinterface : router_interface
`endif //ROUTER_INTERFACE_SV
* * *
[图片上传失败...(image-e19758-1658799902766)]
##
例化变量要在显示之前【否则会报错】
* * *
`ifndef ROUTER_SEND_RECEIVE_CHECK_SV
`define ROUTER_SEND_RECEIVE_CHECK_SV
program router_send_receive_check(router_interface router_inf_tb);
task send_addr(input bit [3:0] source_addr_i,input bit[3:0] dest_addr_i);
$display("send_addr,source_addr_i=0x%0h",source_addr_i,dest_addr_i);/*{{{*/
for(int i=0; i<4 ; i++) begin
@(router_inf_tb.cb);
router_inf_tb.cb.din[source_addr_i] <= dest_addr_i[i];
router_inf_tb.cb.frame_n[source_addr_i] <= 1'b0;
router_inf_tb.cb.valid_n[source_addr_i] <= 1'b0;
end/*}}}*/
endtask: send_addr
task send_pad(input bit[3:0] source_addr_i);
$display("send_pad, source_addr_i=0x%0h",source_addr_i);
for(
int i=0; i < 5; i++) begin/*{{{*/
@(router_inf_tb.cb);
router_inf_tb.cb.din[source_addr_i] <= 1;
router_inf_tb.cb.frame_n[source_addr_i] <= 1'b0;
router_inf_tb.cb.valid_n[source_addr_i] <= 1'b1;
end/*}}}*/
endtask: send_pad
task send_data(input bit [3:0] source_addr_i, input bit [7:0] data_q_i[$]) ;
$display("send_data,source_addr_i=0x%0h,data:%p",source_addr_i,data_q_i);
foreach (data_q_i[index]) begin // byte :8bit
for(int i = 0; i < 8; i++) begin/*{{{*/
@(router_inf_tb.cb);
router_inf_tb.cb.din[source_addr_i] <= data_q_i[index][i];
router_inf_tb.cb.valid_n[source_addr_i] <= 1'b0;
if((index == (data_q_i.size()-1)) && (i == 7)) begin // last beat
router_inf_tb.cb.frame_n[source_addr_i] <= 1'b1;
end else begin
router_inf_tb.cb.frame_n[source_addr_i] <= 1'b0;
end/*}}}*/
end
end
@(router_inf_tb.cb);
router_inf_tb.cb.valid_n[source_addr_i] <= 1'b1;
endtask : send_data
task send_data_8bit(input bit [3:0] source_addr_i, input bit [7:0] data_i);
$display("send_data, source_addr_i=0x%0h, data=0x%h", source_addr_i, data_i);
for(int i = 0; i<8; i++) begin
@(router_inf_tb.cb);
router_inf_tb.cb.din[source_addr_i] <= data_i[i];
router_inf_tb.cb.valid_n[source_addr_i] <= 1'b0;
if(i == 7) begin
router_inf_tb.cb.frame_n[source_addr_i] <= 1'b1;
end else begin
router_inf_tb.cb.frame_n[source_addr_i] <= 1'b0;
end
end
endtask: send_data_8bit
task gen_data(input int send_data_num_i,output bit[7:0] data_q_o[$]); // gen data
bit[7:0] data;
$display("gen_data,send_data_num=%0d",send_data_num_i);
for(int i = 0; i< send_data_num_i ; i++) begin
data = $random(); // $ urandom_range(100,200)
data_q_o.push_back(data);
end
endtask: gen_data
task send (input bit[3:0]source_addr_i, input bit[3:0] dest_addr_i, input int send_data_num_i,output bit [7:0] data_q_o[$]);
// send addr
send_addr(.source_addr_i(source_addr_i), .dest_addr_i(dest_addr_i));
// send pad
send_pad(.source_addr_i(source_addr_i));
// gen data
gen_data(.send_data_num_i(send_data_num_i), .data_q_o(data_q_o));
// send data
send_data(.source_addr_i(source_addr_i),.data_q_i(data_q_o));
endtask:send
task reset();
$display("interface_reset_test,reset enter....");
router_inf_tb.reset_n <= 1'b0;
router_inf_tb.cb.din <= 'h0;
router_inf_tb.cb.frame_n <= 'h1;
router_inf_tb.cb.valid_n <= 'h1;
##2 router_inf_tb.cb.reset_n <= 1'b1;
repeat(15) begin
@(router_inf_tb.cb);
end
endtask : reset
task receive(input bit[3:0] dest_addr_i, output bit [7:0] data_q_o[$]);
bit [7:0] data;
bit [2:0] i = 0;
$display("receive,enter.....");
forever begin
if(i==0) begin
data_q_o.push_back(data);
$display("receive,data_q_o:%p",data_q_o); // %
@(router_inf_tb.cb);
if(router_inf_tb.cb.valido_n[dest_addr_i] ==0) begin
if(router_inf_tb.cb.frameo_n[dest_addr_i] ==0) begin
data[i] = router_inf_tb.dout;
i = i + 1;
end else if (router_inf_tb.frameo_n[dest_addr_i] == 1 && (i == 7)) begin
data[i] = router_inf_tb.dout;
i = i + 1;
end else begin
$display("error dut output frameo_n, i=%0d",i);
$finish;
end
if(i==0) begin
data_q_o.push_back(data);
$display("receive,data_q_o:%p",data_q_o); // %p print queue
end
end
end
end
endtask:receive
task check(input bit[7:0] send_data_q_i[$], input bit [7:0] receive_data_q_i[$]);
bit [7:0] actual_data; /// send_data _q = 0x
bit [7:0] expect_data;
// send data size ?= receive data size
if(send_data_q_i.size()!= receive_data_q_i.size()) begin
$display("data check error,send_data_q_i.size:%0d != receive_data_q_i.size: %0d",send_data_q_i.size(),receive_data_q_i.size()) ;
end
//
//
foreach(receive_data_q_i[i]) begin
actual_data = receive_data_q_i.pop_front();
expect_data = send_data_q_i.pop_front();
if (actual_data != expect_data) begin
$display("data check error, expect_data = 0x%0h, actual_data = 0x%0h",expect_data,actual_data);
end else begin
$display("data check right, expect_data = 0x%0h, actual_data = 0x%0h",expect_data,actual_data);
end
end
endtask:check
initial begin
bit[3:0] source_addr = 0;
bit[3:0] dest_addr = 3;
int send_data_num = 2;
bit [7:0] send_data_q[$];
bit [7:0] receive_data_q[$];
// reset
reset();
// send
fork
send(.source_addr_i(source_addr),.dest_addr_i(dest_addr), .send_data_num_i(send_data_num),.data_q_o(send_data_q));
//receive
receive(.dest_addr_i(dest_addr),.data_q_o(receive_data_q)); // forever
join_any
//check
check(.send_data_q_i(send_data_q),.receive_data_q_i(receive_data_q));
end
endprogram: router_send_receive_check
`endif //ROUTER_SEND_RECEIVE_CHECK_SV
O
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 大O符号是算法复杂度的相对表示,它描述了时空复杂度(时间复杂度/空间复杂度)。 大O符号是我在大学里学过的东西之一...
- 这些都是算法时空复杂度的表示。不仅仅用于表示时间复杂度,也用于表示空间复杂度。 O后面的括号中有一个函数,指明某个...
- 由于平时接触算法比较少,今天看资料看到了o(1),都不知道是什么意思,查资料之后才理解。 描述算法复杂度时,常用...
- O2O这个概念特别火的时候是在2013年,谁都想试水O2O,对于传统行业的商家们来说就像看见了救命稻草一般,直到今...
- 在描述算法复杂度时,经常用到o(1), o(n), o(logn), o(nlogn)来表示对应算法的时间复杂度,...