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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [sdram_test_working/] [rtl/] [verilog/] [dbg_top.v] - Blame information for rev 158

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  dbg_top.v                                                   ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the SoC/OpenRISC Development Interface ////
7 36 mohor
////  http://www.opencores.org/projects/DebugInterface/           ////
8 2 mohor
////                                                              ////
9
////                                                              ////
10
////  Author(s):                                                  ////
11
////       Igor Mohor                                             ////
12
////       igorm@opencores.org                                    ////
13
////                                                              ////
14
////                                                              ////
15
////  All additional information is avaliable in the README.txt   ////
16
////  file.                                                       ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2000,2001 Authors                              ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
//////////////////////////////////////////////////////////////////////
44
//
45
// CVS Revision History
46
//
47
// $Log: not supported by cvs2svn $
48 47 mohor
// Revision 1.25  2002/04/22 12:54:11  mohor
49
// Signal names changed to lower case.
50
//
51 44 mohor
// Revision 1.24  2002/04/17 13:17:01  mohor
52
// Intentional error removed.
53
//
54 43 mohor
// Revision 1.23  2002/04/17 11:16:33  mohor
55
// A block for checking possible simulation/synthesis missmatch added.
56
//
57 42 mohor
// Revision 1.22  2002/03/12 10:31:53  mohor
58
// tap_top and dbg_top modules are put into two separate modules. tap_top
59
// contains only tap state machine and related logic. dbg_top contains all
60
// logic necessery for debugging.
61
//
62 37 mohor
// Revision 1.21  2002/03/08 15:28:16  mohor
63
// Structure changed. Hooks for jtag chain added.
64
//
65 36 mohor
// Revision 1.20  2002/02/06 12:23:09  mohor
66
// LatchedJTAG_IR used when muxing TDO instead of JTAG_IR.
67
//
68 33 mohor
// Revision 1.19  2002/02/05 13:34:51  mohor
69
// Stupid bug that was entered by previous update fixed.
70
//
71 32 mohor
// Revision 1.18  2002/02/05 12:41:01  mohor
72
// trst synchronization is not needed and was removed.
73
//
74 31 mohor
// Revision 1.17  2002/01/25 07:58:35  mohor
75
// IDCODE bug fixed, chains reused to decreas size of core. Data is shifted-in
76
// not filled-in. Tested in hw.
77
//
78 30 mohor
// Revision 1.16  2001/12/20 11:17:26  mohor
79
// TDO and TDO Enable signal are separated into two signals.
80
//
81 28 mohor
// Revision 1.15  2001/12/05 13:28:21  mohor
82
// trst signal is synchronized to wb_clk_i.
83
//
84 25 mohor
// Revision 1.14  2001/11/28 09:36:15  mohor
85
// Register length fixed.
86
//
87 22 mohor
// Revision 1.13  2001/11/27 13:37:43  mohor
88
// CRC is returned when chain selection data is transmitted.
89
//
90 21 mohor
// Revision 1.12  2001/11/26 10:47:09  mohor
91
// Crc generation is different for read or write commands. Small synthesys fixes.
92
//
93 20 mohor
// Revision 1.11  2001/11/14 10:10:41  mohor
94
// Wishbone data latched on wb_clk_i instead of risc_clk.
95
//
96 19 mohor
// Revision 1.10  2001/11/12 01:11:27  mohor
97
// Reset signals are not combined any more.
98
//
99 18 mohor
// Revision 1.9  2001/10/19 11:40:01  mohor
100
// dbg_timescale.v changed to timescale.v This is done for the simulation of
101
// few different cores in a single project.
102
//
103 17 mohor
// Revision 1.8  2001/10/17 10:39:03  mohor
104
// bs_chain_o added.
105
//
106 15 mohor
// Revision 1.7  2001/10/16 10:09:56  mohor
107
// Signal names changed to lowercase.
108 13 mohor
//
109 15 mohor
//
110 13 mohor
// Revision 1.6  2001/10/15 09:55:47  mohor
111
// Wishbone interface added, few fixes for better performance,
112
// hooks for boundary scan testing added.
113
//
114 12 mohor
// Revision 1.5  2001/09/24 14:06:42  mohor
115
// Changes connected to the OpenRISC access (SPR read, SPR write).
116
//
117 11 mohor
// Revision 1.4  2001/09/20 10:11:25  mohor
118
// Working version. Few bugs fixed, comments added.
119
//
120 9 mohor
// Revision 1.3  2001/09/19 11:55:13  mohor
121
// Asynchronous set/reset not used in trace any more.
122
//
123 8 mohor
// Revision 1.2  2001/09/18 14:13:47  mohor
124
// Trace fixed. Some registers changed, trace simplified.
125
//
126 5 mohor
// Revision 1.1.1.1  2001/09/13 13:49:19  mohor
127
// Initial official release.
128
//
129 2 mohor
// Revision 1.3  2001/06/01 22:22:35  mohor
130
// This is a backup. It is not a fully working version. Not for use, yet.
131
//
132
// Revision 1.2  2001/05/18 13:10:00  mohor
133
// Headers changed. All additional information is now avaliable in the README.txt file.
134
//
135
// Revision 1.1.1.1  2001/05/18 06:35:02  mohor
136
// Initial release
137
//
138
//
139
 
140 20 mohor
// synopsys translate_off
141 17 mohor
`include "timescale.v"
142 20 mohor
// synopsys translate_on
143 2 mohor
`include "dbg_defines.v"
144
 
