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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [agent/] [driver/] [uart_driver.svh] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 HanySalah
//-----------------------------------------------------------------------------
2
//
3
//                             UART2BUS VERIFICATION
4
//
5
//-----------------------------------------------------------------------------
6
// CREATOR    : HANY SALAH
7
// PROJECT    : UART2BUS UVM TEST BENCH
8
// UNIT       : DRIVER
9
//-----------------------------------------------------------------------------
10
// TITLE      : UART Driver
11
// DESCRIPTION: This
12
//-----------------------------------------------------------------------------
13
// LOG DETAILS
14
//-------------
15
// VERSION      NAME        DATE        DESCRIPTION
16
//    1       HANY SALAH    02012016    FILE CREATION
17
//    2       HANY SALAH    07012016    ADD INITIALIZE BFM METHOD
18
//-----------------------------------------------------------------------------
19
// ALL COPYRIGHTS ARE RESERVED FOR THE PRODUCER ONLY .THIS FILE IS PRODUCED FOR
20
// OPENCORES MEMBERS ONLY AND IT IS PROHIBTED TO USE THIS MATERIAL WITHOUT THE
21
// CREATOR'S PERMISSION
22
//-----------------------------------------------------------------------------
23
 
24
class uart_driver extends uvm_driver #(uart_transaction);
25
 
26
  // Two Transaction Instances that are used to bring and clone the
27
  // stimulus
28
  uart_transaction      trans,_trans;
29
 
30
  // Instance from Global UART Configuration
31
  uart_config           _config;
32
 
33
  // UART Interafce instance
34
  virtual uart_interface  uart_inf;
35
 
36
  // RF Interface instance
37
  virtual rf_interface rf_inf;
38
 
39
  // Arbiter Interface Instance
40
  virtual uart_arbiter  arb_inf;
41
 
42
  uvm_analysis_port #(uart_transaction)   drv_scbd_cov;
43
 
44
  `uvm_component_utils(uart_driver)
45
 
46
  function new (string name , uvm_component parent);
47
    super.new(name,parent);
48
  endfunction: new
49
 
50
  function void display_content ();
51
    $display("here %s\n command_type = %p \n command = %p \n char_type = %p \n  space_type1 = %p \n  space_wrong1 = %8b \n  space_type2 = %p \n  space_wrong2 = %8b \n  eol_type = %p \n  eol_wrong = %8b \n  address = %h \n  data = %8b", get_full_name(),trans._mode,
52
              trans._command,
53
              trans._chartype,
54
              trans._spacetype1,
55
              trans.space_wrong1,
56
              trans._spacetype2,
57
              trans.space_wrong2,
58
              trans._eoltype,
59
              trans.eol_wrong,
60
              trans.address,
61
              trans._data[0]);
62
  endfunction:display_content
63
 
64
  // UVM Build Phase Declaration that includes locating instances and get
65
  // interfaces handler from the configuration database
66
  extern function void build_phase (uvm_phase phase);
67
 
68
  extern function void end_of_elaboration_phase (uvm_phase phase);
69
 
70
  // UVM Run Phase Declaratio
71
  extern task run_phase (uvm_phase phase);
72
 
73
  // Actual drive data routine
74
  extern task drive_data (int iteration);
75
 
76
  // initialize bfms
77
  extern function void initialize_bfms (act_edge  _edge,
78
                                        start_bit _bit,
79
                                        int num_stop_bits,
80
                                        int num_of_bits,
81
                                        data_mode _datamode,
82
                                        parity_mode _paritymode,
83
                                        time _resp);
84
endclass:uart_driver
85
 
86
function void uart_driver::build_phase (uvm_phase phase);
87
  super.build_phase(phase);
88
 
89
  trans   = uart_transaction::type_id::create("trans");
90
  _trans  = uart_transaction::type_id::create("_trans");
91
 
92
  _config = uart_config::type_id::create("_config");
93
 
94
  drv_scbd_cov = new("drv_scbd_cov",this);
95
 
96
endfunction:build_phase
97
 
98
function void uart_driver::end_of_elaboration_phase (uvm_phase phase);
99
 
100
  if(!uvm_config_db#(uart_config)::get(this, "", "UART_CONFIGURATION", _config))
101
    `uvm_fatal("NOCONFIGURATION",{"configuration instance must be set for: ",get_full_name(),"._config"});
102
 
