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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [trunk/] [rtl/] [verilog/] [dbg_top.v] - Blame information for rev 67

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

powered by: WebSVN 2.1.0

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