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

Subversion Repositories dbg_interface

[/] [dbg_interface/] [trunk/] [rtl/] [verilog/] [dbg_cpu.v] - Blame information for rev 152

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 100 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  dbg_cpu.v                                                   ////
4
////                                                              ////
5
////                                                              ////
6 139 igorm
////  This file is part of the SoC Debug Interface.               ////
7 100 mohor
////  http://www.opencores.org/projects/DebugInterface/           ////
8
////                                                              ////
9
////  Author(s):                                                  ////
10
////       Igor Mohor (igorm@opencores.org)                       ////
11
////                                                              ////
12
////                                                              ////
13
////  All additional information is avaliable in the README.txt   ////
14
////  file.                                                       ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2000 - 2004 Authors                            ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
//
43
// CVS Revision History
44
//
45
// $Log: not supported by cvs2svn $
46 152 igorm
// Revision 1.11  2004/04/07 19:28:55  igorm
47
// Zero is shifted out when CTRL_READ command is active.
48
//
49 150 igorm
// Revision 1.10  2004/04/01 10:22:45  igorm
50
// Signals for easier debugging removed.
51
//
52 143 igorm
// Revision 1.9  2004/03/31 14:34:09  igorm
53
// data_cnt_lim length changed to reduce number of warnings.
54
//
55 141 igorm
// Revision 1.8  2004/03/28 20:27:01  igorm
56
// New release of the debug interface (3rd. release).
57
//
58 139 igorm
// Revision 1.7  2004/01/25 14:04:18  mohor
59
// All flipflops are reset.
60
//
61 123 mohor
// Revision 1.6  2004/01/22 13:58:53  mohor
62
// Port signals are all set to zero after reset.
63
//
64 121 mohor
// Revision 1.5  2004/01/19 07:32:41  simons
65
// Reset values width added because of FV, a good sentence changed because some tools can not handle it.
66
//
67 108 simons
// Revision 1.4  2004/01/17 18:38:11  mohor
68
// cpu_tall_o is set with cpu_stb_o or register.
69
//
70 104 mohor
// Revision 1.3  2004/01/17 18:01:24  mohor
71
// New version.
72
//
73 102 mohor
// Revision 1.2  2004/01/17 17:01:14  mohor
74
// Almost finished.
75
//
76 101 mohor
// Revision 1.1  2004/01/16 14:53:31  mohor
77
// *** empty log message ***
78 100 mohor
//
79
//
80 101 mohor
//
81 139 igorm
 
82 100 mohor
// synopsys translate_off
83
`include "timescale.v"
84
// synopsys translate_on
85
`include "dbg_cpu_defines.v"
86
 
87
// Top module
88
module dbg_cpu(
89
                // JTAG signals
90
                tck_i,
91
                tdi_i,
92
                tdo_o,
93
 
94
                // TAP states
95
                shift_dr_i,
96
                pause_dr_i,
97
                update_dr_i,
98
 
99
                cpu_ce_i,
100
                crc_match_i,
101
                crc_en_o,
102
                shift_crc_o,
103
                rst_i,
104
 
105 139 igorm
                // CPU
106
                cpu_clk_i,
107
                cpu_addr_o, cpu_data_i, cpu_data_o, cpu_bp_i, cpu_stall_o,
108 101 mohor
                cpu_stb_o,
109 139 igorm
                cpu_we_o, cpu_ack_i, cpu_rst_o
110 100 mohor
 
111
              );
112
 
113
// JTAG signals
114
input         tck_i;
115
input         tdi_i;
116
output        tdo_o;
117
 
118
// TAP states
119
input         shift_dr_i;
120
input         pause_dr_i;
121
input         update_dr_i;
122
 
123
input         cpu_ce_i;
124
input         crc_match_i;
125
output        crc_en_o;
126
output        shift_crc_o;
127
input         rst_i;
128 101 mohor
 
129 139 igorm
// CPU
130
input         cpu_clk_i;
131
output [31:0] cpu_addr_o;
132 101 mohor
output [31:0] cpu_data_o;
133
input         cpu_bp_i;
134
output        cpu_stall_o;
135 139 igorm
input  [31:0] cpu_data_i;
136 101 mohor
output        cpu_stb_o;
137
output        cpu_we_o;
138
input         cpu_ack_i;
139
output        cpu_rst_o;
140
 
141 139 igorm
reg           cpu_stb_o;
142
wire          cpu_reg_stall;
143 100 mohor
reg           tdo_o;
144 139 igorm
reg           cpu_ack_q;
145
reg           cpu_ack_csff;
146
reg           cpu_ack_tck;
147 100 mohor
 
