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

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [rtl/] [adv_debug_sys/] [Hardware/] [adv_dbg_if/] [bench/] [simulated_system/] [wb_slave_behavioral.v] - Blame information for rev 21

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 xianfeng
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  wb_slave_behavioral.v                                       ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the SoC Debug Interface.               ////
7
////  http://www.opencores.org/projects/DebugInterface/           ////
8
////                                                              ////
9
////  Author(s):                                                  ////
10
////      Tadej Markovic, tadej@opencores.org                     ////
11
////                                                              ////
12
////                                                              ////
13
////  All additional information is avaliable in the README.txt   ////
14
////  file.                                                       ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2000 - 2004 Authors                            ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
//
43
// CVS Revision History
44
//
45
// $Log: wb_slave_behavioral.v,v $
46
// Revision 1.2  2010-01-08 01:41:08  Nathan
47
// Removed unused, non-existant include from CPU behavioral model.  Minor text edits.
48
//
49
// Revision 1.1  2008/07/08 19:11:57  Nathan
50
// Added second testbench to simulate a complete system, including OR1200, wb_conbus, and onchipram.  Renamed sim-only testbench directory from verilog to simulated_system.
51
//
52
// Revision 1.2  2008/06/26 20:54:44  Nathan
53
// Testbench modified to use WB behavioral model instead of an onchip_ram.  Added test of WB error register.
54
//
55
// Revision 1.1  2008/06/18 18:34:49  Nathan
56
// Initial working version.  Only Wishbone module implemented.  Simple testbench included, with CPU and Wishbone behavioral models from the old dbg_interface.
57
//
58
// Revision 1.1.1.1  2008/05/14 12:07:36  Nathan
59
// Original from OpenCores
60
//
61
// Revision 1.3  2004/03/28 20:27:40  igorm
62
// New release of the debug interface (3rd. release).
63
//
64
// Revision 1.2  2004/01/15 10:47:13  mohor
65
// Working.
66
//
67
// Revision 1.1  2003/12/23 14:26:01  mohor
68
// New version of the debug interface. Not finished, yet.
69
//
70
//
71
//
72
//
73
 
74
//`include "timescale.v"
75
`include "wb_model_defines.v"
76
module wb_slave_behavioral
77
(
78
        CLK_I,
79
        RST_I,
80
        ACK_O,
81
        ADR_I,
82
        CYC_I,
83
        DAT_O,
84
        DAT_I,
85
        ERR_O,
86
        RTY_O,
87
        SEL_I,
88
        STB_I,
89
        WE_I,
90
        CAB_I
91
);
92
 
93
/*------------------------------------------------------------------------------------------------------
94
WISHBONE signals
95
------------------------------------------------------------------------------------------------------*/
96
input                   CLK_I;
97
input                   RST_I;
98
output                  ACK_O;
99
input   `WB_ADDR_TYPE   ADR_I;
100
input                   CYC_I;
101
output  `WB_DATA_TYPE   DAT_O;
102
input   `WB_DATA_TYPE   DAT_I;
103
output                  ERR_O;
104
output                  RTY_O;
105
input   `WB_SEL_TYPE    SEL_I;
106
input                   STB_I;
107
input                   WE_I;
108
input                   CAB_I;
109
 
110
reg     `WB_DATA_TYPE   DAT_O;
111
 
112
/*------------------------------------------------------------------------------------------------------
113
Asynchronous dual-port RAM signals for storing and fetching the data
114
------------------------------------------------------------------------------------------------------*/
115
//reg     `WB_DATA_TYPE wb_memory [0:16777215]; // WB memory - 24 addresses connected - 2 LSB not used
116
reg     `WB_DATA_TYPE wb_memory [0:1048575]; // WB memory - 20 addresses connected - 2 LSB not used
117
reg     `WB_DATA_TYPE mem_wr_data_out;
118
reg     `WB_DATA_TYPE mem_rd_data_in;
119
 
120
/*------------------------------------------------------------------------------------------------------
121
Maximum values for WAIT and RETRY counters and which response !!!
122
------------------------------------------------------------------------------------------------------*/
123
reg     [2:0]  a_e_r_resp; // tells with which cycle_termination_signal must wb_slave respond !
124
reg     [8:0]  wait_cyc;
125
reg     [7:0]  max_retry;
126
 
127
// assign registers to default state while in reset
128
// always@(RST_I)
129
// begin
130
//   if (RST_I)
131
//   begin
132
//     a_e_r_resp <= 3'b000; // do not respond
133
//     wait_cyc   <= 8'b0; // no wait cycles
134
//     max_retry  <= 8'h0; // no retries
135
//   end
136
// end //reset
137
 
138
task cycle_response;
139
  input [2:0]  ack_err_rty_resp; // acknowledge, error or retry response input flags
140
  input [8:0]  wait_cycles; // if wait cycles before each data termination cycle (ack, err or rty)
141
  input [7:0]  retry_cycles; // noumber of retry cycles before acknowledge cycle
142
begin
143
  // assign values
144
  a_e_r_resp <= #1 ack_err_rty_resp;
145
  wait_cyc   <= #1 wait_cycles;
146
  max_retry  <= #1 retry_cycles;
147
end
148
endtask // cycle_response
149
 
150
/*------------------------------------------------------------------------------------------------------
151
Tasks for writing and reading to and from memory !!!
152
------------------------------------------------------------------------------------------------------*/
153
reg    `WB_ADDR_TYPE task_wr_adr_i;
154
reg    `WB_ADDR_TYPE task_rd_adr_i;
155
reg    `WB_DATA_TYPE task_dat_i;
156
reg    `WB_DATA_TYPE task_dat_o;
157
reg    `WB_SEL_TYPE  task_sel_i;
158
reg                  task_wr_data;
159
reg                  task_data_written;
160
reg    `WB_DATA_TYPE task_mem_wr_data;
161
 
162
// write to memory
163
task wr_mem;
164
  input  `WB_ADDR_TYPE adr_i;
