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 150

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

powered by: WebSVN 2.1.0

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