103
  if(!uvm_config_db#(virtual uart_interface)::get(this, "", "uart_inf", _config.uart_inf))
104
      `uvm_fatal("NOVIF",{"virtual interface must be set for: ",get_full_name(),".uart_inf"});
105
    uart_inf=_config.uart_inf;
106
 
107
  if(!uvm_config_db#(virtual rf_interface)::get(this, "", "rf_inf", _config.rf_inf))
108
      `uvm_fatal("NOVIF",{"virtual interface must be set for: ",get_full_name(),".rf_inf"});
109
    rf_inf=_config.rf_inf;
110
 
111
  if(!uvm_config_db#(virtual uart_arbiter)::get(this,"","arb_inf",_config.arb_inf))
112
      `uvm_fatal("NOVIF",{"virtual interface must be set for:",get_full_name(),".arb_inf"})
113
    arb_inf=_config.arb_inf;
114
 
115
endfunction:end_of_elaboration_phase
116
 
117
function void uart_driver::initialize_bfms (act_edge  _edge,
118
                                            start_bit _bit,
119
                                            int num_stop_bits,
120
                                            int num_of_bits,
121
                                            data_mode _datamode,
122
                                            parity_mode _paritymode,
123
                                            time      _resp);
124
  uart_inf.set_configuration(_edge,_bit,num_stop_bits,num_of_bits,_datamode,_paritymode,_resp);
125
endfunction:initialize_bfms
126
 
127
task uart_driver::run_phase (uvm_phase phase);
128
 
129
  int iteration;
130
  iteration = 0;
131
 
132
  initialize_bfms(_config._edge,
133
                  _config._start,
134
                  _config.num_stop_bits,
135
                  _config.num_of_bits,
136
                  _config._datamode,
137
                  _config._paritymode,
138
                  _config.response_time);
139
 
140
  forever
141
    begin
142
    iteration++;
143
    if (iteration == 3)
144
      begin
145
      //$stop;
146
      end
147
    seq_item_port.get_next_item(_trans);
148
    $cast(trans,_trans.clone());
149
    drv_scbd_cov.write(trans);
150
    //display_content();
151
    drive_data(iteration);
152
    seq_item_port.item_done();
153
    end
154
endtask:run_phase
155
 
156
task uart_driver::drive_data(int iteration);
157
  uart_inf.wait_idle_time(trans.time_before*trans.scale);
158
  uart_inf.set_event();
159
  case (trans._mode)
160
  text:
161
    begin
162
      case(trans._command)
163
      read:
164
        begin
165
        fork
166
        begin
167
          if (trans._arbit == accept)
168
            begin
169
            arb_inf.accept_req();
170
            end
171
          else
172
            begin
173
            arb_inf.declain_req();
174
            end
175
        end
176
        join_none
177
        rf_inf.fill_byte (trans.address,
178
                          trans._data[0]);
179
        uart_inf.read_text_mode(trans._chartype,
180
                                trans._spacetype1,
181
                                trans.space_wrong1,
182
                                trans._eoltype,
183
                                trans.eol_wrong,
184
                                trans.address);
185
        end
186
      write:
187
        begin
188
        fork
189
        begin
190
          if (trans._arbit == accept)
191
            begin
192
            arb_inf.accept_req();
193
            end
194
          else
195
            begin
196
            arb_inf.declain_req();
197
            end
198
        end
199
        join_none
200
        uart_inf.write_text_mode(trans._chartype,
201
                                 trans._spacetype1,
202
                                 trans.space_wrong1,
203
                                 trans._spacetype2,
204
                                 trans.space_wrong2,
205
                                 trans._eoltype,
206
                                 trans.eol_wrong,
207
                                 trans.address,
208
                                 trans._data[0]);
209
        end
210
      nop:
211
        begin
212
        `uvm_fatal("UNEXPECTED VALUE","NOP command value shouldn't be valued in text mode")
213
        end
214
      default:
215
        begin
216
        `uvm_fatal("wrong output", "wrong_mode")
217
        end
218
      endcase
219
    end
220
  binary:
221
    begin
222
    case(trans._command)
223
      read:
224
        begin
225
        rf_inf.fill_block(trans.address,
226
                          trans._data,
227
                          trans.length_data);
228
        uart_inf.read_binary_mode(trans._reqack,
229
                                  trans._reqinc,
230
                                  trans.length_data,
231
                                  trans.address,
232
                                  trans._data);
233
        end
234
      write:
235
        begin
236
        uart_inf.write_binary_mode(trans._reqack,
237
                                   trans._reqinc,
238
                                   trans.length_data,
239
                                   trans.address,
240
                                   trans._data);
241
        end
242
      nop:
243
        begin
244
        uart_inf.nop_command(trans._reqack,
245
                             trans._reqinc);
246
        end
247
      default:
248
        begin
249
        `uvm_fatal("UNDEFINED COMMAND","Binary command should be either read or write or no operation")
250
        end
251
    endcase
252
    end
253
  wrong_mode:
254
    begin
255
    uart_inf.wrong_command(trans._reqack,
256
                           trans._reqinc,
257
                           trans.space_wrong1,
258
                           trans.length_data,
259
                           trans.address,
260
                           trans._data);
261
    end
262
  default:
263
    begin
264
    `uvm_fatal("UNEXPECTED VALUE","Command should be text or command or wrong")
265
    end
266
  endcase
267
  uart_inf.wait_idle_time(trans.time_after*trans.scale);
268
endtask:drive_data

powered by: WebSVN 2.1.0

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