148 139 igorm
reg    [31:0] cpu_dat_tmp, cpu_data_dsff;
149
reg    [31:0] cpu_addr_dsff;
150
reg           cpu_we_dsff;
151
reg    [`DBG_CPU_DR_LEN -1 :0] dr;
152
wire          enable;
153 100 mohor
wire          cmd_cnt_en;
154 139 igorm
reg     [`DBG_CPU_CMD_CNT_WIDTH -1:0] cmd_cnt;
155 100 mohor
wire          cmd_cnt_end;
156
reg           cmd_cnt_end_q;
157 139 igorm
reg           addr_len_cnt_en;
158
reg     [5:0] addr_len_cnt;
159
wire          addr_len_cnt_end;
160
reg           addr_len_cnt_end_q;
161
reg           crc_cnt_en;
162
reg     [`DBG_CPU_CRC_CNT_WIDTH -1:0] crc_cnt;
163 100 mohor
wire          crc_cnt_end;
164
reg           crc_cnt_end_q;
165 139 igorm
reg           data_cnt_en;
166
reg    [`DBG_CPU_DATA_CNT_WIDTH:0] data_cnt;
167 141 igorm
reg    [`DBG_CPU_DATA_CNT_LIM_WIDTH:0] data_cnt_limit;
168 100 mohor
wire          data_cnt_end;
169
reg           data_cnt_end_q;
170 139 igorm
reg           crc_match_reg;
171
 
172
reg    [`DBG_CPU_ACC_TYPE_LEN -1:0] acc_type;
173
reg    [`DBG_CPU_ADR_LEN -1:0] adr;
174
reg    [`DBG_CPU_LEN_LEN -1:0] len;
175
reg    [`DBG_CPU_LEN_LEN:0]    len_var;
176
wire   [`DBG_CPU_CTRL_LEN -1:0]ctrl_reg;
177
reg           start_rd_tck;
178
reg           rd_tck_started;
179
reg           start_rd_csff;
180
reg           start_cpu_rd;
181
reg           start_cpu_rd_q;
182
reg           start_wr_tck;
183
reg           start_wr_csff;
184
reg           start_cpu_wr;
185
reg           start_cpu_wr_q;
186
 
187
reg           status_cnt_en;
188 100 mohor
wire          status_cnt_end;
189
 
190 139 igorm
wire          half, long;
191
reg           half_q, long_q;
192 100 mohor
 
193 139 igorm
reg [`DBG_CPU_STATUS_CNT_WIDTH -1:0] status_cnt;
194 100 mohor
 
195 139 igorm
reg [`DBG_CPU_STATUS_LEN -1:0] status;
196 100 mohor
 
197 139 igorm
reg           cpu_overrun, cpu_overrun_csff, cpu_overrun_tck;
198
reg           underrun_tck;
199 100 mohor
 
200 139 igorm
reg           busy_cpu;
201
reg           busy_tck;
202
reg           cpu_end;
203
reg           cpu_end_rst;
204
reg           cpu_end_rst_csff;
205
reg           cpu_end_csff;
206
reg           cpu_end_tck, cpu_end_tck_q;
207
reg           busy_csff;
208
reg           latch_data;
209
reg           update_dr_csff, update_dr_cpu;
210
wire [`DBG_CPU_CTRL_LEN -1:0] cpu_reg_data_i;
211
wire                          cpu_reg_we;
212 101 mohor
 
213 139 igorm
reg           set_addr, set_addr_csff, set_addr_cpu, set_addr_cpu_q;
214
wire   [31:0] input_data;
215
 
216
wire          len_eq_0;
217 100 mohor
wire          crc_cnt_31;
218
 
219 139 igorm
reg           fifo_full;
220
reg     [7:0] mem [0:3];
221
reg           cpu_ce_csff;
222
reg           mem_ptr_init;
223
reg [`DBG_CPU_CMD_LEN -1: 0] curr_cmd;
224
wire          curr_cmd_go;
225
reg           curr_cmd_go_q;
226
wire          curr_cmd_wr_comm;
227
wire          curr_cmd_wr_ctrl;
228
wire          curr_cmd_rd_comm;
229
wire          curr_cmd_rd_ctrl;
230
wire          acc_type_read;
231
wire          acc_type_write;
232 100 mohor
 
233 101 mohor
 
234 100 mohor
assign enable = cpu_ce_i & shift_dr_i;
235
assign crc_en_o = enable & crc_cnt_end & (~status_cnt_end);
236
assign shift_crc_o = enable & status_cnt_end;  // Signals dbg module to shift out the CRC
237
 
238 139 igorm
assign curr_cmd_go      = (curr_cmd == `DBG_CPU_GO) && cmd_cnt_end;
239
assign curr_cmd_wr_comm = (curr_cmd == `DBG_CPU_WR_COMM) && cmd_cnt_end;
240
assign curr_cmd_wr_ctrl = (curr_cmd == `DBG_CPU_WR_CTRL) && cmd_cnt_end;
241
assign curr_cmd_rd_comm = (curr_cmd == `DBG_CPU_RD_COMM) && cmd_cnt_end;
242
assign curr_cmd_rd_ctrl = (curr_cmd == `DBG_CPU_RD_CTRL) && cmd_cnt_end;
243 100 mohor
 
244 139 igorm
assign acc_type_read    = (acc_type == `DBG_CPU_READ);
245
assign acc_type_write   = (acc_type == `DBG_CPU_WRITE);
246
 
247
 
248
 
249
// Shift register for shifting in and out the data
250
always @ (posedge tck_i or posedge rst_i)
251
begin
252
  if (rst_i)
253
    begin
254
      latch_data <= #1 1'b0;
255
      dr <= #1 {`DBG_CPU_DR_LEN{1'b0}};
256
    end
257
  else if (curr_cmd_rd_comm && crc_cnt_31)  // Latching data (from internal regs)
258
    begin
259 152 igorm
      dr[`DBG_CPU_DR_LEN -1:0] <= #1 {acc_type, adr, len};
260 139 igorm
    end
261
  else if (curr_cmd_rd_ctrl && crc_cnt_31)  // Latching data (from control regs)
262
    begin
263 152 igorm
      dr[`DBG_CPU_DR_LEN -1:0] <= #1 {ctrl_reg, {`DBG_CPU_DR_LEN -`DBG_CPU_CTRL_LEN{1'b0}}};
264 139 igorm
    end
265
  else if (acc_type_read && curr_cmd_go && crc_cnt_31)  // Latchind first data (from WB)
266
    begin
267
      dr[31:0] <= #1 input_data[31:0];
268
      latch_data <= #1 1'b1;
269
    end
270
  else if (acc_type_read && curr_cmd_go && crc_cnt_end) // Latching data (from WB)
271
    begin
272
      case (acc_type)  // synthesis parallel_case full_case
273
        `DBG_CPU_READ: begin
274
                      if(long & (~long_q))
275
                        begin
276
                          dr[31:0] <= #1 input_data[31:0];
277
                          latch_data <= #1 1'b1;
278
                        end
279
                      else
280
                        begin
281
                          dr[31:0] <= #1 {dr[30:0], 1'b0};
282
                          latch_data <= #1 1'b0;
283
                        end
284
                    end
285
      endcase
286
    end
287
  else if (enable && (!addr_len_cnt_end))
288
    begin
289
      dr <= #1 {dr[`DBG_CPU_DR_LEN -2:0], tdi_i};
