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

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [rtl/] [adv_debug_sys/] [Hardware/] [adv_dbg_if/] [rtl/] [verilog/] [adbg_or1k_module.v] - Blame information for rev 21

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 xianfeng
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  adbg_or1k_module.v                                          ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the SoC Advanced Debug Interface.      ////
7
////                                                              ////
8
////  Author(s):                                                  ////
9
////       Nathan Yawn (nathan.yawn@opencores.org)                ////
10
////                                                              ////
11
////                                                              ////
12
////                                                              ////
13
//////////////////////////////////////////////////////////////////////
14
////                                                              ////
15
//// Copyright (C) 2008 - 2010       Authors                      ////
16
////                                                              ////
17
//// This source file may be used and distributed without         ////
18
//// restriction provided that this copyright statement is not    ////
19
//// removed from the file and that any derivative work contains  ////
20
//// the original copyright notice and the associated disclaimer. ////
21
////                                                              ////
22
//// This source file is free software; you can redistribute it   ////
23
//// and/or modify it under the terms of the GNU Lesser General   ////
24
//// Public License as published by the Free Software Foundation; ////
25
//// either version 2.1 of the License, or (at your option) any   ////
26
//// later version.                                               ////
27
////                                                              ////
28
//// This source is distributed in the hope that it will be       ////
29
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
30
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
31
//// PURPOSE.  See the GNU Lesser General Public License for more ////
32
//// details.                                                     ////
33
////                                                              ////
34
//// You should have received a copy of the GNU Lesser General    ////
35
//// Public License along with this source; if not, download it   ////
36
//// from http://www.opencores.org/lgpl.shtml                     ////
37
////                                                              ////
38
//////////////////////////////////////////////////////////////////////
39
//
40
// CVS Revision History
41
//
42
// $Log: adbg_or1k_module.v,v $
43
// Revision 1.5  2010-01-13 00:55:45  Nathan
44
// Created hi-speed mode for burst reads.  This will probably be most beneficial to the OR1K module, as GDB does a burst read of all the GPRs each time a microinstruction is single-stepped.
45
//
46
// Revision 1.2  2009/05/17 20:54:56  Nathan
47
// Changed email address to opencores.org
48
//
49
// Revision 1.1  2008/07/22 20:28:31  Nathan
50
// Changed names of all files and modules (prefixed an a, for advanced).  Cleanup, indenting.  No functional changes.
51
//
52
// Revision 1.7  2008/07/11 08:13:29  Nathan
53
// Latch opcode on posedge, like other signals.  This fixes a problem 
54
// when the module is used with a Xilinx BSCAN TAP.  Added signals to 
55
// allow modules to inhibit latching of a new active module by the top 
56
// module.  This allows the sub-modules to force the top level module 
57
// to ignore the command present in the input shift register after e.g. 
58
// a burst read.
59
//
60
 
61
 
62
`include "adbg_defines.v"
63
`include "adbg_or1k_defines.v"
64
 
65
// Module interface
66
module adbg_or1k_module (
67
                         // JTAG signals
68
                         tck_i,
69
                         module_tdo_o,
70
                         tdi_i,
71
 
72
                         // TAP states
73
                         capture_dr_i,
74
                         shift_dr_i,
75
                         update_dr_i,
76
 
77
                         data_register_i,  // the data register is at top level, shared between all modules
78
                         module_select_i,
79
                         top_inhibit_o,
80
                         rst_i,
81
 
82
                         // Interfate to the OR1K debug unit
83
                         cpu_clk_i,
84
                         cpu_addr_o,
85
                         cpu_data_i,
86
                         cpu_data_o,
87
                         cpu_bp_i,
88
                         cpu_stall_o,
89
                         cpu_stb_o,
90
                         cpu_we_o,
91
                         cpu_ack_i,
92
                         cpu_rst_o
93
                         );
94
 
95
   // JTAG signals
96
   input         tck_i;
97
   output        module_tdo_o;
98
   input         tdi_i;  // This is only used by the CRC module - data_register_i[MSB] is delayed a cycle
99
 
100
   // TAP states
101
   input         capture_dr_i;
102
   input         shift_dr_i;
103
   input         update_dr_i;
104
 
105
   input [52:0]  data_register_i;
106
   input         module_select_i;
