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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [tags/] [rel_1/] [rtl/] [verilog/] [dbg_top.v] - Blame information for rev 43

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

powered by: WebSVN 2.1.0

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