290
    end
291
end
292
 
293
 
294
 
295 100 mohor
assign cmd_cnt_en = enable & (~cmd_cnt_end);
296
 
297
 
298
// Command counter
299
always @ (posedge tck_i or posedge rst_i)
300
begin
301
  if (rst_i)
302 139 igorm
    cmd_cnt <= #1 {`DBG_CPU_CMD_CNT_WIDTH{1'b0}};
303 100 mohor
  else if (update_dr_i)
304 139 igorm
    cmd_cnt <= #1 {`DBG_CPU_CMD_CNT_WIDTH{1'b0}};
305 100 mohor
  else if (cmd_cnt_en)
306
    cmd_cnt <= #1 cmd_cnt + 1'b1;
307
end
308
 
309
 
310 139 igorm
// Assigning current command
311
always @ (posedge tck_i or posedge rst_i)
312
begin
313
  if (rst_i)
314
    curr_cmd <= #1 {`DBG_CPU_CMD_LEN{1'b0}};
315
  else if (update_dr_i)
316
    curr_cmd <= #1 {`DBG_CPU_CMD_LEN{1'b0}};
317
  else if (cmd_cnt == (`DBG_CPU_CMD_LEN -1))
318
    curr_cmd <= #1 {dr[`DBG_CPU_CMD_LEN-2 :0], tdi_i};
319
end
320 100 mohor
 
321
 
322 139 igorm
// Assigning current command
323
always @ (posedge tck_i or posedge rst_i)
324
begin
325
  if (rst_i)
326
    curr_cmd_go_q <= #1 1'b0;
327
  else
328
    curr_cmd_go_q <= #1 curr_cmd_go;
329
end
330
 
331
 
332
always @ (enable or cmd_cnt_end or addr_len_cnt_end or curr_cmd_wr_comm or curr_cmd_wr_ctrl or curr_cmd_rd_comm or curr_cmd_rd_ctrl or crc_cnt_end)
333
begin
334
  if (enable && (!addr_len_cnt_end))
335
    begin
336
      if (cmd_cnt_end && (curr_cmd_wr_comm || curr_cmd_wr_ctrl))
337
        addr_len_cnt_en = 1'b1;
338
      else if (crc_cnt_end && (curr_cmd_rd_comm || curr_cmd_rd_ctrl))
339
        addr_len_cnt_en = 1'b1;
340
      else
341
        addr_len_cnt_en = 1'b0;
342
    end
343
  else
344
    addr_len_cnt_en = 1'b0;
345
end
346
 
347
 
348 100 mohor
// Address/length counter
349
always @ (posedge tck_i or posedge rst_i)
350
begin
351
  if (rst_i)
352 139 igorm
    addr_len_cnt <= #1 6'h0;
353 100 mohor
  else if (update_dr_i)
354 139 igorm
    addr_len_cnt <= #1 6'h0;
355
  else if (addr_len_cnt_en)
356
    addr_len_cnt <= #1 addr_len_cnt + 1'b1;
357 100 mohor
end
358
 
359
 
360 139 igorm
always @ (enable or data_cnt_end or cmd_cnt_end or curr_cmd_go or acc_type_write or acc_type_read or crc_cnt_end)
361
begin
362
  if (enable && (!data_cnt_end))
363
    begin
364
      if (cmd_cnt_end && curr_cmd_go && acc_type_write)
365
        data_cnt_en = 1'b1;
366
      else if (crc_cnt_end && curr_cmd_go && acc_type_read)
367
        data_cnt_en = 1'b1;
368
      else
369
        data_cnt_en = 1'b0;
370
    end
371
  else
372
    data_cnt_en = 1'b0;
373
end
374 100 mohor
 
375
 
376
// Data counter
377
always @ (posedge tck_i or posedge rst_i)
378
begin
379
  if (rst_i)
380 139 igorm
    data_cnt <= #1 {`DBG_CPU_DATA_CNT_WIDTH{1'b0}};
381 100 mohor
  else if (update_dr_i)
382 139 igorm
    data_cnt <= #1 {`DBG_CPU_DATA_CNT_WIDTH{1'b0}};
383 100 mohor
  else if (data_cnt_en)