107
   output        top_inhibit_o;
108
   input         rst_i;
109
 
110
   // WISHBONE master interface
111
   input         cpu_clk_i;    // 'bus' style interface to SPRs
112
   output [31:0] cpu_addr_o;
113
   input [31:0]  cpu_data_i;
114
   output [31:0] cpu_data_o;
115
   output        cpu_stb_o;
116
   output        cpu_we_o;
117
   input         cpu_ack_i;
118
   output        cpu_rst_o;  // control lines
119
   input         cpu_bp_i;
120
   output        cpu_stall_o;
121
 
122
   // Declare inputs / outputs as wires / registers
123
   reg           module_tdo_o;
124
   reg           top_inhibit_o;
125
 
126
 
127
   // Registers to hold state etc.
128
   reg [31:0]     address_counter;     // Holds address for next Wishbone access
129
   reg [5:0]      bit_count;            // How many bits have been shifted in/out
130
   reg [15:0]     word_count;          // bytes remaining in current burst command
131
   reg [3:0]      operation;            // holds the current command (rd/wr, word size)
132
   reg [31:0]     data_out_shift_reg;  // parallel-load output shift register
133
   reg [`DBG_OR1K_REGSELECT_SIZE-1:0] internal_register_select;  // Holds index of currently selected register
134
   wire [1:0]                          internal_reg_status;  // Holds CPU stall and reset status - signal is output of separate module
135
 
136
 
137
   // Control signals for the various counters / registers / state machines
138
   reg                                addr_sel;          // Selects data for address_counter. 0 = data_register_i, 1 = incremented address count
139
   reg                                addr_ct_en;        // Enable signal for address counter register
140
   reg                                op_reg_en;         // Enable signal for 'operation' register
141
   reg                                bit_ct_en;         // enable bit counter
142
   reg                                bit_ct_rst;        // reset (zero) bit count register
143
   reg                                word_ct_sel;       // Selects data for byte counter.  0 = data_register_i, 1 = decremented byte count
144
   reg                                word_ct_en;        // Enable byte counter register
145
   reg                                out_reg_ld_en;     // Enable parallel load of data_out_shift_reg
146
   reg                                out_reg_shift_en;  // Enable shift of data_out_shift_reg
147
   reg                                out_reg_data_sel;  // 0 = BIU data, 1 = internal register data
148
   reg [1:0]                           tdo_output_sel;  // Selects signal to send to TDO.  0 = ready bit, 1 = output register, 2 = CRC match, 3 = CRC shift reg.
149
   reg                                biu_strobe;      // Indicates that the bus unit should latch data and start a transaction
150
   reg                                crc_clr;         // resets CRC module
151
   reg                                crc_en;          // does 1-bit iteration in CRC module
152
   reg                                crc_in_sel;      // selects incoming write data (=0) or outgoing read data (=1)as input to CRC module
153
   reg                                crc_shift_en;    // CRC reg is also it's own output shift register; this enables a shift
154
   reg                                regsel_ld_en;    // Reg. select register load enable
155
   reg                                intreg_ld_en;    // load enable for internal registers
156
 
157
 
158
   // Status signals
159
   wire                               word_count_zero;   // true when byte counter is zero
160
   wire                               bit_count_max;     // true when bit counter is equal to current word size
161
   wire                               module_cmd;        // inverse of MSB of data_register_i. 1 means current cmd not for top level (but is for us)
162
   wire                               biu_ready;         // indicates that the BIU has finished the last command
163
   wire                               burst_instruction; // True when the input_data_i reg has a valid burst instruction for this module
164
   wire                               intreg_instruction; // True when the input_data_i reg has a valid internal register instruction
165
   wire                               intreg_write;       // True when the input_data_i reg has an internal register write op
166
   wire                               rd_op;              // True when operation in the opcode reg is a read, false when a write
167
   wire                               crc_match;         // indicates whether data_register_i matches computed CRC
168
   wire                               bit_count_32;      // true when bit count register == 32, for CRC after burst writes
169
 
170
   // Intermediate signals
171
   wire [5:0]                          word_size_bits;         // 8,16, or 32.  Decoded from 'operation'
172
   wire [2:0]                          address_increment;      // How much to add to the address counter each iteration 
173
   wire [32:0]                         incremented_address;   // value of address counter plus 'word_size'
174
   wire [31:0]                         data_to_addr_counter;  // output of the mux in front of the address counter inputs
175
   wire [15:0]                         data_to_word_counter;  // output of the mux in front of the byte counter input
176
   wire [15:0]                         decremented_word_count;
177
   wire [31:0]                         address_data_in;       // from data_register_i
178
   wire [15:0]                         count_data_in;         // from data_register_i
179
   wire [3:0]                          operation_in;          // from data_register_i
180
   wire [31:0]                         data_to_biu;           // from data_register_i
181
   wire [31:0]                         data_from_biu;         // to data_out_shift_register
182
   wire [31:0]                         crc_data_out;          // output of CRC module, to output shift register
183
   wire                               crc_data_in;                  // input to CRC module, either data_register_i[52] or data_out_shift_reg[0]
184
   wire                               crc_serial_out;
185
   wire [`DBG_OR1K_REGSELECT_SIZE-1:0] reg_select_data; // from data_register_i, input to internal register select register