165
  input  `WB_DATA_TYPE dat_i;
166
  input  `WB_SEL_TYPE  sel_i;
167
begin
168
  task_data_written = 0;
169
  task_wr_adr_i = adr_i;
170
  task_dat_i = dat_i;
171
  task_sel_i = sel_i;
172
  task_wr_data = 1;
173
  wait(task_data_written);
174
  task_wr_data = 0;
175
end
176
endtask
177
 
178
// read from memory
179
task rd_mem;
180
  input  `WB_ADDR_TYPE adr_i;
181
  output `WB_DATA_TYPE dat_o;
182
  input  `WB_SEL_TYPE  sel_i;
183
begin
184
  task_rd_adr_i = adr_i;
185
  task_sel_i = sel_i;
186
  #1;
187
  dat_o = task_dat_o;
188
end
189
endtask
190
 
191
/*------------------------------------------------------------------------------------------------------
192
Internal signals and logic
193
------------------------------------------------------------------------------------------------------*/
194
reg            calc_ack;
195
reg            calc_err;
196
reg            calc_rty;
197
 
198
reg     [7:0]  retry_cnt;
199
reg     [7:0]  retry_num;
200
reg            retry_expired;
201
 
202
// Retry counter
203
always@(posedge RST_I or posedge CLK_I)
204
begin
205
  if (RST_I)
206
    retry_cnt <= #1 8'h00;
207
  else
208
  begin
209
    if (calc_ack || calc_err)
210
      retry_cnt <= #1 8'h00;
211
    else if (calc_rty)
212
      retry_cnt <= #1 retry_num;
213
  end
214
end
215
 
216
always@(retry_cnt or max_retry)
217
begin
218
  if (retry_cnt < max_retry)
219
  begin
220
    retry_num = retry_cnt + 1'b1;
221
    retry_expired = 1'b0;
222
  end
223
  else
224
  begin
225
    retry_num = retry_cnt;
226
    retry_expired = 1'b1;
227
  end
228
end
229
 
230
reg     [8:0]  wait_cnt;
231
reg     [8:0]  wait_num;
232
reg            wait_expired;
233
 
234
// Wait counter
235
always@(posedge RST_I or posedge CLK_I)
236
begin
237
  if (RST_I)
238
    wait_cnt <= #1 9'h0;
239
  else
240
  begin
241
    if (wait_expired || ~STB_I)
242
      wait_cnt <= #1 9'h0;
243
    else
244
      wait_cnt <= #1 wait_num;
245
  end
246
end
247
 
248
always@(wait_cnt or wait_cyc or STB_I or a_e_r_resp or retry_expired)
249
begin
250
  if ((wait_cyc > 0) && (STB_I))
251
  begin
252
    if (wait_cnt < wait_cyc)
253
    begin
254
      wait_num = wait_cnt + 1'b1;
255
      wait_expired = 1'b0;
256
      calc_ack = 1'b0;
257
      calc_err = 1'b0;
258
      calc_rty = 1'b0;
259
    end
260
    else
261
    begin
262
      wait_num = wait_cnt;
263
      wait_expired = 1'b1;
264
      if (a_e_r_resp == 3'b100)
265
      begin
266
        calc_ack = 1'b1;
267
        calc_err = 1'b0;
268
        calc_rty = 1'b0;
269
      end
270
      else
271
      if (a_e_r_resp == 3'b010)
272
      begin
273
        calc_ack = 1'b0;
274
        calc_err = 1'b1;
275
        calc_rty = 1'b0;
276
      end
277
      else
278
      if (a_e_r_resp == 3'b001)
279
      begin
280
        calc_err = 1'b0;
281
        if (retry_expired)
282
        begin
283
          calc_ack = 1'b1;
284
          calc_rty = 1'b0;
285
        end
286
        else
287
        begin
288
          calc_ack = 1'b0;
289
          calc_rty = 1'b1;
290
        end
291
      end
292
      else
293
      begin
294
        calc_ack = 1'b0;
295
        calc_err = 1'b0;
296
        calc_rty = 1'b0;
297
      end
298
    end
299
  end
300
  else
301
  if ((wait_cyc == 0) && (STB_I))
302
  begin
303
    wait_num = 9'h0;
304
    wait_expired = 1'b1;
305
    if (a_e_r_resp == 3'b100)
306
    begin
307
      calc_ack = 1'b1;
308
      calc_err = 1'b0;
309
      calc_rty = 1'b0;
310
    end
311
    else if (a_e_r_resp == 3'b010)
312
    begin
313
      calc_ack = 1'b0;
314
      calc_err = 1'b1;
315
      calc_rty = 1'b0;
316
    end
317
    else if (a_e_r_resp == 3'b001)
318
    begin
319
      calc_err = 1'b0;
320
      if (retry_expired)
321
      begin
322
        calc_ack = 1'b1;
323
        calc_rty = 1'b0;
324
      end
325
      else
326
      begin
327
        calc_ack = 1'b0;
328
        calc_rty = 1'b1;
329
      end
330
    end
331
    else
332
    begin
333
      calc_ack = 1'b0;
334
      calc_err = 1'b0;
335
      calc_rty = 1'b0;
336
    end
337
  end
338
  else
339
  begin
340
    wait_num = 9'h0;
341
    wait_expired = 1'b0;
342
    calc_ack = 1'b0;
343
    calc_err = 1'b0;
344
    calc_rty = 1'b0;
345
  end
346
end
347
 
348
wire rd_sel = (CYC_I && STB_I && ~WE_I);
349
wire wr_sel = (CYC_I && STB_I && WE_I);
350
 
351
// Generate cycle termination signals
352
assign ACK_O = calc_ack && STB_I;
353
assign ERR_O = calc_err && STB_I;
354
assign RTY_O = calc_rty && STB_I;
355
 
356
// Assign address to asynchronous memory
357
always@(RST_I or ADR_I)
358
begin
359
  if (RST_I) // this is added because at start of test bench we need address change in order to get data!
360
  begin
361
    #1 mem_rd_data_in = `WB_DATA_WIDTH'hxxxx_xxxx;
