|
| 1 | +// Copyright 2024 ETH Zurich and University of Bologna. |
| 2 | +// Solderpad Hardware License, Version 0.51, see LICENSE for details. |
| 3 | +// SPDX-License-Identifier: SHL-0.51 |
| 4 | +// |
| 5 | +// Author: Tim Fischer <fischeti@iis.ee.ethz.ch> |
| 6 | + |
| 7 | +/// A set of testbench utilities for the FlooNoC interface. |
| 8 | +package floo_test; |
| 9 | + |
| 10 | + import floo_pkg::*; |
| 11 | + import floo_axi_pkg::*; |
| 12 | + |
| 13 | + class floo_driver #( |
| 14 | + parameter time TA = 0ns, |
| 15 | + parameter time TT = 0ns |
| 16 | + ); |
| 17 | + virtual FLOO_LINK_DV intf; |
| 18 | + |
| 19 | + function new(virtual FLOO_LINK_DV intf); |
| 20 | + this.intf = intf; |
| 21 | + endfunction |
| 22 | + |
| 23 | + function void reset_mgr(); |
| 24 | + intf.floo_req_mgr <= '0; |
| 25 | + intf.floo_rsp_mgr <= '0; |
| 26 | + endfunction |
| 27 | + |
| 28 | + function void reset_sbr(); |
| 29 | + intf.floo_req_sbr <= '0; |
| 30 | + intf.floo_rsp_sbr <= '0; |
| 31 | + endfunction |
| 32 | + |
| 33 | + task cycle_start(); |
| 34 | + #TT; |
| 35 | + endtask |
| 36 | + |
| 37 | + task cycle_end(); |
| 38 | + @(posedge intf.clk_i); |
| 39 | + endtask |
| 40 | + |
| 41 | + task send_req ( |
| 42 | + input floo_req_generic_flit_t req |
| 43 | + ); |
| 44 | + intf.floo_req_mgr.req <= #TA req; |
| 45 | + intf.floo_req_mgr.valid <= #TA 1'b1; |
| 46 | + cycle_start(); |
| 47 | + while (intf.floo_req_sbr.ready != 1'b1) begin cycle_end(); cycle_start(); end |
| 48 | + cycle_end(); |
| 49 | + intf.floo_req_mgr.req <= #TA '0; |
| 50 | + intf.floo_req_mgr.valid <= #TA 1'b0; |
| 51 | + endtask |
| 52 | + |
| 53 | + task send_rsp ( |
| 54 | + input floo_rsp_generic_flit_t rsp |
| 55 | + ); |
| 56 | + intf.floo_rsp_sbr.rsp <= #TA rsp; |
| 57 | + intf.floo_rsp_sbr.valid <= #TA 1'b1; |
| 58 | + cycle_start(); |
| 59 | + while (intf.floo_rsp_mgr.ready != 1'b1) begin cycle_end(); cycle_start(); end |
| 60 | + cycle_end(); |
| 61 | + intf.floo_rsp_sbr.rsp <= #TA '0; |
| 62 | + intf.floo_rsp_sbr.valid <= #TA 1'b0; |
| 63 | + endtask |
| 64 | + |
| 65 | + task recv_req ( |
| 66 | + output floo_req_generic_flit_t req |
| 67 | + ); |
| 68 | + intf.floo_req_sbr.ready <= #TA 1'b1; |
| 69 | + cycle_start(); |
| 70 | + while (intf.floo_req_mgr.valid != 1'b1) begin cycle_end(); cycle_start(); end |
| 71 | + // TODO: create new req? i.e. do we need to define it as a class? |
| 72 | + req = intf.floo_req_mgr.req; |
| 73 | + cycle_end(); |
| 74 | + intf.floo_req_mgr.ready <= #TA 1'b0; |
| 75 | + endtask |
| 76 | + |
| 77 | + task recv_rsp ( |
| 78 | + output floo_rsp_generic_flit_t rsp |
| 79 | + ); |
| 80 | + intf.floo_rsp_mgr.ready <= #TA 1'b1; |
| 81 | + cycle_start(); |
| 82 | + while (intf.floo_rsp_sbr.valid != 1'b1) begin cycle_end(); cycle_start(); end |
| 83 | + rsp = intf.floo_rsp_sbr.rsp; |
| 84 | + cycle_end(); |
| 85 | + intf.floo_rsp_sbr.ready <= #TA 1'b0; |
| 86 | + endtask |
| 87 | + |
| 88 | + endclass |
| 89 | + |
| 90 | + class floo_node #( |
| 91 | + parameter time TA = 0ns, |
| 92 | + parameter time TT = 0ns, |
| 93 | + parameter id_t SrcId = '0, |
| 94 | + parameter route_algo_e RouteAlgo = XYRouting, |
| 95 | + parameter int MaxId = 0 |
| 96 | + ); |
| 97 | + floo_driver #( |
| 98 | + .TA(TA), |
| 99 | + .TT(TT) |
| 100 | + ) drv; |
| 101 | + |
| 102 | + function new(virtual FLOO_LINK_DV intf); |
| 103 | + drv = new(intf); |
| 104 | + drv.reset_mgr(); |
| 105 | + drv.reset_sbr(); |
| 106 | + endfunction |
| 107 | + |
| 108 | + function floo_req_generic_flit_t new_rand_req(); |
| 109 | + automatic logic rand_success; |
| 110 | + automatic hdr_t hdr; |
| 111 | + automatic floo_req_generic_flit_t req; |
| 112 | + automatic id_t dst_id; |
| 113 | + |
| 114 | + dst_id = id_t'($urandom_range(0, MaxId)); |
| 115 | + endfunction |
| 116 | + |
| 117 | + endclass |
| 118 | + |
| 119 | + |
| 120 | +endpackage |
0 commit comments