186
   wire [31:0]                          out_reg_data;           // parallel input to the output shift register
187
   reg [31:0]                           data_from_internal_reg;  // data from internal reg. MUX to output shift register
188
   wire                                status_reg_wr;
189
 
190
 
191
   /////////////////////////////////////////////////
192
   // Combinatorial assignments
193
 
194
       assign module_cmd = ~(data_register_i[52]);
195
   assign     operation_in = data_register_i[51:48];
196
   assign     address_data_in = data_register_i[47:16];
197
   assign     count_data_in = data_register_i[15:0];
198
`ifdef ADBG_USE_HISPEED
199
   assign     data_to_biu = {tdi_i,data_register_i[52:22]};
200
`else
201
   assign     data_to_biu = data_register_i[52:21];
202
`endif
203
   assign     reg_select_data = data_register_i[47:(47-(`DBG_OR1K_REGSELECT_SIZE-1))];
204
 
205
   ////////////////////////////////////////////////
206
              // Operation decoder
207
 
208
   // These are only used before the operation is latched, so decode them from operation_in
209
   assign     burst_instruction = (operation_in == `DBG_OR1K_CMD_BWRITE32) | (operation_in == `DBG_OR1K_CMD_BREAD32);
210
   assign     intreg_instruction = ((operation_in == `DBG_OR1K_CMD_IREG_WR) | (operation_in == `DBG_OR1K_CMD_IREG_SEL));