362
  end
363
  else
364
  begin
365
//    #1 mem_rd_data_in = wb_memory[ADR_I[25:2]];
366
    #1 mem_rd_data_in = wb_memory[ADR_I[21:2]];
367
  end
368
end
369
 
370
// Data input/output interface
371
always@(rd_sel or mem_rd_data_in or RST_I)
372
begin
373
  if (RST_I)
374
    DAT_O <=#1 `WB_DATA_WIDTH'hxxxx_xxxx;       // assign outputs to unknown state while in reset
375
  else if (rd_sel)
376
    DAT_O <=#1 mem_rd_data_in;
377
  else
378
    DAT_O <=#1 `WB_DATA_WIDTH'hxxxx_xxxx;
379
end
380
 
381
 
382
always@(RST_I or task_rd_adr_i)
383
begin
384
  if (RST_I)
385
    task_dat_o = `WB_DATA_WIDTH'hxxxx_xxxx;
386
  else
387
    task_dat_o = wb_memory[task_rd_adr_i[21:2]];
388
end
389
always@(CLK_I or wr_sel or task_wr_data or ADR_I or task_wr_adr_i or
390
        mem_wr_data_out or DAT_I or task_mem_wr_data or task_dat_i or
391
        SEL_I or task_sel_i)
392
begin
393
  if (task_wr_data)
394
  begin
395
    task_mem_wr_data = wb_memory[task_wr_adr_i[21:2]];
396
 
397
    if (task_sel_i[3])
398
      task_mem_wr_data[31:24] = task_dat_i[31:24];
399
    if (task_sel_i[2])
400
      task_mem_wr_data[23:16] = task_dat_i[23:16];
401
    if (task_sel_i[1])
402
      task_mem_wr_data[15: 8] = task_dat_i[15: 8];
403
    if (task_sel_i[0])
404
      task_mem_wr_data[ 7: 0] = task_dat_i[ 7: 0];
405
 
406
    wb_memory[task_wr_adr_i[21:2]] = task_mem_wr_data; // write data
407
    task_data_written = 1;
408
  end
409
  else if (wr_sel && CLK_I)
410
  begin
411
//    mem_wr_data_out = wb_memory[ADR_I[25:2]]; // if no SEL_I is active, old value will be written
412
    mem_wr_data_out = wb_memory[ADR_I[21:2]]; // if no SEL_I is active, old value will be written
413
 
414
    if (SEL_I[3])
415
      mem_wr_data_out[31:24] = DAT_I[31:24];
416
    if (SEL_I[2])
417
      mem_wr_data_out[23:16] = DAT_I[23:16];
418
    if (SEL_I[1])
419
      mem_wr_data_out[15: 8] = DAT_I[15: 8];
420
    if (SEL_I[0])
421
      mem_wr_data_out[ 7: 0] = DAT_I[ 7: 0];
422
 
423
//    wb_memory[ADR_I[25:2]]  <= mem_wr_data_out; // write data
424
    wb_memory[ADR_I[21:2]]      = mem_wr_data_out; // write data
425
  end
426
end
427
 
428
endmodule

powered by: WebSVN 2.1.0

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