384
    data_cnt <= #1 data_cnt + 1'b1;
385
end
386
 
387
 
388
 
389 139 igorm
// Upper limit. Data counter counts until this value is reached.
390 100 mohor
always @ (posedge tck_i or posedge rst_i)
391
begin
392
  if (rst_i)
393 141 igorm
    data_cnt_limit <= #1 {`DBG_CPU_DATA_CNT_LIM_WIDTH{1'b0}};
394 100 mohor
  else if (update_dr_i)
395 141 igorm
    data_cnt_limit <= #1 len + 1'b1;
396 100 mohor
end
397
 
398
 
399 139 igorm
always @ (enable or crc_cnt_end or curr_cmd_rd_comm or curr_cmd_rd_ctrl or curr_cmd_wr_comm or curr_cmd_wr_ctrl or curr_cmd_go or addr_len_cnt_end or data_cnt_end or acc_type_write or acc_type_read or cmd_cnt_end)
400 100 mohor
begin
401 139 igorm
  if (enable && (!crc_cnt_end) && cmd_cnt_end)
402 100 mohor
    begin
403 139 igorm
      if (addr_len_cnt_end && (curr_cmd_wr_comm || curr_cmd_wr_ctrl))
404
        crc_cnt_en = 1'b1;
405
      else if (data_cnt_end && curr_cmd_go && acc_type_write)
406
        crc_cnt_en = 1'b1;
407
      else if (cmd_cnt_end && (curr_cmd_go && acc_type_read || curr_cmd_rd_comm || curr_cmd_rd_ctrl))
408
        crc_cnt_en = 1'b1;
409
      else
410
        crc_cnt_en = 1'b0;
411 100 mohor
    end
412 139 igorm
  else
413
    crc_cnt_en = 1'b0;
414 100 mohor
end
415
 
416
 
417 139 igorm
// crc counter
418 123 mohor
always @ (posedge tck_i or posedge rst_i)
419 100 mohor
begin
420 123 mohor
  if (rst_i)
421 139 igorm
    crc_cnt <= #1 {`DBG_CPU_CRC_CNT_WIDTH{1'b0}};
422
  else if(crc_cnt_en)
423
    crc_cnt <= #1 crc_cnt + 1'b1;
424
  else if (update_dr_i)
425
    crc_cnt <= #1 {`DBG_CPU_CRC_CNT_WIDTH{1'b0}};
426
end
427
 