145
// Top module
146 9 mohor
module dbg_top(
147
 
148
                // RISC signals
149 11 mohor
                risc_clk_i, risc_addr_o, risc_data_i, risc_data_o, wp_i,
150
                bp_i, opselect_o, lsstatus_i, istatus_i, risc_stall_o, reset_o,
151 9 mohor
 
152 12 mohor
                // WISHBONE common signals
153
                wb_rst_i, wb_clk_i,
154
 
155
                // WISHBONE master interface
156
                wb_adr_o, wb_dat_o, wb_dat_i, wb_cyc_o, wb_stb_o, wb_sel_o,
157 36 mohor
                wb_we_o, wb_ack_i, wb_cab_o, wb_err_i,
158 12 mohor
 
159 36 mohor
                // TAP states
160
                ShiftDR, Exit1DR, UpdateDR, UpdateDR_q,
161
 
162
                // Instructions
163
                IDCODESelected, CHAIN_SELECTSelected, DEBUGSelected,
164
 
165
                // TAP signals
166 37 mohor
                trst_in, tck, tdi, TDOData,
167 36 mohor
 
168 47 mohor
                BypassRegister,
169
 
170
                // Monitor mux control
171
                mon_cntl_o
172 37 mohor
 
173 2 mohor
              );
174
 
175
parameter Tp = 1;
176
 
177
 
178 9 mohor
// RISC signals
179 11 mohor
input         risc_clk_i;                 // Master clock (RISC clock)
180 9 mohor
input  [31:0] risc_data_i;                // RISC data inputs (data that is written to the RISC registers)
181
input  [10:0] wp_i;                       // Watchpoint inputs
182
input         bp_i;                       // Breakpoint input
183
input  [3:0]  lsstatus_i;                 // Load/store status inputs
184
input  [1:0]  istatus_i;                  // Instruction status inputs
185
output [31:0] risc_addr_o;                // RISC address output (for adressing registers within RISC)
186
output [31:0] risc_data_o;                // RISC data output (data read from risc registers)
187
output [`OPSELECTWIDTH-1:0] opselect_o;   // Operation selection (selecting what kind of data is set to the risc_data_i)
188
output                      risc_stall_o; // Stalls the RISC
189 11 mohor
output                      reset_o;      // Resets the RISC
190 2 mohor
 
191
 
192 12 mohor
// WISHBONE common signals
193 9 mohor
input         wb_rst_i;                   // WISHBONE reset
194 12 mohor
input         wb_clk_i;                   // WISHBONE clock
195 9 mohor
 
196 12 mohor
// WISHBONE master interface
197
output [31:0] wb_adr_o;
198
output [31:0] wb_dat_o;
199
input  [31:0] wb_dat_i;
200
output        wb_cyc_o;
201
output        wb_stb_o;
202
output  [3:0] wb_sel_o;
203
output        wb_we_o;
204
input         wb_ack_i;
205
output        wb_cab_o;
206
input         wb_err_i;
207 9 mohor
 
208
// TAP states
209 36 mohor
input         ShiftDR;
210
input         Exit1DR;
211
input         UpdateDR;
212
input         UpdateDR_q;
213 2 mohor
 
214 37 mohor
input trst_in;
215 36 mohor
input tck;
216
input tdi;
217 2 mohor
 
218 36 mohor
input BypassRegister;
219 9 mohor
 
220 36 mohor
output TDOData;
221 47 mohor
output [3:0] mon_cntl_o;
222 36 mohor
 
223 9 mohor
// Defining which instruction is selected
224 36 mohor
input         IDCODESelected;
225
input         CHAIN_SELECTSelected;
226
input         DEBUGSelected;
227 2 mohor
 
228 36 mohor
reg           wb_cyc_o;
229 9 mohor
 
230 36 mohor
reg [31:0]    ADDR;
231
reg [31:0]    DataOut;
232 11 mohor
 
233 36 mohor
reg [`OPSELECTWIDTH-1:0] opselect_o;        // Operation selection (selecting what kind of data is set to the risc_data_i)
234 2 mohor
 
235 36 mohor
reg [`CHAIN_ID_LENGTH-1:0] Chain;           // Selected chain
236
reg [31:0]    DataReadLatch;                // Data when reading register or RISC is latched one risc_clk_i clock after the data is read.
237
reg           RegAccessTck;                 // Indicates access to the registers (read or write)
238
reg           RISCAccessTck;                // Indicates access to the RISC (read or write)
239
reg [7:0]     BitCounter;                   // Counting bits in the ShiftDR and Exit1DR stages
240
reg           RW;                           // Read/Write bit
241
reg           CrcMatch;                     // The crc that is shifted in and the internaly calculated crc are equal
242 2 mohor
 
243 36 mohor
reg           RegAccess_q;                  // Delayed signals used for accessing the registers
244
reg           RegAccess_q2;                 // Delayed signals used for accessing the registers
245
reg           RISCAccess_q;                 // Delayed signals used for accessing the RISC
246
reg           RISCAccess_q2;                // Delayed signals used for accessing the RISC
247 2 mohor
 
248 36 mohor
reg           wb_AccessTck;                 // Indicates access to the WISHBONE
249
reg [31:0]    WBReadLatch;                  // Data latched during WISHBONE read
250
reg           WBErrorLatch;                 // Error latched during WISHBONE read
251 30 mohor
 
252 37 mohor
wire trst;
253 30 mohor
 
254 37 mohor
 
255 9 mohor
wire [31:0]             RegDataIn;        // Data from registers (read data)
256
wire [`CRC_LENGTH-1:0]  CalculatedCrcOut; // CRC calculated in this module. This CRC is apended at the end of the TDO.
257 2 mohor
 
258 9 mohor
wire RiscStall_reg;                       // RISC is stalled by setting the register bit
259
wire RiscReset_reg;                       // RISC is reset by setting the register bit
260
wire RiscStall_trace;                     // RISC is stalled by trace module
261
 
262
 
263
wire RegisterScanChain;                   // Register Scan chain selected
264
wire RiscDebugScanChain;                  // Risc Debug Scan chain selected
265 12 mohor
wire WishboneScanChain;                   // WISHBONE Scan chain selected
266 11 mohor
 
