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 36

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

powered by: WebSVN 2.1.0

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