OpenCores
URL https://opencores.org/ocsvn/ha1588/ha1588/trunk

Subversion Repositories ha1588

[/] [ha1588/] [tags/] [v1p2/] [sim/] [sopc/] [master_bfm_tb.v] - Blame information for rev 53

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 edn_walter
//--------------------------------------------------------------------------
2
// master_bfm_tb.v 
3
// This test bench instantiates a master BFM and an onchip RAM
4
// as the slave DUT. The test starts with master BFM writing an
5
// amount of data to the slave according to the number of
6
// transactions which is defined by user.
7
//
8
// Next, master BFM starts reading back the data from slave.
9
// The read back data is compared with the desired data .
10
//
11
// The test case is defined in the test_input.v file while the
12
// result checking rountine is defined in test_result.v file
13
//--------------------------------------------------------------------------
14
 
15
// console messaging level
16
`define VERBOSITY VERBOSITY_INFO
17
 
18
//BFM hierachy
19
`define MSTR_BFM tb.DUT.the_master_bfm.master_bfm
20
 
21
//test bench parameters
22
`define NUM_TRANS 5  //user-defined number of transactions to be performed
23
`define INDEX_ZERO 0  //burst cycle with index zero for non-bursting transactions
24
 
25
// BFM related parameters
26
`define AV_ADDRESS_W 16
27
`define AV_SYMBOL_W 8
28
`define AV_NUMSYMBOLS 4
29
 
30
// derived parameters
31
`define AV_DATA_W (`AV_SYMBOL_W * `AV_NUMSYMBOLS)
32
 
33
 
34
//-----------------------------------------------------------------------------
35
// Test Top Level begins here
36
//-----------------------------------------------------------------------------
37
module master_bfm_tb();
38
 
39
  //importing verbosity and avalon_mm packages
40
  import verbosity_pkg::*;
41
  import avalon_mm_pkg::*;
42
 
43
  // instantiate SOPC system module
44
  test_bench tb();
45
 
46
  //local variables   
47
  Request_t command_request, response_request;
48
  reg [`AV_ADDRESS_W-1:0] command_addr, response_addr;
49
  reg [`AV_DATA_W-1:0] command_data, response_data;
50
  reg [`AV_NUMSYMBOLS-1:0] byte_enable;
51
  reg [`AV_DATA_W-1:0] idle;
52
  integer init_latency;
53
  reg [`AV_DATA_W-1:0] master_scoreboard [$];
54
  reg [`AV_DATA_W-1:0] expected_data;
55
  integer failure = 0;
56
  integer checked = 0;
57
  event start_test;
58
  event go_check;
59
 
60
  //initialize the master BFM
61
  initial
62
  begin
63
    set_verbosity(`VERBOSITY);
64
    `MSTR_BFM.init();
65
        //wait for reset to de-assert and trigger start_test event
66
    wait(`MSTR_BFM.reset == 0);
67
        -> start_test;
68
  end
69
 
70
  //check responses received by master BFM
71
  always @(posedge tb.clk_0)
72
  begin
73
    while (`MSTR_BFM.get_response_queue_size() > 0)
74
        begin
75
          //pop out the response desriptor from queue when queue is not empty
76
          master_pop_and_get_response(response_request, response_addr, response_data);
77
          //trigger event to check the response with expected data
78
          -> go_check;
79
        end
80
  end
81
 
82
  //simulation ends here
83
  //both write and read transactions do have response descriptors, so the number 
84
  //of responses received by master BFM is double of NUM_TRANS
85
  initial
86
  begin
87
    while (checked != (`NUM_TRANS*2))
88
          @(tb.clk_0);
89
        //we care only the result for read transactions
90
        $sformat(message, "%m: Test has completed. %0d pass, %0d fail", ((checked / 2) - failure), failure);
91
        print(VERBOSITY_INFO, message);
92
        $stop;
93
  end
94
 
95
  `include "test_input.v"
96
  `include "test_result.v"
97
 
98
  //----------------------------------------------------------------------------------
99
  // tasks
100
  //----------------------------------------------------------------------------------
101
 
102
  //this task sets the command descriptor for master BFM and push it to the queue
103
  task master_set_and_push_command;
104
  input Request_t request;
105
  input [`AV_ADDRESS_W-1:0] addr;
106
  input [`AV_DATA_W-1:0] data;
107
  input [`AV_NUMSYMBOLS-1:0] byte_enable;
108
  input [`AV_DATA_W-1:0] idle;
109
  input [31:0] init_latency;
110
 
111
  begin
112
        `MSTR_BFM.set_command_request(request);
113
    `MSTR_BFM.set_command_address(addr);
114
    `MSTR_BFM.set_command_byte_enable(byte_enable,`INDEX_ZERO);
115
    `MSTR_BFM.set_command_idle(idle, `INDEX_ZERO);
116
        `MSTR_BFM.set_command_init_latency(init_latency);
117
 
118
        if (request == REQ_WRITE)
119
        begin
120
           `MSTR_BFM.set_command_data(data, `INDEX_ZERO);
121
        end
122
 
123
        `MSTR_BFM.push_command();
124
  end
125
  endtask
126
 
127
  //this task pops the response received by master BFM from queue
128
  task master_pop_and_get_response;
129
  output Request_t request;
130
  output [`AV_ADDRESS_W-1:0] addr;
131
  output [`AV_DATA_W-1:0] data;
132
 
133
  begin
134
    `MSTR_BFM.pop_response();
135
        request = Request_t' (`MSTR_BFM.get_response_request());
136
        addr = `MSTR_BFM.get_response_address();
137
    data = `MSTR_BFM.get_response_data(`INDEX_ZERO);
138
  end
139
  endtask
140
 
141
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.