267
wire RiscStall_read_access;               // Stalling RISC because of the read access (SPR read)
268
wire RiscStall_write_access;              // Stalling RISC because of the write access (SPR write)
269
wire RiscStall_access;                    // Stalling RISC because of the read or write access
270
 
271 30 mohor
wire BitCounter_Lt4;
272
wire BitCounter_Eq5;
273
wire BitCounter_Eq32;
274
wire BitCounter_Lt38;
275
wire BitCounter_Lt65;
276
 
277 15 mohor
 
278
 
279 9 mohor
// This signals are used only when TRACE is used in the design
280 2 mohor
`ifdef TRACE_ENABLED
281 9 mohor
  wire [39:0] TraceChain;                 // Chain that comes from trace module
282 36 mohor
  reg  ReadBuffer_Tck;                    // Command for incrementing the trace read pointer (synchr with tck)
283 9 mohor
  wire ReadTraceBuffer;                   // Command for incrementing the trace read pointer (synchr with MClk)
284
  reg  ReadTraceBuffer_q;                 // Delayed command for incrementing the trace read pointer (synchr with MClk)
285
  wire ReadTraceBufferPulse;              // Pulse for reading the trace buffer (valid for only one Mclk command)
286 2 mohor
 
287
  // Outputs from registers
288 9 mohor
  wire ContinMode;                        // Trace working in continous mode
289
  wire TraceEnable;                       // Trace enabled
290 2 mohor
 
291 9 mohor
  wire [10:0] WpTrigger;                  // Watchpoint starts trigger
292
  wire        BpTrigger;                  // Breakpoint starts trigger
293
  wire [3:0]  LSSTrigger;                 // Load/store status starts trigger
294
  wire [1:0]  ITrigger;                   // Instruction status starts trigger
295
  wire [1:0]  TriggerOper;                // Trigger operation
296 2 mohor
 
297 9 mohor
  wire        WpTriggerValid;             // Watchpoint trigger is valid
298
  wire        BpTriggerValid;             // Breakpoint trigger is valid
299
  wire        LSSTriggerValid;            // Load/store status trigger is valid
300
  wire        ITriggerValid;              // Instruction status trigger is valid
301 2 mohor
 
302 9 mohor
  wire [10:0] WpQualif;                   // Watchpoint starts qualifier
303
  wire        BpQualif;                   // Breakpoint starts qualifier
304
  wire [3:0]  LSSQualif;                  // Load/store status starts qualifier
305
  wire [1:0]  IQualif;                    // Instruction status starts qualifier
306
  wire [1:0]  QualifOper;                 // Qualifier operation
307 2 mohor
 
308 9 mohor
  wire        WpQualifValid;              // Watchpoint qualifier is valid
309
  wire        BpQualifValid;              // Breakpoint qualifier is valid
310
  wire        LSSQualifValid;             // Load/store status qualifier is valid
311
  wire        IQualifValid;               // Instruction status qualifier is valid
312 2 mohor
 
313 9 mohor
  wire [10:0] WpStop;                     // Watchpoint stops recording of the trace
314
  wire        BpStop;                     // Breakpoint stops recording of the trace
315
  wire [3:0]  LSSStop;                    // Load/store status stops recording of the trace
316
  wire [1:0]  IStop;                      // Instruction status stops recording of the trace
317
  wire [1:0]  StopOper;                   // Stop operation
318 2 mohor
 
319 9 mohor
  wire WpStopValid;                       // Watchpoint stop is valid
320
  wire BpStopValid;                       // Breakpoint stop is valid
321
  wire LSSStopValid;                      // Load/store status stop is valid
322
  wire IStopValid;                        // Instruction status stop is valid
323 2 mohor
 
324 9 mohor
  wire RecordPC;                          // Recording program counter
325
  wire RecordLSEA;                        // Recording load/store effective address
326
  wire RecordLDATA;                       // Recording load data
327
  wire RecordSDATA;                       // Recording store data
328
  wire RecordReadSPR;                     // Recording read SPR
329
  wire RecordWriteSPR;                    // Recording write SPR
330
  wire RecordINSTR;                       // Recording instruction
331 2 mohor
 
332
  // End: Outputs from registers
333
 
334 9 mohor
  wire TraceTestScanChain;                // Trace Test Scan chain selected
335
  wire [47:0] Trace_Data;                 // Trace data
336 2 mohor
 
337 11 mohor
  wire [`OPSELECTWIDTH-1:0]opselect_trace;// Operation selection (trace selecting what kind of
338
                                          // data is set to the risc_data_i)
339 30 mohor
  wire BitCounter_Lt40;
340 11 mohor
 
341 2 mohor
`endif
342
 
343
 
344 37 mohor
assign trst = ~trst_in;                   // trst_pad_i is active low
345 25 mohor
 
346
 
347 2 mohor
/**********************************************************************************
348
*                                                                                 *
349
*   JTAG_DR:  JTAG Data Register                                                  *
350
*                                                                                 *
351
**********************************************************************************/
352
reg [`DR_LENGTH-1:0]JTAG_DR_IN;    // Data register
353
reg TDOData;
354
 
355
 
356 36 mohor
always @ (posedge tck or posedge trst)
357 2 mohor
begin
358 18 mohor
  if(trst)