211
   assign     intreg_write = (operation_in == `DBG_OR1K_CMD_IREG_WR);
212
 
213
   // These are constant, the CPU module only does 32-bit accesses
214
   assign     word_size_bits = 5'd31;  // Bits is actually bits-1, to make the FSM easier
215
   assign     address_increment = 3'd1;  // This is only used to increment the address.  SPRs are word-addressed.
216
 
217
   // This is the only thing that actually needs to be saved and 'decoded' from the latched opcode
218
   // It goes to the BIU each time a transaction is started.
219
   assign     rd_op = operation[2];
220
 
221
 
222
   ////////////////////////////////////////////////
223
   // Module-internal register select register (no, that's not redundant.)
224
   // Also internal register output MUX
225
 
226
   always @ (posedge tck_i or posedge rst_i)
227
     begin
228
        if(rst_i) internal_register_select = 1'h0;
229
        else if(regsel_ld_en) internal_register_select = reg_select_data;
230
     end
231
 
232
   // This is completely unnecessary here, since the module has only 1 internal
233
   // register.  However, to make the module expandable, it is included anyway.
234
   always @ (internal_register_select or internal_reg_status)
235
     begin
236
        case(internal_register_select)
237
          `DBG_OR1K_INTREG_STATUS: data_from_internal_reg = {30'h0, internal_reg_status};
238
          default: data_from_internal_reg = {30'h0, internal_reg_status};
239
        endcase
240
     end
241
 
242
 
243
 
244
   ////////////////////////////////////////////////////////////////////
245
   // Module-internal registers
246
   // These have generic read/write/select code, but
247
   // individual registers may have special behavior, defined here.
248
 
249
   // This is the status register, which holds the reset and stall states.
250
 
251
   assign status_reg_wr = (intreg_ld_en & (reg_select_data == `DBG_OR1K_INTREG_STATUS));
252
 
253
   adbg_or1k_status_reg or1k_statusreg_i (
254
                                     .data_i(data_register_i[(47-`DBG_OR1K_REGSELECT_SIZE):(47-(`DBG_OR1K_REGSELECT_SIZE+1))]),
255
                                     .we_i(status_reg_wr),
256
                                     .tck_i(tck_i),
257
                                     .bp_i(cpu_bp_i),
258
                                     .rst_i(rst_i),
259
                                     .cpu_clk_i(cpu_clk_i),
260
                                     .ctrl_reg_o(internal_reg_status),
261
                                     .cpu_stall_o(cpu_stall_o),
262
                                     .cpu_rst_o(cpu_rst_o)
263
                                     );
264
 
265
 
266
   ///////////////////////////////////////////////
267
   // Address counter
268
 
269
     assign data_to_addr_counter = (addr_sel) ? incremented_address[31:0] : address_data_in;
270
   assign   incremented_address = address_counter + address_increment;
271
 
272
   // Technically, since this data (sometimes) comes from the input shift reg, we should latch on
273
   // negedge, per the JTAG spec. But that makes things difficult when incrementing.
274
   always @ (posedge tck_i or posedge rst_i)  // JTAG spec specifies latch on negative edge in UPDATE_DR state
275
     begin
276
        if(rst_i)
277
          address_counter <= 32'h0;
278
        else if(addr_ct_en)
279
          address_counter <= data_to_addr_counter;
280
     end
281
 
282
   ////////////////////////////////////////
283
     // Opcode latch
284
 
285
   always @ (posedge tck_i or posedge rst_i)  // JTAG spec specifies latch on negative edge in UPDATE_DR state
286
     begin
287
        if(rst_i)
288
          operation <= 4'h0;
289
        else if(op_reg_en)
290
          operation <= operation_in;
291
     end
292
 
293
   //////////////////////////////////////
294
     // Bit counter
295
 
296
   always @ (posedge tck_i or posedge rst_i)
297
     begin
298
 
299
        if(rst_i)             bit_count <= 6'h0;
300
        else if(bit_ct_rst)  bit_count <= 6'h0;
301
        else if(bit_ct_en)    bit_count <= bit_count + 6'h1;
302
 
303
     end
304
 
305
   assign bit_count_max = (bit_count == word_size_bits) ? 1'b1 : 1'b0 ;
306
   assign bit_count_32 = (bit_count == 6'h20) ? 1'b1 : 1'b0;
307
 
308
   ////////////////////////////////////////
309
   // Word counter
310
 
311
   assign data_to_word_counter = (word_ct_sel) ?  decremented_word_count : count_data_in;
312
   assign decremented_word_count = word_count - 16'h1;
313
 
314
   // Technically, since this data (sometimes) comes from the input shift reg, we should latch on
315
   // negedge, per the JTAG spec. But that makes things difficult when incrementing.
316
   always @ (posedge tck_i or posedge rst_i)  // JTAG spec specifies latch on negative edge in UPDATE_DR state
317
     begin
318
        if(rst_i)
319
          word_count <= 16'h0;
320
        else if(word_ct_en)
321
          word_count <= data_to_word_counter;
322
     end
323
 
324
   assign word_count_zero = (word_count == 16'h0);
325
 
326
   /////////////////////////////////////////////////////
327
                            // Output register and TDO output MUX
328
 
329
                            assign out_reg_data = (out_reg_data_sel) ? data_from_internal_reg : data_from_biu;
330
 
331
   always @ (posedge tck_i or posedge rst_i)
332
     begin
333
        if(rst_i) data_out_shift_reg <= 32'h0;
334
        else if(out_reg_ld_en) data_out_shift_reg <= out_reg_data;
335
        else if(out_reg_shift_en) data_out_shift_reg <= {1'b0, data_out_shift_reg[31:1]};
336
     end
337
 
338
 
339
   always @ (tdo_output_sel or data_out_shift_reg[0] or biu_ready or crc_match or crc_serial_out)
340
     begin
341
        if(tdo_output_sel == 2'h0) module_tdo_o <= biu_ready;
342
        else if(tdo_output_sel == 2'h1) module_tdo_o <= data_out_shift_reg[0];
343
        else if(tdo_output_sel == 2'h2) module_tdo_o <= crc_match;
344
        else module_tdo_o <= crc_serial_out;
345
     end
346
 
347
   ////////////////////////////////////////
348
     // Bus Interface Unit (to OR1K SPR bus)
349
   // It is assumed that the BIU has internal registers, and will
350
   // latch address, operation, and write data on rising clock edge 
351
   // when strobe is asserted
352
 
353
   adbg_or1k_biu or1k_biu_i (
354
                             // Debug interface signals
355
                             .tck_i           (tck_i),
356
                             .rst_i           (rst_i),
357
                             .data_i          (data_to_biu),
358
                             .data_o          (data_from_biu),
359
                             .addr_i          (address_counter),
360
                             .strobe_i        (biu_strobe),
361
                             .rd_wrn_i        (rd_op),           // If 0, then write op
362
                             .rdy_o           (biu_ready),
363
                             //  This bus has no error signal
364
 
365
                             // OR1K SPR bus signals
366
                             .cpu_clk_i(cpu_clk_i),
367
                             .cpu_addr_o(cpu_addr_o),
368
                             .cpu_data_i(cpu_data_i),
369
                             .cpu_data_o(cpu_data_o),
370
                             .cpu_stb_o(cpu_stb_o),
371
                             .cpu_we_o(cpu_we_o),
372
                             .cpu_ack_i(cpu_ack_i)
373
                             );
374
 
375
 
376
 
377
   /////////////////////////////////////
378
     // CRC module
379
 
380
     assign crc_data_in = (crc_in_sel) ? tdi_i : data_out_shift_reg[0];  // MUX, write or read data
381
 
382
   adbg_crc32 or1k_crc_i
383
     (
384
      .clk(tck_i),
385
      .data(crc_data_in),
386
      .enable(crc_en),
387
      .shift(crc_shift_en),
388
      .clr(crc_clr),
389
      .rst(rst_i),
390
      .crc_out(crc_data_out),
391
      .serial_out(crc_serial_out)
392
      );
393
 
394
   assign   crc_match = (data_register_i[52:21] == crc_data_out) ? 1'b1 : 1'b0;
395
 
396
   ////////////////////////////////////////
397
   // Control FSM
398
 
399
   // Definition of machine state values.
400
   // Don't worry too much about the state encoding, the synthesis tool
401
   // will probably re-encode it anyway.
402
 
403
`define STATE_idle     4'h0
404
`define STATE_Rbegin   4'h1
405
`define STATE_Rready   4'h2
406
`define STATE_Rstatus  4'h3
407
`define STATE_Rburst   4'h4
408
`define STATE_Wready   4'h5
409
`define STATE_Wwait    4'h6
410
`define STATE_Wburst   4'h7
411
`define STATE_Wstatus  4'h8
412
`define STATE_Rcrc     4'h9
413
`define STATE_Wcrc     4'ha
414
`define STATE_Wmatch   4'hb
415
 
416
   reg [3:0] module_state;       // FSM state
417
   reg [3:0] module_next_state;  // combinatorial signal, not actually a register
418
 
419
 
420
 
421
   // sequential part of the FSM
422
   always @ (posedge tck_i or posedge rst_i)
423
     begin
424
        if(rst_i)
425
          module_state <= `STATE_idle;
426
        else
427
          module_state <= module_next_state;
428
     end
429
 
430
 
431
   // Determination of next state; purely combinatorial
432
   always @ (module_state or module_select_i or update_dr_i or capture_dr_i or shift_dr_i or operation_in[2]
433
             or word_count_zero or bit_count_max or data_register_i[52] or bit_count_32 or biu_ready
434
             or module_cmd or intreg_write or decremented_word_count or burst_instruction)
435
     begin
436
        case(module_state)
437
          `STATE_idle:
438
            begin
439
               if(module_cmd && module_select_i && update_dr_i && burst_instruction && operation_in[2]) module_next_state <= `STATE_Rbegin;
440
               else if(module_cmd && module_select_i && update_dr_i && burst_instruction) module_next_state <= `STATE_Wready;
441
               else module_next_state <= `STATE_idle;
442
            end
443
 
444
          `STATE_Rbegin:
445
            begin
446
               if(word_count_zero) module_next_state <= `STATE_idle;  // set up a burst of size 0, illegal.
447
               else module_next_state <= `STATE_Rready;
448
            end
449
          `STATE_Rready:
450
            begin
451
               if(module_select_i && capture_dr_i) module_next_state <= `STATE_Rstatus;
452
               else module_next_state <= `STATE_Rready;
453
            end
454
          `STATE_Rstatus:
455
            begin
456
               if(update_dr_i) module_next_state <= `STATE_idle;
457
               else if (biu_ready) module_next_state <= `STATE_Rburst;
458
               else module_next_state <= `STATE_Rstatus;
459
            end
460
          `STATE_Rburst:
461
            begin
462
               if(update_dr_i) module_next_state <= `STATE_idle;
463
               else if(bit_count_max && word_count_zero) module_next_state <= `STATE_Rcrc;
464
`ifndef ADBG_USE_HISPEED
465
               else if(bit_count_max) module_next_state <= `STATE_Rstatus;
466
`endif
467
               else module_next_state <= `STATE_Rburst;
468
            end
469
          `STATE_Rcrc:
470
            begin
471
               if(update_dr_i) module_next_state <= `STATE_idle;
472
               // This doubles as the 'recovery' state, so stay here until update_dr_i.
473
               else module_next_state <= `STATE_Rcrc;
474
            end
475
 
476
          `STATE_Wready:
477
            begin
478
               if(word_count_zero) module_next_state <= `STATE_idle;
479
               else if(module_select_i && capture_dr_i) module_next_state <= `STATE_Wwait;
480
               else module_next_state <= `STATE_Wready;
481
            end
482
          `STATE_Wwait:
483
            begin
484
               if(update_dr_i)  module_next_state <= `STATE_idle;  // client terminated early
485
               else if(module_select_i && data_register_i[52]) module_next_state <= `STATE_Wburst; // Got a start bit
486
               else module_next_state <= `STATE_Wwait;
487
            end
488
          `STATE_Wburst:
489
            begin
490
               if(update_dr_i)  module_next_state <= `STATE_idle;  // client terminated early    
491
               else if(bit_count_max)
492
                 begin
493
`ifdef ADBG_USE_HISPEED
494
                        if(word_count_zero) module_next_state <= `STATE_Wcrc;
495
                        else module_next_state <= `STATE_Wburst;
496
`else
497
                 module_next_state <= `STATE_Wstatus;
498
`endif
499
                 end
500
               else module_next_state <= `STATE_Wburst;
501
            end
502
          `STATE_Wstatus:
503
            begin
504
               if(update_dr_i)  module_next_state <= `STATE_idle;  // client terminated early    
505
               else if(word_count_zero) module_next_state <= `STATE_Wcrc;
506
               // can't wait until bus ready if multiple devices in chain...
507
               // Would have to read postfix_bits, then send another start bit and push it through
508
               // prefix_bits...potentially very inefficient.
509
               else module_next_state <= `STATE_Wburst;
510
            end
511
 
512
          `STATE_Wcrc:
513
            begin
514
               if(update_dr_i)  module_next_state <= `STATE_idle;  // client terminated early
515
               else if(bit_count_32) module_next_state <= `STATE_Wmatch;
516
               else module_next_state <= `STATE_Wcrc;
517
            end
518
 
519
          `STATE_Wmatch:
520
            begin
521
               if(update_dr_i)  module_next_state <= `STATE_idle;
522
               // This doubles as our recovery state, stay here until update_dr_i
523
               else module_next_state <= `STATE_Wmatch;
524
            end
525
 
526
          default: module_next_state <= `STATE_idle;  // shouldn't actually happen...
527
        endcase
528
     end
529
 
530
 
531
   // Outputs of state machine, pure combinatorial
532
   always @ (module_state or module_next_state or module_select_i or update_dr_i or capture_dr_i or shift_dr_i or operation_in[2]
533
             or word_count_zero or bit_count_max or data_register_i[52] or biu_ready or intreg_instruction
534
             or module_cmd or intreg_write or decremented_word_count)
535
     begin
536
        // Default everything to 0, keeps the case statement simple
537
        addr_sel <= 1'b1;  // Selects data for address_counter. 0 = data_register_i, 1 = incremented address count
538
        addr_ct_en <= 1'b0;  // Enable signal for address counter register
539
        op_reg_en <= 1'b0;  // Enable signal for 'operation' register
540
        bit_ct_en <= 1'b0;  // enable bit counter
541
        bit_ct_rst <= 1'b0;  // reset (zero) bit count register
542
        word_ct_sel <= 1'b1;  // Selects data for byte counter.  0 = data_register_i, 1 = decremented byte count
543
        word_ct_en <= 1'b0;   // Enable byte counter register
544
        out_reg_ld_en <= 1'b0;  // Enable parallel load of data_out_shift_reg
545
        out_reg_shift_en <= 1'b0;  // Enable shift of data_out_shift_reg
546
        tdo_output_sel <= 2'b1;   // 1 = data reg, 0 = biu_ready, 2 = crc_match, 3 = CRC data
547
        biu_strobe <= 1'b0;
548
        crc_clr <= 1'b0;
549
        crc_en <= 1'b0;      // add the input bit to the CRC calculation
550
        crc_in_sel <= 1'b0;  // 0 = tdo, 1 = tdi
551
        crc_shift_en <= 1'b0;
552
        out_reg_data_sel <= 1'b1;  // 0 = BIU data, 1 = internal register data
553
        regsel_ld_en <= 1'b0;
554
        intreg_ld_en <= 1'b0;
555
        top_inhibit_o <= 1'b0;  // Don't disable the top-level module in the default case
556
 
557
        case(module_state)
558
          `STATE_idle:
559
            begin
560
               addr_sel <= 1'b0;
561
               word_ct_sel <= 1'b0;
562
 
563
               // Operations for internal registers - stay in idle state
564
               if(module_select_i & shift_dr_i) out_reg_shift_en <= 1'b1; // For module regs
565
               if(module_select_i & capture_dr_i)
566
                 begin
567
                    out_reg_data_sel <= 1'b1;  // select internal register data
568
                    out_reg_ld_en <= 1'b1;   // For module regs
569
                 end
570
               if(module_select_i & module_cmd & update_dr_i) begin
571
                  if(intreg_instruction) regsel_ld_en <= 1'b1;  // For module regs
572
                  if(intreg_write)       intreg_ld_en <= 1'b1;  // For module regs
573
               end
574
 
575
               // Burst operations
576
               if(module_next_state != `STATE_idle) begin  // Do the same to receive read or write opcode
577
                  addr_ct_en <= 1'b1;
578
                  op_reg_en <= 1'b1;
579
                  bit_ct_rst <= 1'b1;
580
                  word_ct_en <= 1'b1;
581
                  crc_clr <= 1'b1;
582
               end
583
            end
584
 
585
          `STATE_Rbegin:
586
            begin
587
               if(!word_count_zero) begin  // Start a biu read transaction
588
                  biu_strobe <= 1'b1;
589
                  addr_sel <= 1'b1;
590
                  addr_ct_en <= 1'b1;
591
               end
592
            end
593
 
594
          `STATE_Rready:
595
            ; // Just a wait state
596
 
597
          `STATE_Rstatus:
598
            begin
599
               tdo_output_sel <= 2'h0;
600
               top_inhibit_o <= 1'b1;    // in case of early termination
601
 
602
               if (module_next_state == `STATE_Rburst)
603
               begin
604
                 out_reg_data_sel <= 1'b0;  // select BIU data
605
                 out_reg_ld_en <= 1'b1;
606
                 bit_ct_rst <= 1'b1;
607
                 word_ct_sel <= 1'b1;
608
                 word_ct_en <= 1'b1;
609
                 if(!(decremented_word_count == 0) && !word_count_zero)  // Start a biu read transaction
610
                 begin
611
                   biu_strobe <= 1'b1;
612
                   addr_sel <= 1'b1;
613
                   addr_ct_en <= 1'b1;
614
                 end
615
               end
616
            end
617
 
618
          `STATE_Rburst:
619
            begin
620
               tdo_output_sel <= 2'h1;
621
               out_reg_shift_en <= 1'b1;
622
               bit_ct_en <= 1'b1;
623
               crc_en <= 1'b1;
624
               crc_in_sel <= 1'b0;  // read data in output shift register LSB (tdo)
625
               top_inhibit_o <= 1'b1;    // in case of early termination
626
 
627
`ifdef ADBG_USE_HISPEED
628
               if(bit_count_max)
629
               begin
630
                 out_reg_data_sel <= 1'b0;  // select BIU data
631
                 out_reg_ld_en <= 1'b1;
632
                 bit_ct_rst <= 1'b1;
633
                 word_ct_sel <= 1'b1;
634
                 word_ct_en <= 1'b1;
635
                 if(!(decremented_word_count == 0) && !word_count_zero)  // Start a biu read transaction
636
                 begin
637
                   biu_strobe <= 1'b1;
638
                   addr_sel <= 1'b1;
639
                   addr_ct_en <= 1'b1;
640
                 end
641
               end
642
`endif
643
            end
644
 
645
          `STATE_Rcrc:
646
            begin
647
               // Just shift out the data, don't bother counting, we don't move on until update_dr_i
648
               tdo_output_sel <= 2'h3;
649
               crc_shift_en <= 1'b1;
650
               top_inhibit_o <= 1'b1;
651
            end
652
 
653
          `STATE_Wready:
654
            ; // Just a wait state
655
 
656
          `STATE_Wwait:
657
            begin
658
               tdo_output_sel <= 2'h1;
659
               top_inhibit_o <= 1'b1;    // in case of early termination
660
               if(module_next_state == `STATE_Wburst) begin
661
                  bit_ct_en <= 1'b1;
662
                  word_ct_sel <= 1'b1;  // Pre-decrement the byte count
663
                  word_ct_en <= 1'b1;
664
                  crc_en <= 1'b1;  // CRC gets tdi_i, which is 1 cycle ahead of data_register_i, so we need the bit there now in the CRC
665
                  crc_in_sel <= 1'b1;  // read data from tdi_i
666
               end
667
            end
668
 
669
          `STATE_Wburst:
670
            begin
671
               bit_ct_en <= 1'b1;
672
               tdo_output_sel <= 2'h1;
673
               crc_en <= 1'b1;
674
               crc_in_sel <= 1'b1;  // read data from tdi_i
675
               top_inhibit_o <= 1'b1;    // in case of early termination
676
 
677
`ifdef ADBG_USE_HISPEED
678
               // It would be better to do this in STATE_Wstatus, but we don't use that state 
679
               // if ADBG_USE_HISPEED is defined.  
680
               if(bit_count_max)
681
                      begin
682
                      bit_ct_rst <= 1'b1;  // Zero the bit count
683
                      // start transaction. Can't do this here if not hispeed, biu_ready
684
                      // is the status bit, and it's 0 if we start a transaction here.
685
                      biu_strobe <= 1'b1;  // Start a BIU transaction
686
                      addr_ct_en <= 1'b1;  // Increment thte address counter
687
                      // Also can't dec the byte count yet unless hispeed,
688
                      // that would skip the last word.
689
                      word_ct_sel <= 1'b1;  // Decrement the byte count
690
                      word_ct_en <= 1'b1;
691
                      end
692
`endif
693
            end
694
 
695
          `STATE_Wstatus:
696
            begin
697
               tdo_output_sel <= 2'h0;  // Send the status bit to TDO
698
               // start transaction
699
               biu_strobe <= 1'b1;  // Start a BIU transaction
700
               word_ct_sel <= 1'b1;  // Decrement the byte count
701
               word_ct_en <= 1'b1;
702
               bit_ct_rst <= 1'b1;  // Zero the bit count
703
               addr_ct_en <= 1'b1;  // Increment thte address counter
704
               top_inhibit_o <= 1'b1;    // in case of early termination
705
            end
706
 
707
          `STATE_Wcrc:
708
            begin
709
               bit_ct_en <= 1'b1;
710
               top_inhibit_o <= 1'b1;    // in case of early termination
711
               if(module_next_state == `STATE_Wmatch) tdo_output_sel <= 2'h2;  // This is when the 'match' bit is actually read
712
            end
713
 
714
          `STATE_Wmatch:
715
            begin
716
               tdo_output_sel <= 2'h2;
717
               top_inhibit_o <= 1'b1;    // in case of early termination
718
            end
719
 
720
          default: ;
721
        endcase
722
     end
723
 
724
 
725
endmodule
726
 

powered by: WebSVN 2.1.0

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