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 44

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

powered by: WebSVN 2.1.0

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