359 2 mohor
    JTAG_DR_IN[`DR_LENGTH-1:0]<=#Tp 0;
360
  else
361 30 mohor
  if(IDCODESelected)                          // To save space JTAG_DR_IN is also used for shifting out IDCODE
362
    begin
363
      if(ShiftDR)
364 36 mohor
        JTAG_DR_IN[31:0] <= #Tp {tdi, JTAG_DR_IN[31:1]};
365 30 mohor
      else
366
        JTAG_DR_IN[31:0] <= #Tp `IDCODE_VALUE;
367
    end
368
  else
369
  if(CHAIN_SELECTSelected & ShiftDR)
370 36 mohor
    JTAG_DR_IN[12:0] <= #Tp {tdi, JTAG_DR_IN[12:1]};
371 30 mohor
  else
372
  if(DEBUGSelected & ShiftDR)
373
    begin
374
      if(RiscDebugScanChain | WishboneScanChain)
375 36 mohor
        JTAG_DR_IN[73:0] <= #Tp {tdi, JTAG_DR_IN[73:1]};
376 30 mohor
      else
377
      if(RegisterScanChain)
378 36 mohor
        JTAG_DR_IN[46:0] <= #Tp {tdi, JTAG_DR_IN[46:1]};
379 30 mohor
    end
380 2 mohor
end
381 30 mohor
 
382 22 mohor
wire [73:0] RISC_Data;
383
wire [46:0] Register_Data;
384
wire [73:0] WISHBONE_Data;
385 21 mohor
wire [12:0] chain_sel_data;
386 12 mohor
wire wb_Access_wbClk;
387 2 mohor
 
388
 
389 30 mohor
reg select_crc_out;
390 36 mohor
always @ (posedge tck or posedge trst)
391 30 mohor
begin
392
  if(trst)
393
    select_crc_out <= 0;
394
  else
395
  if( RegisterScanChain  & BitCounter_Eq5  |
396
      RiscDebugScanChain & BitCounter_Eq32 |
397
      WishboneScanChain  & BitCounter_Eq32 )
398 36 mohor
    select_crc_out <=#Tp tdi;
399 30 mohor
  else
400
  if(CHAIN_SELECTSelected)
401
    select_crc_out <=#Tp 1;
402
  else
403
  if(UpdateDR)
404
    select_crc_out <=#Tp 0;
405
end
406 12 mohor
 
407 20 mohor
wire [8:0] send_crc;
408
 
409 30 mohor
assign send_crc = select_crc_out? {9{BypassRegister}}    :    // Calculated CRC is returned when read operation is
410
                                  {CalculatedCrcOut, 1'b0} ;  // performed, else received crc is returned (loopback).
411 20 mohor
 
412 30 mohor
assign RISC_Data      = {send_crc, DataReadLatch, 33'h0};
413
assign Register_Data  = {send_crc, DataReadLatch, 6'h0};
414 20 mohor
assign WISHBONE_Data  = {send_crc, WBReadLatch, 32'h0, WBErrorLatch};
415 21 mohor
assign chain_sel_data = {send_crc, 4'h0};
416 20 mohor
 
417
 
418
`ifdef TRACE_ENABLED
419 2 mohor
  assign Trace_Data     = {CalculatedCrcOut, TraceChain};
420
`endif
421
 
422 36 mohor
//TDO is changing on the falling edge of tck
423
always @ (negedge tck or posedge trst)
424 2 mohor
begin
425 18 mohor
  if(trst)
426 2 mohor
    begin
427
      TDOData <= #Tp 0;
428
      `ifdef TRACE_ENABLED
429
      ReadBuffer_Tck<=#Tp 0;
430
      `endif
431
    end
432
  else
433
  if(UpdateDR)
434
    begin
435
      TDOData <= #Tp CrcMatch;
436
      `ifdef TRACE_ENABLED
437 9 mohor
      if(DEBUGSelected & TraceTestScanChain & TraceChain[0])  // Sample in the trace buffer is valid
438
        ReadBuffer_Tck<=#Tp 1;                                // Increment read pointer
439 2 mohor
      `endif
440
    end
441
  else
442
    begin
443
      if(ShiftDR)
444
        begin
445
          if(IDCODESelected)
446 36 mohor
            TDOData <= #Tp JTAG_DR_IN[0]; // IDCODE is shifted out 32-bits, then tdi is bypassed
447 2 mohor
          else
448
          if(CHAIN_SELECTSelected)
449 21 mohor
            TDOData <= #Tp chain_sel_data[BitCounter];        // Received crc is sent back
450 2 mohor
          else
451
          if(DEBUGSelected)
452
            begin
453
              if(RiscDebugScanChain)
454 9 mohor
                TDOData <= #Tp RISC_Data[BitCounter];         // Data read from RISC in the previous cycle is shifted out
455 2 mohor
              else
456
              if(RegisterScanChain)
457 9 mohor
                TDOData <= #Tp Register_Data[BitCounter];     // Data read from register in the previous cycle is shifted out
458 12 mohor
              else
459
              if(WishboneScanChain)
460
                TDOData <= #Tp WISHBONE_Data[BitCounter];     // Data read from the WISHBONE slave
461 2 mohor
              `ifdef TRACE_ENABLED
462
              else
463
              if(TraceTestScanChain)
464 9 mohor
                TDOData <= #Tp Trace_Data[BitCounter];        // Data from the trace buffer is shifted out
465 2 mohor
              `endif
466
            end
467
        end
468
      else
469
        begin
470
          TDOData <= #Tp 0;
471
          `ifdef TRACE_ENABLED
472
          ReadBuffer_Tck<=#Tp 0;
473
          `endif
474
        end
475
    end
476
end
477
 
478 42 mohor
 
479
//synopsys translate_off
480
always @ (posedge tck)
481
begin
482
  if(ShiftDR & CHAIN_SELECTSelected & BitCounter > 12)
483
    begin
484
      $display("\n%m Error: BitCounter is bigger then chain_sel_data bits width[12:0]. BitCounter=%d\n",BitCounter);
485
      $stop;
486
    end
487
  else
488
  if(ShiftDR & DEBUGSelected)
489
    begin
490
      if(RiscDebugScanChain & BitCounter > 73)
491
        begin
492
          $display("\n%m Error: BitCounter is bigger then RISC_Data bits width[73:0]. BitCounter=%d\n",BitCounter);
493
          $stop;
494
        end
495
      else
496 43 mohor
      if(RegisterScanChain & BitCounter > 46)
497 42 mohor
        begin
498
          $display("\n%m Error: BitCounter is bigger then RISC_Data bits width[46:0]. BitCounter=%d\n",BitCounter);
499
          $stop;
500
        end
501
      else
502
      if(WishboneScanChain & BitCounter > 73)
503
        begin
504
          $display("\n%m Error: BitCounter is bigger then WISHBONE_Data bits width[73:0]. BitCounter=%d\n",BitCounter);
505
          $stop;
506
        end
507
      `ifdef TRACE_ENABLED
508
      else
509
      if(TraceTestScanChain & BitCounter > 47)
510
        begin
511
          $display("\n%m Error: BitCounter is bigger then Trace_Data bits width[47:0]. BitCounter=%d\n",BitCounter);
512
          $stop;
513
        end
514
      `endif
515
    end
516
end
517
// synopsys translate_on
518
 
519
 
520
 
521
 
522
 
523
 
524
 
525
 
526 2 mohor
/**********************************************************************************
527
*                                                                                 *
528
*   End: JTAG_DR                                                                  *
529
*                                                                                 *
530
**********************************************************************************/
531
 
532
 
533
 
534
/**********************************************************************************
535
*                                                                                 *
536
*   CHAIN_SELECT logic                                                            *
537
*                                                                                 *
538
**********************************************************************************/
539 36 mohor
always @ (posedge tck or posedge trst)
540 2 mohor
begin
541 18 mohor
  if(trst)
542 9 mohor
    Chain[`CHAIN_ID_LENGTH-1:0]<=#Tp `GLOBAL_BS_CHAIN;  // Global BS chain is selected after reset
543 2 mohor
  else
544
  if(UpdateDR & CHAIN_SELECTSelected & CrcMatch)
545 9 mohor
    Chain[`CHAIN_ID_LENGTH-1:0]<=#Tp JTAG_DR_IN[3:0];   // New chain is selected
546 2 mohor
end
547
 
548
 
549
 
550
/**********************************************************************************
551
*                                                                                 *
552
*   Register read/write logic                                                     *
553
*   RISC registers read/write logic                                               *
554
*                                                                                 *
555
**********************************************************************************/
556 36 mohor
always @ (posedge tck or posedge trst)
557 2 mohor
begin
558 18 mohor
  if(trst)
559 2 mohor
    begin
560
      ADDR[31:0]        <=#Tp 32'h0;
561
      DataOut[31:0]     <=#Tp 32'h0;
562
      RW                <=#Tp 1'b0;
563
      RegAccessTck      <=#Tp 1'b0;
564
      RISCAccessTck     <=#Tp 1'b0;
565 12 mohor
      wb_AccessTck      <=#Tp 1'h0;
566 2 mohor
    end
567
  else
568
  if(UpdateDR & DEBUGSelected & CrcMatch)
569
    begin
570
      if(RegisterScanChain)
571
        begin
572
          ADDR[4:0]         <=#Tp JTAG_DR_IN[4:0];    // Latching address for register access
573
          RW                <=#Tp JTAG_DR_IN[5];      // latch R/W bit
574
          DataOut[31:0]     <=#Tp JTAG_DR_IN[37:6];   // latch data for write
575
          RegAccessTck      <=#Tp 1'b1;
576
        end
577
      else
578
      if(RiscDebugScanChain)
579
        begin
580
          ADDR[31:0]        <=#Tp JTAG_DR_IN[31:0];   // Latching address for RISC register access
581
          RW                <=#Tp JTAG_DR_IN[32];     // latch R/W bit
582
          DataOut[31:0]     <=#Tp JTAG_DR_IN[64:33];  // latch data for write
583
          RISCAccessTck     <=#Tp 1'b1;
584
        end
585 12 mohor
      else
586
      if(WishboneScanChain)
587
        begin
588 20 mohor
          ADDR              <=#Tp JTAG_DR_IN[31:0];   // Latching address for WISHBONE slave access
589
          RW                <=#Tp JTAG_DR_IN[32];     // latch R/W bit
590
          DataOut           <=#Tp JTAG_DR_IN[64:33];  // latch data for write
591 12 mohor
          wb_AccessTck      <=#Tp 1'b1;               // 
592
        end
593 2 mohor
    end
594
  else
595
    begin
596 36 mohor
      RegAccessTck      <=#Tp 1'b0;       // This signals are valid for one tck clock period only
597 2 mohor
      RISCAccessTck     <=#Tp 1'b0;
598 12 mohor
      wb_AccessTck      <=#Tp 1'b0;
599 2 mohor
    end
600
end
601
 
602 20 mohor
 
603
assign wb_adr_o = ADDR;
604
assign wb_we_o  = RW;
605
assign wb_dat_o = DataOut;
606 12 mohor
assign wb_sel_o[3:0] = 4'hf;
607
assign wb_cab_o = 1'b0;
608 20 mohor
 
609
 
610 11 mohor
// Synchronizing the RegAccess signal to risc_clk_i clock
611 36 mohor
dbg_sync_clk1_clk2 syn1 (.clk1(risc_clk_i),   .clk2(tck),           .reset1(wb_rst_i),  .reset2(trst),
612 2 mohor
                         .set2(RegAccessTck), .sync_out(RegAccess)
613
                        );
614
 
615 11 mohor
// Synchronizing the RISCAccess signal to risc_clk_i clock
616 36 mohor
dbg_sync_clk1_clk2 syn2 (.clk1(risc_clk_i),    .clk2(tck),          .reset1(wb_rst_i),  .reset2(trst),
617 2 mohor
                         .set2(RISCAccessTck), .sync_out(RISCAccess)
618
                        );
619
 
620
 
621 12 mohor
// Synchronizing the wb_Access signal to wishbone clock
622 36 mohor
dbg_sync_clk1_clk2 syn3 (.clk1(wb_clk_i),     .clk2(tck),           .reset1(wb_rst_i),  .reset2(trst),
623 12 mohor
                         .set2(wb_AccessTck), .sync_out(wb_Access_wbClk)
624
                        );
625
 
626
 
627
 
628
 
629
 
630 9 mohor
// Delayed signals used for accessing registers and RISC
631 18 mohor
always @ (posedge risc_clk_i or posedge wb_rst_i)
632 2 mohor
begin
633 18 mohor
  if(wb_rst_i)
634 2 mohor
    begin
635
      RegAccess_q   <=#Tp 1'b0;
636
      RegAccess_q2  <=#Tp 1'b0;
637
      RISCAccess_q  <=#Tp 1'b0;
638
      RISCAccess_q2 <=#Tp 1'b0;
639
    end
640
  else
641
    begin
642
      RegAccess_q   <=#Tp RegAccess;
643
      RegAccess_q2  <=#Tp RegAccess_q;
644
      RISCAccess_q  <=#Tp RISCAccess;
645
      RISCAccess_q2 <=#Tp RISCAccess_q;
646
    end
647
end
648
 
649 9 mohor
// Chip select and read/write signals for accessing RISC
650 11 mohor
assign RiscStall_write_access = RISCAccess & ~RISCAccess_q  &  RW;
651
assign RiscStall_read_access  = RISCAccess & ~RISCAccess_q2 & ~RW;
652
assign RiscStall_access = RiscStall_write_access | RiscStall_read_access;
653 2 mohor
 
654
 
655 12 mohor
reg wb_Access_wbClk_q;
656
// Delayed signals used for accessing WISHBONE
657 18 mohor
always @ (posedge wb_clk_i or posedge wb_rst_i)
658 12 mohor
begin
659 18 mohor
  if(wb_rst_i)
660 12 mohor
    wb_Access_wbClk_q <=#Tp 1'b0;
661
  else
662
    wb_Access_wbClk_q <=#Tp wb_Access_wbClk;
663
end
664
 
665 18 mohor
always @ (posedge wb_clk_i or posedge wb_rst_i)
666 12 mohor
begin
667 18 mohor
  if(wb_rst_i)
668 12 mohor
    wb_cyc_o <=#Tp 1'b0;
669
  else
670
  if(wb_Access_wbClk & ~wb_Access_wbClk_q & ~(wb_ack_i | wb_err_i))
671
    wb_cyc_o <=#Tp 1'b1;
672
  else
673
  if(wb_ack_i | wb_err_i)
674
    wb_cyc_o <=#Tp 1'b0;
675
end
676
 
677
assign wb_stb_o = wb_cyc_o;
678
 
679
 
680
// Latching data read from registers
681 19 mohor
always @ (posedge wb_clk_i or posedge wb_rst_i)
682 12 mohor
begin
683 18 mohor
  if(wb_rst_i)
684 12 mohor
    WBReadLatch[31:0]<=#Tp 32'h0;
685
  else
686
  if(wb_ack_i)
687
    WBReadLatch[31:0]<=#Tp wb_dat_i[31:0];
688
end
689
 
690
// Latching WISHBONE error cycle
691 18 mohor
always @ (posedge wb_clk_i or posedge wb_rst_i)
692 12 mohor
begin
693 18 mohor
  if(wb_rst_i)
694 12 mohor
    WBErrorLatch<=#Tp 1'b0;
695
  else
696
  if(wb_err_i)
697
    WBErrorLatch<=#Tp 1'b1;     // Latching wb_err_i while performing WISHBONE access
698 20 mohor
  else
699 12 mohor
  if(wb_ack_i)
700
    WBErrorLatch<=#Tp 1'b0;     // Clearing status
701
end
702
 
703
 
704 9 mohor
// Whan enabled, TRACE stalls RISC while saving data to the trace buffer.
705 5 mohor
`ifdef TRACE_ENABLED
706 11 mohor
  assign  risc_stall_o = RiscStall_access | RiscStall_reg | RiscStall_trace ;
707 5 mohor
`else
708 12 mohor
  assign  risc_stall_o = RiscStall_access | RiscStall_reg;
709 5 mohor
`endif
710
 
711 11 mohor
assign  reset_o = RiscReset_reg;
712 5 mohor
 
713
 
714 12 mohor
`ifdef TRACE_ENABLED
715 11 mohor
always @ (RiscStall_write_access or RiscStall_read_access or opselect_trace)
716 12 mohor
`else
717
always @ (RiscStall_write_access or RiscStall_read_access)
718
`endif
719 11 mohor
begin
720
  if(RiscStall_write_access)
721
    opselect_o = `DEBUG_WRITE_SPR;  // Write spr
722
  else
723
  if(RiscStall_read_access)
724
    opselect_o = `DEBUG_READ_SPR;   // Read spr
725
  else
726 12 mohor
`ifdef TRACE_ENABLED
727 11 mohor
    opselect_o = opselect_trace;
728 12 mohor
`else
729
    opselect_o = 3'h0;
730
`endif
731 11 mohor
end
732 9 mohor
 
733 11 mohor
 
734 30 mohor
// Latching data read from RISC or registers
735 18 mohor
always @ (posedge risc_clk_i or posedge wb_rst_i)
736 2 mohor
begin
737 18 mohor
  if(wb_rst_i)
738 30 mohor
    DataReadLatch[31:0]<=#Tp 0;
739 2 mohor
  else
740
  if(RISCAccess_q & ~RISCAccess_q2)
741 30 mohor
    DataReadLatch[31:0]<=#Tp risc_data_i[31:0];
742
  else
743
  if(RegAccess_q & ~RegAccess_q2)
744
    DataReadLatch[31:0]<=#Tp RegDataIn[31:0];
745 2 mohor
end
746
 
747 12 mohor
assign risc_addr_o = ADDR;
748
assign risc_data_o = DataOut;
749 2 mohor
 
750
 
751
 
752
/**********************************************************************************
753
*                                                                                 *
754
*   Read Trace buffer logic                                                       *
755
*                                                                                 *
756
**********************************************************************************/
757
`ifdef TRACE_ENABLED
758
 
759 9 mohor
 
760 11 mohor
// Synchronizing the trace read buffer signal to risc_clk_i clock
761 36 mohor
dbg_sync_clk1_clk2 syn4 (.clk1(risc_clk_i),     .clk2(tck),           .reset1(wb_rst_i),  .reset2(trst),
762 9 mohor
                         .set2(ReadBuffer_Tck), .sync_out(ReadTraceBuffer)
763
                        );
764
 
765
 
766
 
767 18 mohor
  always @(posedge risc_clk_i or posedge wb_rst_i)
768 2 mohor
  begin
769 18 mohor
    if(wb_rst_i)
770 9 mohor
      ReadTraceBuffer_q <=#Tp 0;
771 2 mohor
    else
772 9 mohor
      ReadTraceBuffer_q <=#Tp ReadTraceBuffer;
773 2 mohor
  end
774 9 mohor
 
775
  assign ReadTraceBufferPulse = ReadTraceBuffer & ~ReadTraceBuffer_q;
776
 
777 2 mohor
`endif
778
 
779
/**********************************************************************************
780
*                                                                                 *
781
*   End: Read Trace buffer logic                                                  *
782
*                                                                                 *
783
**********************************************************************************/
784
 
785
 
786
 
787
 
788
 
789
/**********************************************************************************
790
*                                                                                 *
791
*   Bit counter                                                                   *
792
*                                                                                 *
793
**********************************************************************************/
794
 
795
 
796 36 mohor
always @ (posedge tck or posedge trst)
797 2 mohor
begin
798 18 mohor
  if(trst)
799 2 mohor
    BitCounter[7:0]<=#Tp 0;
800
  else
801
  if(ShiftDR)
802
    BitCounter[7:0]<=#Tp BitCounter[7:0]+1;
803
  else
804
  if(UpdateDR)
805
    BitCounter[7:0]<=#Tp 0;
806
end
807
 
808
 
809
 
810
/**********************************************************************************
811
*                                                                                 *
812
*   End: Bit counter                                                              *
813
*                                                                                 *
814
**********************************************************************************/
815
 
816
 
817
 
818
/**********************************************************************************
819
*                                                                                 *
820
*   Connecting Registers                                                          *
821
*                                                                                 *
822
**********************************************************************************/
823 44 mohor
dbg_registers dbgregs(.data_in(DataOut[31:0]), .data_out(RegDataIn[31:0]),
824
                      .address(ADDR[4:0]), .rw(RW), .access(RegAccess & ~RegAccess_q), .clk(risc_clk_i),
825
                      .bp(bp_i), .reset(wb_rst_i),
826 2 mohor
                      `ifdef TRACE_ENABLED
827 5 mohor
                      .ContinMode(ContinMode), .TraceEnable(TraceEnable),
828 2 mohor
                      .WpTrigger(WpTrigger), .BpTrigger(BpTrigger), .LSSTrigger(LSSTrigger),
829
                      .ITrigger(ITrigger), .TriggerOper(TriggerOper), .WpQualif(WpQualif),
830
                      .BpQualif(BpQualif), .LSSQualif(LSSQualif), .IQualif(IQualif),
831 5 mohor
                      .QualifOper(QualifOper), .RecordPC(RecordPC),
832
                      .RecordLSEA(RecordLSEA), .RecordLDATA(RecordLDATA),
833
                      .RecordSDATA(RecordSDATA), .RecordReadSPR(RecordReadSPR),
834
                      .RecordWriteSPR(RecordWriteSPR), .RecordINSTR(RecordINSTR),
835
                      .WpTriggerValid(WpTriggerValid),
836 2 mohor
                      .BpTriggerValid(BpTriggerValid), .LSSTriggerValid(LSSTriggerValid),
837
                      .ITriggerValid(ITriggerValid), .WpQualifValid(WpQualifValid),
838
                      .BpQualifValid(BpQualifValid), .LSSQualifValid(LSSQualifValid),
839
                      .IQualifValid(IQualifValid),
840
                      .WpStop(WpStop), .BpStop(BpStop), .LSSStop(LSSStop), .IStop(IStop),
841 5 mohor
                      .StopOper(StopOper), .WpStopValid(WpStopValid), .BpStopValid(BpStopValid),
842
                      .LSSStopValid(LSSStopValid), .IStopValid(IStopValid),
843 2 mohor
                      `endif
844 47 mohor
                      .risc_stall(RiscStall_reg), .risc_reset(RiscReset_reg), .mon_cntl_o(mon_cntl_o)
845 5 mohor
 
846 2 mohor
                     );
847
 
848
/**********************************************************************************
849
*                                                                                 *
850
*   End: Connecting Registers                                                     *
851
*                                                                                 *
852
**********************************************************************************/
853
 
854
 
855
/**********************************************************************************
856
*                                                                                 *
857
*   Connecting CRC module                                                         *
858
*                                                                                 *
859
**********************************************************************************/
860 18 mohor
wire AsyncResetCrc = trst;
861 9 mohor
wire SyncResetCrc = UpdateDR_q;
862 2 mohor
wire [7:0] CalculatedCrcIn;     // crc calculated from the input data (shifted in)
863
 
864 30 mohor
assign BitCounter_Lt4   = BitCounter<4;
865
assign BitCounter_Eq5   = BitCounter==5;
866
assign BitCounter_Eq32  = BitCounter==32;
867
assign BitCounter_Lt38  = BitCounter<38;
868
assign BitCounter_Lt65  = BitCounter<65;
869
 
870
`ifdef TRACE_ENABLED
871
  assign BitCounter_Lt40 = BitCounter<40;
872
`endif
873
 
874
 
875 2 mohor
wire EnableCrcIn = ShiftDR &
876 30 mohor
                  ( (CHAIN_SELECTSelected                 & BitCounter_Lt4) |
877
                    ((DEBUGSelected & RegisterScanChain)  & BitCounter_Lt38)|
878
                    ((DEBUGSelected & RiscDebugScanChain) & BitCounter_Lt65)|
879
                    ((DEBUGSelected & WishboneScanChain)  & BitCounter_Lt65)
880 9 mohor
                  );
881 2 mohor
 
882
wire EnableCrcOut= ShiftDR &
883 9 mohor
                   (
884 30 mohor
                    ((DEBUGSelected & RegisterScanChain)  & BitCounter_Lt38)|
885
                    ((DEBUGSelected & RiscDebugScanChain) & BitCounter_Lt65)|
886
                    ((DEBUGSelected & WishboneScanChain)  & BitCounter_Lt65)
887 2 mohor
                    `ifdef TRACE_ENABLED
888 30 mohor
                                                                            |
889
                    ((DEBUGSelected & TraceTestScanChain) & BitCounter_Lt40)
890 2 mohor
                    `endif
891 9 mohor
                   );
892 2 mohor
 
893
// Calculating crc for input data
894 44 mohor
dbg_crc8_d1 crc1 (.data(tdi), .enable_crc(EnableCrcIn), .reset(AsyncResetCrc), .sync_rst_crc(SyncResetCrc),
895
                  .crc_out(CalculatedCrcIn), .clk(tck));
896 2 mohor
 
897
// Calculating crc for output data
898 44 mohor
dbg_crc8_d1 crc2 (.data(TDOData), .enable_crc(EnableCrcOut), .reset(AsyncResetCrc), .sync_rst_crc(SyncResetCrc),
899
                  .crc_out(CalculatedCrcOut), .clk(tck));
900 2 mohor
 
901
 
902
// Generating CrcMatch signal
903 36 mohor
always @ (posedge tck or posedge trst)
904 2 mohor
begin
905 18 mohor
  if(trst)
906 2 mohor
    CrcMatch <=#Tp 1'b0;
907
  else
908
  if(Exit1DR)
909
    begin
910
      if(CHAIN_SELECTSelected)
911
        CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[11:4];
912
      else
913 30 mohor
        begin
914
          if(RegisterScanChain)
915
            CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[45:38];
916
          else
917
          if(RiscDebugScanChain)
918
            CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[72:65];
919
          else
920
          if(WishboneScanChain)
921
            CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[72:65];
922
        end
923 2 mohor
    end
924
end
925
 
926
 
927
// Active chain
928
assign RegisterScanChain   = Chain == `REGISTER_SCAN_CHAIN;
929
assign RiscDebugScanChain  = Chain == `RISC_DEBUG_CHAIN;
930 12 mohor
assign WishboneScanChain   = Chain == `WISHBONE_SCAN_CHAIN;
931 2 mohor
 
932
`ifdef TRACE_ENABLED
933
  assign TraceTestScanChain  = Chain == `TRACE_TEST_CHAIN;
934
`endif
935
 
936
/**********************************************************************************
937
*                                                                                 *
938
*   End: Connecting CRC module                                                    *
939
*                                                                                 *
940
**********************************************************************************/
941
 
942
/**********************************************************************************
943
*                                                                                 *
944
*   Connecting trace module                                                       *
945
*                                                                                 *
946
**********************************************************************************/
947
`ifdef TRACE_ENABLED
948 11 mohor
  dbg_trace dbgTrace1(.Wp(wp_i), .Bp(bp_i), .DataIn(risc_data_i), .OpSelect(opselect_trace),
949 9 mohor
                      .LsStatus(lsstatus_i), .IStatus(istatus_i), .RiscStall_O(RiscStall_trace),
950 18 mohor
                      .Mclk(risc_clk_i), .Reset(wb_rst_i), .TraceChain(TraceChain),
951 8 mohor
                      .ContinMode(ContinMode), .TraceEnable_reg(TraceEnable),
952 5 mohor
                      .WpTrigger(WpTrigger),
953 2 mohor
                      .BpTrigger(BpTrigger), .LSSTrigger(LSSTrigger), .ITrigger(ITrigger),
954
                      .TriggerOper(TriggerOper), .WpQualif(WpQualif), .BpQualif(BpQualif),
955
                      .LSSQualif(LSSQualif), .IQualif(IQualif), .QualifOper(QualifOper),
956 5 mohor
                      .RecordPC(RecordPC), .RecordLSEA(RecordLSEA),
957
                      .RecordLDATA(RecordLDATA), .RecordSDATA(RecordSDATA),
958
                      .RecordReadSPR(RecordReadSPR), .RecordWriteSPR(RecordWriteSPR),
959
                      .RecordINSTR(RecordINSTR),
960 2 mohor
                      .WpTriggerValid(WpTriggerValid), .BpTriggerValid(BpTriggerValid),
961
                      .LSSTriggerValid(LSSTriggerValid), .ITriggerValid(ITriggerValid),
962
                      .WpQualifValid(WpQualifValid), .BpQualifValid(BpQualifValid),
963
                      .LSSQualifValid(LSSQualifValid), .IQualifValid(IQualifValid),
964 9 mohor
                      .ReadBuffer(ReadTraceBufferPulse),
965 2 mohor
                      .WpStop(WpStop), .BpStop(BpStop), .LSSStop(LSSStop), .IStop(IStop),
966
                      .StopOper(StopOper), .WpStopValid(WpStopValid), .BpStopValid(BpStopValid),
967
                      .LSSStopValid(LSSStopValid), .IStopValid(IStopValid)
968
                     );
969
`endif
970
/**********************************************************************************
971
*                                                                                 *
972
*   End: Connecting trace module                                                  *
973
*                                                                                 *
974
**********************************************************************************/
975
 
976
 
977
 
978 9 mohor
endmodule

powered by: WebSVN 2.1.0

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