428
assign cmd_cnt_end      = cmd_cnt      == `DBG_CPU_CMD_LEN;
429
assign addr_len_cnt_end = addr_len_cnt == `DBG_CPU_DR_LEN;
430
assign crc_cnt_end      = crc_cnt      == `DBG_CPU_CRC_CNT_WIDTH'd32;
431
assign crc_cnt_31       = crc_cnt      == `DBG_CPU_CRC_CNT_WIDTH'd31;
432 141 igorm
assign data_cnt_end     = (data_cnt    == {data_cnt_limit, 3'b000});
433 139 igorm
 
434
always @ (posedge tck_i or posedge rst_i)
435
begin
436
  if (rst_i)
437 123 mohor
    begin
438 139 igorm
      crc_cnt_end_q       <= #1 1'b0;
439
      cmd_cnt_end_q       <= #1 1'b0;
440
      data_cnt_end_q      <= #1 1'b0;
441
      addr_len_cnt_end_q  <= #1 1'b0;
442 123 mohor
    end
443
  else
444
    begin
445 139 igorm
      crc_cnt_end_q       <= #1 crc_cnt_end;
446
      cmd_cnt_end_q       <= #1 cmd_cnt_end;
447
      data_cnt_end_q      <= #1 data_cnt_end;
448
      addr_len_cnt_end_q  <= #1 addr_len_cnt_end;
449 123 mohor
    end
450 100 mohor
end
451
 
452
 
453
// Status counter is made of 4 serialy connected registers
454
always @ (posedge tck_i or posedge rst_i)
455
begin
456
  if (rst_i)
457 139 igorm
    status_cnt <= #1 {`DBG_CPU_STATUS_CNT_WIDTH{1'b0}};
458 100 mohor
  else if (update_dr_i)
459 139 igorm
    status_cnt <= #1 {`DBG_CPU_STATUS_CNT_WIDTH{1'b0}};
460
  else if (status_cnt_en)
461
    status_cnt <= #1 status_cnt + 1'b1;
462 100 mohor
end
463
 
464
 
465 141 igorm
always @ (enable or status_cnt_end or crc_cnt_end or curr_cmd_rd_comm or curr_cmd_rd_ctrl or
466
          curr_cmd_wr_comm or curr_cmd_wr_ctrl or curr_cmd_go or acc_type_write or
467
          acc_type_read or data_cnt_end or addr_len_cnt_end)
468 139 igorm
begin
469
  if (enable && (!status_cnt_end))
470
    begin
471
      if (crc_cnt_end && (curr_cmd_wr_comm || curr_cmd_wr_ctrl))
472
        status_cnt_en = 1'b1;
473
      else if (crc_cnt_end && curr_cmd_go && acc_type_write)
474
        status_cnt_en = 1'b1;
475
      else if (data_cnt_end && curr_cmd_go && acc_type_read)
476
        status_cnt_en = 1'b1;
477
      else if (addr_len_cnt_end && (curr_cmd_rd_comm || curr_cmd_rd_ctrl))
478
        status_cnt_en = 1'b1;
479
      else
480
        status_cnt_en = 1'b0;
481
    end
482
  else
483
    status_cnt_en = 1'b0;
484
end
485
 
486
 
487
assign status_cnt_end = status_cnt == `DBG_CPU_STATUS_LEN;
488
 
489
 
490
// Latching acc_type, address and length
491 100 mohor
always @ (posedge tck_i or posedge rst_i)
492
begin
493
  if (rst_i)
494
    begin
495 139 igorm
      acc_type  <= #1 {`DBG_CPU_ACC_TYPE_LEN{1'b0}};
496
      adr       <= #1 {`DBG_CPU_ADR_LEN{1'b0}};
497
      len       <= #1 {`DBG_CPU_LEN_LEN{1'b0}};
498
      set_addr  <= #1 1'b0;
499 100 mohor
    end
500 139 igorm
  else if(crc_cnt_end && (!crc_cnt_end_q) && crc_match_i && curr_cmd_wr_comm)
501 100 mohor
    begin
502 139 igorm
      acc_type  <= #1 dr[`DBG_CPU_ACC_TYPE_LEN + `DBG_CPU_ADR_LEN + `DBG_CPU_LEN_LEN -1 : `DBG_CPU_ADR_LEN + `DBG_CPU_LEN_LEN];
503
      adr       <= #1 dr[`DBG_CPU_ADR_LEN + `DBG_CPU_LEN_LEN -1 : `DBG_CPU_LEN_LEN];
504
      len       <= #1 dr[`DBG_CPU_LEN_LEN -1:0];
505
      set_addr  <= #1 1'b1;
506 100 mohor
    end
507 139 igorm
  else if(cpu_end_tck)               // Writing back the address
508 100 mohor
    begin
509 139 igorm
      adr  <= #1 cpu_addr_dsff;
510 100 mohor
    end
511 139 igorm
  else
512
    set_addr <= #1 1'b0;
513 100 mohor
end
514
 
515
 
516 121 mohor
always @ (posedge tck_i or posedge rst_i)
517 100 mohor
begin
518 121 mohor
  if (rst_i)
519 139 igorm
    crc_match_reg <= #1 1'b0;
520
  else if(crc_cnt_end & (~crc_cnt_end_q))
521
    crc_match_reg <= #1 crc_match_i;
522 100 mohor
end
523
 
524
 
525 139 igorm
// Length counter
526 121 mohor
always @ (posedge tck_i or posedge rst_i)
527 100 mohor
begin
528 121 mohor
  if (rst_i)
529 139 igorm
    len_var <= #1 {1'b0, {`DBG_CPU_LEN_LEN{1'b0}}};
530
  else if(update_dr_i)
531
    len_var <= #1 len + 1'b1;
532
  else if (start_rd_tck)
533 101 mohor
    begin
534 139 igorm
      if (len_var > 'd4)
535
        len_var <= #1 len_var - 3'd4;
536 101 mohor
      else
537 139 igorm
        len_var <= #1 {1'b0, {`DBG_CPU_LEN_LEN{1'b0}}};
538 101 mohor
    end
539 100 mohor
end
540
 
541
 
542 139 igorm
assign len_eq_0 = len_var == 'h0;
543 100 mohor
 
544
 
545 139 igorm
assign half = data_cnt[3:0] == 4'd15;
546
assign long = data_cnt[4:0] == 5'd31;
547
 
548
 
549 123 mohor
always @ (posedge tck_i or posedge rst_i)
550 100 mohor
begin
551 123 mohor
  if (rst_i)
552 100 mohor
    begin
553 139 igorm
      half_q <= #1  1'b0;
554
      long_q <= #1  1'b0;
555 100 mohor
    end
556 139 igorm
  else
557 123 mohor
    begin
558 139 igorm
      half_q <= #1 half;
559
      long_q <= #1 long;
560 123 mohor
    end
561 100 mohor
end
562
 
563 139 igorm
 
564
// Start cpu write cycle
565 100 mohor
always @ (posedge tck_i or posedge rst_i)
566
begin
567
  if (rst_i)
568
    begin
569 139 igorm
      start_wr_tck <= #1 1'b0;
570
      cpu_dat_tmp <= #1 32'h0;
571 100 mohor
    end
572 139 igorm
  else if (curr_cmd_go && acc_type_write)
573 100 mohor
    begin
574 139 igorm
      if (long_q)
575
        begin
576
          start_wr_tck <= #1 1'b1;
577
          cpu_dat_tmp <= #1 dr[31:0];
578
        end
579
      else
580
        begin
581
          start_wr_tck <= #1 1'b0;
582
        end
583 100 mohor
    end
584 139 igorm
  else
585
    start_wr_tck <= #1 1'b0;
586 100 mohor
end
587
 
588
 
589 139 igorm
// cpu_data_o in WB clk domain
590
always @ (posedge cpu_clk_i)
591 100 mohor
begin
592 139 igorm
  cpu_data_dsff <= #1 cpu_dat_tmp;
593 100 mohor
end
594
 
595 139 igorm
assign cpu_data_o = cpu_data_dsff;
596 100 mohor
 
597
 
598 139 igorm
// Start cpu read cycle
599 123 mohor
always @ (posedge tck_i or posedge rst_i)
600 100 mohor
begin
601 123 mohor
  if (rst_i)
602 139 igorm
    start_rd_tck <= #1 1'b0;
603
  else if (curr_cmd_go && (!curr_cmd_go_q) && acc_type_read)              // First read after cmd is entered
604
    start_rd_tck <= #1 1'b1;
605
  else if ((!start_rd_tck) && curr_cmd_go && acc_type_read  && (!len_eq_0) && (!fifo_full) && (!rd_tck_started) && (!cpu_ack_tck))
606
    start_rd_tck <= #1 1'b1;
607
  else
608
    start_rd_tck <= #1 1'b0;
609 100 mohor
end
610
 
611
 
612 123 mohor
always @ (posedge tck_i or posedge rst_i)
613 100 mohor
begin
614 123 mohor
  if (rst_i)
615 139 igorm
    rd_tck_started <= #1 1'b0;
616
  else if (update_dr_i || cpu_end_tck && (!cpu_end_tck_q))
617
    rd_tck_started <= #1 1'b0;
618
  else if (start_rd_tck)
619
    rd_tck_started <= #1 1'b1;
620 100 mohor
end
621
 
622
 
623 139 igorm
 
624
always @ (posedge cpu_clk_i or posedge rst_i)
625 100 mohor
begin
626 123 mohor
  if (rst_i)
627
    begin
628 139 igorm
      start_rd_csff   <= #1 1'b0;
629
      start_cpu_rd    <= #1 1'b0;
630
      start_cpu_rd_q  <= #1 1'b0;
631
 
632
      start_wr_csff   <= #1 1'b0;
633
      start_cpu_wr    <= #1 1'b0;
634
      start_cpu_wr_q  <= #1 1'b0;
635
 
636
      set_addr_csff   <= #1 1'b0;
637
      set_addr_cpu    <= #1 1'b0;
638
      set_addr_cpu_q  <= #1 1'b0;
639
 
640
      cpu_ack_q       <= #1 1'b0;
641 123 mohor
    end
642
  else
643
    begin
644 139 igorm
      start_rd_csff   <= #1 start_rd_tck;
645
      start_cpu_rd    <= #1 start_rd_csff;
646
      start_cpu_rd_q  <= #1 start_cpu_rd;
647
 
648
      start_wr_csff   <= #1 start_wr_tck;
649
      start_cpu_wr    <= #1 start_wr_csff;
650
      start_cpu_wr_q  <= #1 start_cpu_wr;
651
 
652
      set_addr_csff   <= #1 set_addr;
653
      set_addr_cpu    <= #1 set_addr_csff;
654
      set_addr_cpu_q  <= #1 set_addr_cpu;
655
 
656
      cpu_ack_q       <= #1 cpu_ack_i;
657 123 mohor
    end
658 101 mohor
end
659
 
660
 
661 139 igorm
// cpu_stb_o
662
always @ (posedge cpu_clk_i or posedge rst_i)
663 101 mohor
begin
664 123 mohor
  if (rst_i)
665 139 igorm
    cpu_stb_o <= #1 1'b0;
666
  else if (cpu_ack_i)
667
    cpu_stb_o <= #1 1'b0;
668
  else if ((start_cpu_wr && (!start_cpu_wr_q)) || (start_cpu_rd && (!start_cpu_rd_q)))
669
    cpu_stb_o <= #1 1'b1;
670 100 mohor
end
671
 
672
 
673 139 igorm
assign cpu_stall_o = cpu_stb_o | cpu_reg_stall;
674
 
675
 
676
// cpu_addr_o logic
677
always @ (posedge cpu_clk_i or posedge rst_i)
678 100 mohor
begin
679 121 mohor
  if (rst_i)
680 139 igorm
    cpu_addr_dsff <= #1 32'h0;
681
  else if (set_addr_cpu && (!set_addr_cpu_q)) // Setting starting address
682
    cpu_addr_dsff <= #1 adr;
683
  else if (cpu_ack_i && (!cpu_ack_q))
684
    cpu_addr_dsff <= #1 cpu_addr_dsff + 3'd4;
685 100 mohor
end
686
 
687
 
688 139 igorm
assign cpu_addr_o = cpu_addr_dsff;
689 100 mohor
 
690
 
691 139 igorm
always @ (posedge cpu_clk_i)
692
begin
693
  cpu_we_dsff <= #1 curr_cmd_go && acc_type_write;
694
end
695 101 mohor
 
696 139 igorm
 
697
assign cpu_we_o = cpu_we_dsff;
698
 
699
 
700
 
701
// Logic for detecting end of transaction
702
always @ (posedge cpu_clk_i or posedge rst_i)
703
begin
704
  if (rst_i)
705
    cpu_end <= #1 1'b0;
706
  else if (cpu_ack_i && (!cpu_ack_q))
707
    cpu_end <= #1 1'b1;
708
  else if (cpu_end_rst)
709
    cpu_end <= #1 1'b0;
710
end
711
 
712
 
713 123 mohor
always @ (posedge tck_i or posedge rst_i)
714 100 mohor
begin
715 123 mohor
  if (rst_i)
716 139 igorm
    begin
717
      cpu_end_csff  <= #1 1'b0;
718
      cpu_end_tck   <= #1 1'b0;
719
      cpu_end_tck_q <= #1 1'b0;
720
    end
721 100 mohor
  else
722 139 igorm
    begin
723
      cpu_end_csff  <= #1 cpu_end;
724
      cpu_end_tck   <= #1 cpu_end_csff;
725
      cpu_end_tck_q <= #1 cpu_end_tck;
726
    end
727 100 mohor
end
728
 
729
 
730 139 igorm
always @ (posedge cpu_clk_i or posedge rst_i)
731
begin
732
  if (rst_i)
733
    begin
734
      cpu_end_rst_csff <= #1 1'b0;
735
      cpu_end_rst      <= #1 1'b0;
736
    end
737
  else
738
    begin
739
      cpu_end_rst_csff <= #1 cpu_end_tck;
740
      cpu_end_rst      <= #1 cpu_end_rst_csff;
741
    end
742
end
743 100 mohor
 
744
 
745 139 igorm
always @ (posedge cpu_clk_i or posedge rst_i)
746
begin
747
  if (rst_i)
748
    busy_cpu <= #1 1'b0;
749
  else if (cpu_end_rst)
750
    busy_cpu <= #1 1'b0;
751
  else if (cpu_stb_o)
752
    busy_cpu <= #1 1'b1;
753
end
754 100 mohor
 
755
 
756 123 mohor
always @ (posedge tck_i or posedge rst_i)
757 101 mohor
begin
758 123 mohor
  if (rst_i)
759
    begin
760 139 igorm
      busy_csff       <= #1 1'b0;
761
      busy_tck        <= #1 1'b0;
762
 
763
      update_dr_csff  <= #1 1'b0;
764
      update_dr_cpu   <= #1 1'b0;
765 123 mohor
    end
766
  else
767
    begin
768 139 igorm
      busy_csff       <= #1 busy_cpu;
769
      busy_tck        <= #1 busy_csff;
770
 
771
      update_dr_csff  <= #1 update_dr_i;
772
      update_dr_cpu   <= #1 update_dr_csff;
773 123 mohor
    end
774 101 mohor
end
775
 
776
 
777 139 igorm
// Detecting overrun when write operation.
778
always @ (posedge cpu_clk_i or posedge rst_i)
779
begin
780
  if (rst_i)
781
    cpu_overrun <= #1 1'b0;
782
  else if(start_cpu_wr && (!start_cpu_wr_q) && cpu_ack_i)
783
    cpu_overrun <= #1 1'b1;
784
  else if(update_dr_cpu) // error remains active until update_dr arrives
785
    cpu_overrun <= #1 1'b0;
786
end
787 101 mohor
 
788 139 igorm
 
789
// Detecting underrun when read operation
790 121 mohor
always @ (posedge tck_i or posedge rst_i)
791 101 mohor
begin
792 121 mohor
  if (rst_i)
793 139 igorm
    underrun_tck <= #1 1'b0;
794
  else if(latch_data && (!fifo_full) && (!data_cnt_end))
795
    underrun_tck <= #1 1'b1;
796
  else if(update_dr_i) // error remains active until update_dr arrives
797
    underrun_tck <= #1 1'b0;
798 101 mohor
end
799
 
800
 
801 139 igorm
always @ (posedge tck_i or posedge rst_i)
802
begin
803
  if (rst_i)
804
    begin
805
      cpu_overrun_csff <= #1 1'b0;
806
      cpu_overrun_tck  <= #1 1'b0;
807 101 mohor
 
808 139 igorm
      cpu_ack_csff     <= #1 1'b0;
809
      cpu_ack_tck      <= #1 1'b0;
810
    end
811
  else
812
    begin
813
      cpu_overrun_csff <= #1 cpu_overrun;
814
      cpu_overrun_tck  <= #1 cpu_overrun_csff;
815
 
816
      cpu_ack_csff     <= #1 cpu_ack_i;
817
      cpu_ack_tck      <= #1 cpu_ack_csff;
818
    end
819
end
820
 
821
 
822
 
823 123 mohor
always @ (posedge cpu_clk_i or posedge rst_i)
824 101 mohor
begin
825 123 mohor
  if (rst_i)
826
    begin
827 139 igorm
      cpu_ce_csff  <= #1 1'b0;
828
      mem_ptr_init      <= #1 1'b0;
829 123 mohor
    end
830
  else
831
    begin
832 139 igorm
      cpu_ce_csff  <= #1  cpu_ce_i;
833
      mem_ptr_init      <= #1 ~cpu_ce_csff;
834 123 mohor
    end
835 101 mohor
end
836
 
837
 
838 139 igorm
// Logic for latching data that is read from cpu
839
always @ (posedge cpu_clk_i)
840 102 mohor
begin
841 139 igorm
  if (cpu_ack_i && (!cpu_ack_q))
842
    begin
843
      mem[0] <= #1 cpu_data_i[31:24];
844
      mem[1] <= #1 cpu_data_i[23:16];
845
      mem[2] <= #1 cpu_data_i[15:08];
846
      mem[3] <= #1 cpu_data_i[07:00];
847
    end
848 102 mohor
end
849 101 mohor
 
850
 
851 139 igorm
assign input_data = {mem[0], mem[1], mem[2], mem[3]};
852 101 mohor
 
853 139 igorm
 
854
// Fifo counter and empty/full detection
855 102 mohor
always @ (posedge tck_i or posedge rst_i)
856
begin
857
  if (rst_i)
858 139 igorm
    fifo_full <= #1 1'h0;
859
  else if (update_dr_i)
860
    fifo_full <= #1 1'h0;
861
  else if (cpu_end_tck && (!cpu_end_tck_q) && (!latch_data) && (!fifo_full))  // incrementing
862
    fifo_full <= #1 1'b1;
863
  else if (!(cpu_end_tck && (!cpu_end_tck_q)) && latch_data && (fifo_full))  // decrementing
864
    fifo_full <= #1 1'h0;
865 102 mohor
end
866 101 mohor
 
867 102 mohor
 
868
 
869
// TDO multiplexer
870 139 igorm
always @ (pause_dr_i or busy_tck or crc_cnt_end or crc_cnt_end_q or curr_cmd_wr_comm or curr_cmd_wr_ctrl or curr_cmd_go or acc_type_write or acc_type_read or crc_match_i or data_cnt_end or dr or data_cnt_end_q or crc_match_reg or status_cnt_en or status or addr_len_cnt_end or addr_len_cnt_end_q or curr_cmd_rd_comm or curr_cmd_rd_ctrl)
871 102 mohor
begin
872 139 igorm
  if (pause_dr_i)
873 102 mohor
    begin
874 139 igorm
    tdo_o = busy_tck;
875 102 mohor
    end
876 139 igorm
  else if (crc_cnt_end && (!crc_cnt_end_q) && (curr_cmd_wr_comm || curr_cmd_wr_ctrl || curr_cmd_go && acc_type_write ))
877 102 mohor
    begin
878 139 igorm
      tdo_o = ~crc_match_i;
879 102 mohor
    end
880 139 igorm
  else if (curr_cmd_go && acc_type_read && crc_cnt_end && (!data_cnt_end))
881 102 mohor
    begin
882 139 igorm
      tdo_o = dr[31];
883 102 mohor
    end
884 139 igorm
  else if (curr_cmd_go && acc_type_read && data_cnt_end && (!data_cnt_end_q))
885 102 mohor
    begin
886 139 igorm
      tdo_o = ~crc_match_reg;
887 102 mohor
    end
888 139 igorm
  else if ((curr_cmd_rd_comm || curr_cmd_rd_ctrl) && addr_len_cnt_end && (!addr_len_cnt_end_q))
889
    begin
890
      tdo_o = ~crc_match_reg;
891
    end
892 152 igorm
  else if ((curr_cmd_rd_comm || curr_cmd_rd_ctrl) && crc_cnt_end && (!addr_len_cnt_end))
893 139 igorm
    begin
894
      tdo_o = dr[`DBG_CPU_ACC_TYPE_LEN + `DBG_CPU_ADR_LEN + `DBG_CPU_LEN_LEN -1];
895
    end
896
  else if (status_cnt_en)
897
    begin
898
      tdo_o = status[3];
899
    end
900 102 mohor
  else
901
    begin
902
      tdo_o = 1'b0;
903
    end
904
end
905
 
906 143 igorm
 
907 139 igorm
// Status register
908
always @ (posedge tck_i or posedge rst_i)
909
begin
910
  if (rst_i)
911
    begin
912
    status <= #1 {`DBG_CPU_STATUS_LEN{1'b0}};
913
    end
914
  else if(crc_cnt_end && (!crc_cnt_end_q) && (!(curr_cmd_go && acc_type_read)))
915
    begin
916
    status <= #1 {1'b0, 1'b0, cpu_overrun_tck, crc_match_i};
917
    end
918
  else if (data_cnt_end && (!data_cnt_end_q) && curr_cmd_go && acc_type_read)
919
    begin
920
    status <= #1 {1'b0, 1'b0, underrun_tck, crc_match_reg};
921
    end
922
  else if (addr_len_cnt_end && (!addr_len_cnt_end) && (curr_cmd_rd_comm || curr_cmd_rd_ctrl))
923
    begin
924
    status <= #1 {1'b0, 1'b0, 1'b0, crc_match_reg};
925
    end
926
  else if (shift_dr_i && (!status_cnt_end))
927
    begin
928
    status <= #1 {status[`DBG_CPU_STATUS_LEN -2:0], status[`DBG_CPU_STATUS_LEN -1]};
929
    end
930
end
931
// Following status is shifted out (MSB first):
932
// 3. bit:          1 if crc is OK, else 0
933
// 2. bit:          1'b0
934
// 1. bit:          0
935
// 0. bit:          1 if overrun occured during write (data couldn't be written fast enough)
936
//                    or underrun occured during read (data couldn't be read fast enough)
937 102 mohor
 
938
 
939
 
940 139 igorm
// Connecting cpu registers
941
assign cpu_reg_we = crc_cnt_end && (!crc_cnt_end_q) && crc_match_i && curr_cmd_wr_ctrl;
942
assign cpu_reg_data_i = dr[`DBG_CPU_DR_LEN -1:`DBG_CPU_DR_LEN -`DBG_CPU_CTRL_LEN];
943 102 mohor
 
944 139 igorm
dbg_cpu_registers i_dbg_cpu_registers
945
  (
946
    .data_i          (cpu_reg_data_i),
947
    .we_i            (cpu_reg_we),
948
    .tck_i           (tck_i),
949
    .bp_i            (cpu_bp_i),
950
    .rst_i           (rst_i),
951
    .cpu_clk_i       (cpu_clk_i),
952
    .ctrl_reg_o      (ctrl_reg),
953
    .cpu_stall_o     (cpu_reg_stall),
954
    .cpu_rst_o       (cpu_rst_o)
955
  );
956 102 mohor
 
957
 
958 139 igorm
 
959
 
960
 
961 100 mohor
endmodule
962
 

powered by: WebSVN 2.1.0

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