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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [xilinx_avnet_lx9microbard/] [rtl/] [verilog/] [openmsp430/] [omsp_dbg.v] - Blame information for rev 167

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

Line No. Rev Author Line
1 157 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2009 , Olivier Girard
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions
6
// are met:
7
//     * Redistributions of source code must retain the above copyright
8
//       notice, this list of conditions and the following disclaimer.
9
//     * Redistributions in binary form must reproduce the above copyright
10
//       notice, this list of conditions and the following disclaimer in the
11
//       documentation and/or other materials provided with the distribution.
12
//     * Neither the name of the authors nor the names of its contributors
13
//       may be used to endorse or promote products derived from this software
14
//       without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26
// THE POSSIBILITY OF SUCH DAMAGE
27
//
28
//----------------------------------------------------------------------------
29
//
30
// *File Name: omsp_dbg.v
31
// 
32
// *Module Description:
33
//                       Debug interface
34
//
35
// *Author(s):
36
//              - Olivier Girard,    olgirard@gmail.com
37
//
38
//----------------------------------------------------------------------------
39
// $Rev: 103 $
40
// $LastChangedBy: olivier.girard $
41
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
42
//----------------------------------------------------------------------------
43
`ifdef OMSP_NO_INCLUDE
44
`else
45
`include "openMSP430_defines.v"
46
`endif
47
 
48
module  omsp_dbg (
49
 
50
// OUTPUTs
51
    dbg_cpu_reset,                     // Reset CPU from debug interface
52
    dbg_freeze,                        // Freeze peripherals
53
    dbg_halt_cmd,                      // Halt CPU command
54
    dbg_i2c_sda_out,                   // Debug interface: I2C SDA OUT
55
    dbg_mem_addr,                      // Debug address for rd/wr access
56
    dbg_mem_dout,                      // Debug unit data output
57
    dbg_mem_en,                        // Debug unit memory enable
58
    dbg_mem_wr,                        // Debug unit memory write
59
    dbg_reg_wr,                        // Debug unit CPU register write
60
    dbg_uart_txd,                      // Debug interface: UART TXD
61
 
62
// INPUTs
63
    cpu_en_s,                          // Enable CPU code execution (synchronous)
64
    cpu_id,                            // CPU ID
65
    cpu_nr_inst,                       // Current oMSP instance number
66
    cpu_nr_total,                      // Total number of oMSP instances-1
67
    dbg_clk,                           // Debug unit clock
68
    dbg_en_s,                          // Debug interface enable (synchronous)
69
    dbg_halt_st,                       // Halt/Run status from CPU
70
    dbg_i2c_addr,                      // Debug interface: I2C Address
71
    dbg_i2c_broadcast,                 // Debug interface: I2C Broadcast Address (for multicore systems)
72
    dbg_i2c_scl,                       // Debug interface: I2C SCL
73
    dbg_i2c_sda_in,                    // Debug interface: I2C SDA IN
74
    dbg_mem_din,                       // Debug unit Memory data input
75
    dbg_reg_din,                       // Debug unit CPU register data input
76
    dbg_rst,                           // Debug unit reset
77
    dbg_uart_rxd,                      // Debug interface: UART RXD (asynchronous)
78
    decode_noirq,                      // Frontend decode instruction
79
    eu_mab,                            // Execution-Unit Memory address bus
80
    eu_mb_en,                          // Execution-Unit Memory bus enable
81
    eu_mb_wr,                          // Execution-Unit Memory bus write transfer
82
    eu_mdb_in,                         // Memory data bus input
83
    eu_mdb_out,                        // Memory data bus output
84
    exec_done,                         // Execution completed
85
    fe_mb_en,                          // Frontend Memory bus enable
86
    fe_mdb_in,                         // Frontend Memory data bus input
87
    pc,                                // Program counter
88
    puc_pnd_set                        // PUC pending set for the serial debug interface
89
);
90
 
91
// OUTPUTs
92
//=========
93
output              dbg_cpu_reset;     // Reset CPU from debug interface
94
output              dbg_freeze;        // Freeze peripherals
95
output              dbg_halt_cmd;      // Halt CPU command
96
output              dbg_i2c_sda_out;   // Debug interface: I2C SDA OUT
97
output       [15:0] dbg_mem_addr;      // Debug address for rd/wr access
98
output       [15:0] dbg_mem_dout;      // Debug unit data output
99
output              dbg_mem_en;        // Debug unit memory enable
100
output        [1:0] dbg_mem_wr;        // Debug unit memory write
101
output              dbg_reg_wr;        // Debug unit CPU register write
102
output              dbg_uart_txd;      // Debug interface: UART TXD
103
 
104
// INPUTs
105
//=========
106
input               cpu_en_s;          // Enable CPU code execution (synchronous)
107
input        [31:0] cpu_id;            // CPU ID
108
input         [7:0] cpu_nr_inst;       // Current oMSP instance number
109
input         [7:0] cpu_nr_total;      // Total number of oMSP instances-1
110
input               dbg_clk;           // Debug unit clock
111
input               dbg_en_s;          // Debug interface enable (synchronous)
112
input               dbg_halt_st;       // Halt/Run status from CPU
113
input         [6:0] dbg_i2c_addr;      // Debug interface: I2C Address
114
input         [6:0] dbg_i2c_broadcast; // Debug interface: I2C Broadcast Address (for multicore systems)
115
input               dbg_i2c_scl;       // Debug interface: I2C SCL
116
input               dbg_i2c_sda_in;    // Debug interface: I2C SDA IN
117
input        [15:0] dbg_mem_din;       // Debug unit Memory data input
118
input        [15:0] dbg_reg_din;       // Debug unit CPU register data input
119
input               dbg_rst;           // Debug unit reset
120
input               dbg_uart_rxd;      // Debug interface: UART RXD (asynchronous)
121
input               decode_noirq;      // Frontend decode instruction
122
input        [15:0] eu_mab;            // Execution-Unit Memory address bus
123
input               eu_mb_en;          // Execution-Unit Memory bus enable
124
input         [1:0] eu_mb_wr;          // Execution-Unit Memory bus write transfer
125
input        [15:0] eu_mdb_in;         // Memory data bus input
126
input        [15:0] eu_mdb_out;        // Memory data bus output
127
input               exec_done;         // Execution completed
128
input               fe_mb_en;          // Frontend Memory bus enable
129
input        [15:0] fe_mdb_in;         // Frontend Memory data bus input
130
input        [15:0] pc;                // Program counter
131
input               puc_pnd_set;       // PUC pending set for the serial debug interface
132
 
133
 
134
//=============================================================================
135
// 1)  WIRE & PARAMETER DECLARATION
136
//=============================================================================
137
 
138
// Diverse wires and registers
139
wire  [5:0] dbg_addr;
140
wire [15:0] dbg_din;
141
wire        dbg_wr;
142
reg         mem_burst;
143
wire        dbg_reg_rd;
144
wire        dbg_mem_rd;
145
reg         dbg_mem_rd_dly;
146
wire        dbg_swbrk;
147
wire        dbg_rd;
148
reg         dbg_rd_rdy;
149
wire        mem_burst_rd;
150
wire        mem_burst_wr;
151
wire        brk0_halt;
152
wire        brk0_pnd;
153
wire [15:0] brk0_dout;
154
wire        brk1_halt;
155
wire        brk1_pnd;
156
wire [15:0] brk1_dout;
157
wire        brk2_halt;
158
wire        brk2_pnd;
159
wire [15:0] brk2_dout;
160
wire        brk3_halt;
161
wire        brk3_pnd;
162
wire [15:0] brk3_dout;
163
 
164
// Number of registers
165
parameter           NR_REG       = 25;
166
 
167
// Register addresses
168
parameter           CPU_ID_LO    = 6'h00;
169
parameter           CPU_ID_HI    = 6'h01;
170
parameter           CPU_CTL      = 6'h02;
171
parameter           CPU_STAT     = 6'h03;
172
parameter           MEM_CTL      = 6'h04;
173
parameter           MEM_ADDR     = 6'h05;
174
parameter           MEM_DATA     = 6'h06;
175
parameter           MEM_CNT      = 6'h07;
176
`ifdef DBG_HWBRK_0
177
parameter           BRK0_CTL     = 6'h08;
178
parameter           BRK0_STAT    = 6'h09;
179
parameter           BRK0_ADDR0   = 6'h0A;
180
parameter           BRK0_ADDR1   = 6'h0B;
181
`endif
182
`ifdef DBG_HWBRK_1
183
parameter           BRK1_CTL     = 6'h0C;
184
parameter           BRK1_STAT    = 6'h0D;
185
parameter           BRK1_ADDR0   = 6'h0E;
186
parameter           BRK1_ADDR1   = 6'h0F;
187
`endif
188
`ifdef DBG_HWBRK_2
189
parameter           BRK2_CTL     = 6'h10;
190
parameter           BRK2_STAT    = 6'h11;
191
parameter           BRK2_ADDR0   = 6'h12;
192
parameter           BRK2_ADDR1   = 6'h13;
193
`endif
194
`ifdef DBG_HWBRK_3
195
parameter           BRK3_CTL     = 6'h14;
196
parameter           BRK3_STAT    = 6'h15;
197
parameter           BRK3_ADDR0   = 6'h16;
198
parameter           BRK3_ADDR1   = 6'h17;
199
`endif
200
parameter           CPU_NR       = 6'h18;
201
 
202
// Register one-hot decoder
203
parameter           BASE_D       = {{NR_REG-1{1'b0}}, 1'b1};
204
parameter           CPU_ID_LO_D  = (BASE_D << CPU_ID_LO);
205
parameter           CPU_ID_HI_D  = (BASE_D << CPU_ID_HI);
206
parameter           CPU_CTL_D    = (BASE_D << CPU_CTL);
207
parameter           CPU_STAT_D   = (BASE_D << CPU_STAT);
208
parameter           MEM_CTL_D    = (BASE_D << MEM_CTL);
209
parameter           MEM_ADDR_D   = (BASE_D << MEM_ADDR);
210
parameter           MEM_DATA_D   = (BASE_D << MEM_DATA);
211
parameter           MEM_CNT_D    = (BASE_D << MEM_CNT);
212
`ifdef DBG_HWBRK_0
213
parameter           BRK0_CTL_D   = (BASE_D << BRK0_CTL);
214
parameter           BRK0_STAT_D  = (BASE_D << BRK0_STAT);
215
parameter           BRK0_ADDR0_D = (BASE_D << BRK0_ADDR0);
216
parameter           BRK0_ADDR1_D = (BASE_D << BRK0_ADDR1);
217
`endif
218
`ifdef DBG_HWBRK_1
219
parameter           BRK1_CTL_D   = (BASE_D << BRK1_CTL);
220
parameter           BRK1_STAT_D  = (BASE_D << BRK1_STAT);
221
parameter           BRK1_ADDR0_D = (BASE_D << BRK1_ADDR0);
222
parameter           BRK1_ADDR1_D = (BASE_D << BRK1_ADDR1);
223
`endif
224
`ifdef DBG_HWBRK_2
225
parameter           BRK2_CTL_D   = (BASE_D << BRK2_CTL);
226
parameter           BRK2_STAT_D  = (BASE_D << BRK2_STAT);
227
parameter           BRK2_ADDR0_D = (BASE_D << BRK2_ADDR0);
228
parameter           BRK2_ADDR1_D = (BASE_D << BRK2_ADDR1);
229
`endif
230
`ifdef DBG_HWBRK_3
231
parameter           BRK3_CTL_D   = (BASE_D << BRK3_CTL);
232
parameter           BRK3_STAT_D  = (BASE_D << BRK3_STAT);
233
parameter           BRK3_ADDR0_D = (BASE_D << BRK3_ADDR0);
234
parameter           BRK3_ADDR1_D = (BASE_D << BRK3_ADDR1);
235
`endif
236
parameter           CPU_NR_D     = (BASE_D << CPU_NR);
237
 
238
 
239
//============================================================================
240
// 2)  REGISTER DECODER
241
//============================================================================
242
 
243
// Select Data register during a burst
244
wire  [5:0] dbg_addr_in = mem_burst ? MEM_DATA : dbg_addr;
245
 
246
// Register address decode
247
reg  [NR_REG-1:0]  reg_dec;
248
always @(dbg_addr_in)
249
  case (dbg_addr_in)
250
    CPU_ID_LO :  reg_dec  =  CPU_ID_LO_D;
251
    CPU_ID_HI :  reg_dec  =  CPU_ID_HI_D;
252
    CPU_CTL   :  reg_dec  =  CPU_CTL_D;
253
    CPU_STAT  :  reg_dec  =  CPU_STAT_D;
254
    MEM_CTL   :  reg_dec  =  MEM_CTL_D;
255
    MEM_ADDR  :  reg_dec  =  MEM_ADDR_D;
256
    MEM_DATA  :  reg_dec  =  MEM_DATA_D;
257
    MEM_CNT   :  reg_dec  =  MEM_CNT_D;
258
`ifdef DBG_HWBRK_0
259
    BRK0_CTL  :  reg_dec  =  BRK0_CTL_D;
260
    BRK0_STAT :  reg_dec  =  BRK0_STAT_D;
261
    BRK0_ADDR0:  reg_dec  =  BRK0_ADDR0_D;
262
    BRK0_ADDR1:  reg_dec  =  BRK0_ADDR1_D;
263
`endif
264
`ifdef DBG_HWBRK_1
265
    BRK1_CTL  :  reg_dec  =  BRK1_CTL_D;
266
    BRK1_STAT :  reg_dec  =  BRK1_STAT_D;
267
    BRK1_ADDR0:  reg_dec  =  BRK1_ADDR0_D;
268
    BRK1_ADDR1:  reg_dec  =  BRK1_ADDR1_D;
269
`endif
270
`ifdef DBG_HWBRK_2
271
    BRK2_CTL  :  reg_dec  =  BRK2_CTL_D;
272
    BRK2_STAT :  reg_dec  =  BRK2_STAT_D;
273
    BRK2_ADDR0:  reg_dec  =  BRK2_ADDR0_D;
274
    BRK2_ADDR1:  reg_dec  =  BRK2_ADDR1_D;
275
`endif
276
`ifdef DBG_HWBRK_3
277
    BRK3_CTL  :  reg_dec  =  BRK3_CTL_D;
278
    BRK3_STAT :  reg_dec  =  BRK3_STAT_D;
279
    BRK3_ADDR0:  reg_dec  =  BRK3_ADDR0_D;
280
    BRK3_ADDR1:  reg_dec  =  BRK3_ADDR1_D;
281
`endif
282
    CPU_NR    :  reg_dec  =  CPU_NR_D;
283
  // pragma coverage off
284
    default:     reg_dec  =  {NR_REG{1'b0}};
285
  // pragma coverage on
286
  endcase
287
 
288
// Read/Write probes
289
wire               reg_write =  dbg_wr;
290
wire               reg_read  =  1'b1;
291
 
292
// Read/Write vectors
293
wire  [NR_REG-1:0] reg_wr    = reg_dec & {NR_REG{reg_write}};
294
wire  [NR_REG-1:0] reg_rd    = reg_dec & {NR_REG{reg_read}};
295
 
296
 
297
//=============================================================================
298
// 3)  REGISTER: CORE INTERFACE
299
//=============================================================================
300
 
301
// CPU_ID Register
302
//-----------------   
303
//              -------------------------------------------------------------------
304
// CPU_ID_LO:  | 15  14  13  12  11  10  9  |  8  7  6  5  4  |  3   |   2  1  0   |
305
//             |----------------------------+-----------------+------+-------------|
306
//             |        PER_SPACE           |   USER_VERSION  | ASIC | CPU_VERSION |
307
//              --------------------------------------------------------------------
308
// CPU_ID_HI:  |   15  14  13  12  11  10   |   9  8  7  6  5  4  3  2  1   |   0  |
309
//             |----------------------------+-------------------------------+------|
310
//             |         PMEM_SIZE          |            DMEM_SIZE          |  MPY |
311
//              -------------------------------------------------------------------
312
 
313
// This register is assigned in the SFR module
314
 
315
 
316
// CPU_NR Register
317
//-----------------
318
//    -------------------------------------------------------------------
319
//   | 15  14  13  12  11  10   9   8  |  7   6   5   4   3   2   1   0  |
320
//   |---------------------------------+---------------------------------|
321
//   |            CPU_TOTAL_NR         |           CPU_INST_NR           |
322
//    -------------------------------------------------------------------
323
 
324
wire [15:0] cpu_nr = {cpu_nr_total, cpu_nr_inst};
325
 
326
 
327
// CPU_CTL Register
328
//-----------------------------------------------------------------------------
329
//       7         6          5          4           3        2     1    0
330
//   Reserved   CPU_RST  RST_BRK_EN  FRZ_BRK_EN  SW_BRK_EN  ISTEP  RUN  HALT
331
//-----------------------------------------------------------------------------
332
reg   [6:3] cpu_ctl;
333
 
334
wire        cpu_ctl_wr = reg_wr[CPU_CTL];
335
 
336
always @ (posedge dbg_clk or posedge dbg_rst)
337
`ifdef DBG_RST_BRK_EN
338
  if (dbg_rst)         cpu_ctl <=  4'h6;
339
`else
340
  if (dbg_rst)         cpu_ctl <=  4'h2;
341
`endif
342
  else if (cpu_ctl_wr) cpu_ctl <=  dbg_din[6:3];
343
 
344
wire  [7:0] cpu_ctl_full = {1'b0, cpu_ctl, 3'b000};
345
 
346
wire        halt_cpu = cpu_ctl_wr & dbg_din[`HALT]  & ~dbg_halt_st;
347
wire        run_cpu  = cpu_ctl_wr & dbg_din[`RUN]   &  dbg_halt_st;
348
wire        istep    = cpu_ctl_wr & dbg_din[`ISTEP] &  dbg_halt_st;
349
 
350
 
351
// CPU_STAT Register
352
//------------------------------------------------------------------------------------
353
//      7           6          5           4           3         2      1       0
354
// HWBRK3_PND  HWBRK2_PND  HWBRK1_PND  HWBRK0_PND  SWBRK_PND  PUC_PND  Res.  HALT_RUN
355
//------------------------------------------------------------------------------------
356
reg   [3:2] cpu_stat;
357
 
358
wire        cpu_stat_wr  = reg_wr[CPU_STAT];
359
wire  [3:2] cpu_stat_set = {dbg_swbrk, puc_pnd_set};
360
wire  [3:2] cpu_stat_clr = ~dbg_din[3:2];
361
 
362
always @ (posedge dbg_clk or posedge dbg_rst)
363
  if (dbg_rst)          cpu_stat <=  2'b00;
364
  else if (cpu_stat_wr) cpu_stat <= ((cpu_stat & cpu_stat_clr) | cpu_stat_set);
365
  else                  cpu_stat <=  (cpu_stat                 | cpu_stat_set);
366
 
367
wire  [7:0] cpu_stat_full = {brk3_pnd, brk2_pnd, brk1_pnd, brk0_pnd,
368
                             cpu_stat, 1'b0, dbg_halt_st};
369
 
370
 
371
//=============================================================================
372
// 4)  REGISTER: MEMORY INTERFACE
373
//=============================================================================
374
 
375
// MEM_CTL Register
376
//-----------------------------------------------------------------------------
377
//       7     6     5     4          3        2         1       0
378
//            Reserved               B/W    MEM/REG    RD/WR   START
379
//
380
// START  :  -  0 : Do nothing.
381
//           -  1 : Initiate memory transfer.
382
//
383
// RD/WR  :  -  0 : Read access.
384
//           -  1 : Write access.
385
//
386
// MEM/REG:  -  0 : Memory access.
387
//           -  1 : CPU Register access.
388
//
389
// B/W    :  -  0 : 16 bit access.
390
//           -  1 :  8 bit access (not valid for CPU Registers).
391
//
392
//-----------------------------------------------------------------------------
393
reg   [3:1] mem_ctl;
394
 
395
wire        mem_ctl_wr = reg_wr[MEM_CTL];
396
 
397
always @ (posedge dbg_clk or posedge dbg_rst)
398
  if (dbg_rst)         mem_ctl <=  3'h0;
399
  else if (mem_ctl_wr) mem_ctl <=  dbg_din[3:1];
400
 
401
wire  [7:0] mem_ctl_full  = {4'b0000, mem_ctl, 1'b0};
402
 
403
reg         mem_start;
404
always @ (posedge dbg_clk or posedge dbg_rst)
405
  if (dbg_rst)  mem_start <=  1'b0;
406
  else          mem_start <=  mem_ctl_wr & dbg_din[0];
407
 
408
wire        mem_bw    = mem_ctl[3];
409
 
410
// MEM_DATA Register
411
//------------------   
412
reg  [15:0] mem_data;
413
reg  [15:0] mem_addr;
414
wire        mem_access;
415
 
416
wire        mem_data_wr = reg_wr[MEM_DATA];
417
 
418
wire [15:0] dbg_mem_din_bw = ~mem_bw      ? dbg_mem_din                :
419
                              mem_addr[0] ? {8'h00, dbg_mem_din[15:8]} :
420
                                            {8'h00, dbg_mem_din[7:0]};
421
 
422
always @ (posedge dbg_clk or posedge dbg_rst)
423
  if (dbg_rst)             mem_data <=  16'h0000;
424
  else if (mem_data_wr)    mem_data <=  dbg_din;
425
  else if (dbg_reg_rd)     mem_data <=  dbg_reg_din;
426
  else if (dbg_mem_rd_dly) mem_data <=  dbg_mem_din_bw;
427
 
428
 
429
// MEM_ADDR Register
430
//------------------   
431
reg  [15:0] mem_cnt;
432
 
433
wire        mem_addr_wr  = reg_wr[MEM_ADDR];
434
wire        dbg_mem_acc  = (|dbg_mem_wr | (dbg_rd_rdy & ~mem_ctl[2]));
435
wire        dbg_reg_acc  = ( dbg_reg_wr | (dbg_rd_rdy &  mem_ctl[2]));
436
 
437
wire [15:0] mem_addr_inc = (mem_cnt==16'h0000)         ? 16'h0000 :
438
                           (dbg_mem_acc & ~mem_bw)     ? 16'h0002 :
439
                           (dbg_mem_acc | dbg_reg_acc) ? 16'h0001 : 16'h0000;
440
 
441
always @ (posedge dbg_clk or posedge dbg_rst)
442
  if (dbg_rst)          mem_addr <=  16'h0000;
443
  else if (mem_addr_wr) mem_addr <=  dbg_din;
444
  else                  mem_addr <=  mem_addr + mem_addr_inc;
445
 
446
// MEM_CNT Register
447
//------------------   
448
 
449
wire        mem_cnt_wr  = reg_wr[MEM_CNT];
450
 
451
wire [15:0] mem_cnt_dec = (mem_cnt==16'h0000)                       ? 16'h0000 :
452
                          (mem_burst & (dbg_mem_acc | dbg_reg_acc)) ? 16'hffff : 16'h0000;
453
 
454
always @ (posedge dbg_clk or posedge dbg_rst)
455
  if (dbg_rst)         mem_cnt <=  16'h0000;
456
  else if (mem_cnt_wr) mem_cnt <=  dbg_din;
457
  else                 mem_cnt <=  mem_cnt + mem_cnt_dec;
458
 
459
 
460
//=============================================================================
461
// 5)  BREAKPOINTS / WATCHPOINTS
462
//=============================================================================
463
 
464
`ifdef DBG_HWBRK_0
465
// Hardware Breakpoint/Watchpoint Register read select
466
wire [3:0] brk0_reg_rd = {reg_rd[BRK0_ADDR1],
467
                          reg_rd[BRK0_ADDR0],
468
                          reg_rd[BRK0_STAT],
469
                          reg_rd[BRK0_CTL]};
470
 
471
// Hardware Breakpoint/Watchpoint Register write select
472
wire [3:0] brk0_reg_wr = {reg_wr[BRK0_ADDR1],
473
                          reg_wr[BRK0_ADDR0],
474
                          reg_wr[BRK0_STAT],
475
                          reg_wr[BRK0_CTL]};
476
 
477
omsp_dbg_hwbrk dbg_hwbr_0 (
478
 
479
// OUTPUTs
480
    .brk_halt   (brk0_halt),   // Hardware breakpoint command
481
    .brk_pnd    (brk0_pnd),    // Hardware break/watch-point pending
482
    .brk_dout   (brk0_dout),   // Hardware break/watch-point register data input
483
 
484
// INPUTs
485
    .brk_reg_rd (brk0_reg_rd), // Hardware break/watch-point register read select
486
    .brk_reg_wr (brk0_reg_wr), // Hardware break/watch-point register write select
487
    .dbg_clk    (dbg_clk),     // Debug unit clock
488
    .dbg_din    (dbg_din),     // Debug register data input
489
    .dbg_rst    (dbg_rst),     // Debug unit reset
490
    .eu_mab     (eu_mab),      // Execution-Unit Memory address bus
491
    .eu_mb_en   (eu_mb_en),    // Execution-Unit Memory bus enable
492
    .eu_mb_wr   (eu_mb_wr),    // Execution-Unit Memory bus write transfer
493
    .eu_mdb_in  (eu_mdb_in),   // Memory data bus input
494
    .eu_mdb_out (eu_mdb_out),  // Memory data bus output
495
    .exec_done  (exec_done),   // Execution completed
496
    .fe_mb_en   (fe_mb_en),    // Frontend Memory bus enable
497
    .pc         (pc)           // Program counter
498
);
499
 
500
`else
501
assign brk0_halt =  1'b0;
502
assign brk0_pnd  =  1'b0;
503
assign brk0_dout = 16'h0000;
504
`endif
505
 
506
`ifdef DBG_HWBRK_1
507
// Hardware Breakpoint/Watchpoint Register read select
508
wire [3:0] brk1_reg_rd = {reg_rd[BRK1_ADDR1],
509
                          reg_rd[BRK1_ADDR0],
510
                          reg_rd[BRK1_STAT],
511
                          reg_rd[BRK1_CTL]};
512
 
513
// Hardware Breakpoint/Watchpoint Register write select
514
wire [3:0] brk1_reg_wr = {reg_wr[BRK1_ADDR1],
515
                          reg_wr[BRK1_ADDR0],
516
                          reg_wr[BRK1_STAT],
517
                          reg_wr[BRK1_CTL]};
518
 
519
omsp_dbg_hwbrk dbg_hwbr_1 (
520
 
521
// OUTPUTs
522
    .brk_halt   (brk1_halt),   // Hardware breakpoint command
523
    .brk_pnd    (brk1_pnd),    // Hardware break/watch-point pending
524
    .brk_dout   (brk1_dout),   // Hardware break/watch-point register data input
525
 
526
// INPUTs
527
    .brk_reg_rd (brk1_reg_rd), // Hardware break/watch-point register read select
528
    .brk_reg_wr (brk1_reg_wr), // Hardware break/watch-point register write select
529
    .dbg_clk    (dbg_clk),     // Debug unit clock
530
    .dbg_din    (dbg_din),     // Debug register data input
531
    .dbg_rst    (dbg_rst),     // Debug unit reset
532
    .eu_mab     (eu_mab),      // Execution-Unit Memory address bus
533
    .eu_mb_en   (eu_mb_en),    // Execution-Unit Memory bus enable
534
    .eu_mb_wr   (eu_mb_wr),    // Execution-Unit Memory bus write transfer
535
    .eu_mdb_in  (eu_mdb_in),   // Memory data bus input
536
    .eu_mdb_out (eu_mdb_out),  // Memory data bus output
537
    .exec_done  (exec_done),   // Execution completed
538
    .fe_mb_en   (fe_mb_en),    // Frontend Memory bus enable
539
    .pc         (pc)           // Program counter
540
);
541
 
542
`else
543
assign brk1_halt =  1'b0;
544
assign brk1_pnd  =  1'b0;
545
assign brk1_dout = 16'h0000;
546
`endif
547
 
548
 `ifdef DBG_HWBRK_2
549
// Hardware Breakpoint/Watchpoint Register read select
550
wire [3:0] brk2_reg_rd = {reg_rd[BRK2_ADDR1],
551
                          reg_rd[BRK2_ADDR0],
552
                          reg_rd[BRK2_STAT],
553
                          reg_rd[BRK2_CTL]};
554
 
555
// Hardware Breakpoint/Watchpoint Register write select
556
wire [3:0] brk2_reg_wr = {reg_wr[BRK2_ADDR1],
557
                          reg_wr[BRK2_ADDR0],
558
                          reg_wr[BRK2_STAT],
559
                          reg_wr[BRK2_CTL]};
560
 
561
omsp_dbg_hwbrk dbg_hwbr_2 (
562
 
563
// OUTPUTs
564
    .brk_halt   (brk2_halt),   // Hardware breakpoint command
565
    .brk_pnd    (brk2_pnd),    // Hardware break/watch-point pending
566
    .brk_dout   (brk2_dout),   // Hardware break/watch-point register data input
567
 
568
// INPUTs
569
    .brk_reg_rd (brk2_reg_rd), // Hardware break/watch-point register read select
570
    .brk_reg_wr (brk2_reg_wr), // Hardware break/watch-point register write select
571
    .dbg_clk    (dbg_clk),     // Debug unit clock
572
    .dbg_din    (dbg_din),     // Debug register data input
573
    .dbg_rst    (dbg_rst),     // Debug unit reset
574
    .eu_mab     (eu_mab),      // Execution-Unit Memory address bus
575
    .eu_mb_en   (eu_mb_en),    // Execution-Unit Memory bus enable
576
    .eu_mb_wr   (eu_mb_wr),    // Execution-Unit Memory bus write transfer
577
    .eu_mdb_in  (eu_mdb_in),   // Memory data bus input
578
    .eu_mdb_out (eu_mdb_out),  // Memory data bus output
579
    .exec_done  (exec_done),   // Execution completed
580
    .fe_mb_en   (fe_mb_en),    // Frontend Memory bus enable
581
    .pc         (pc)           // Program counter
582
);
583
 
584
`else
585
assign brk2_halt =  1'b0;
586
assign brk2_pnd  =  1'b0;
587
assign brk2_dout = 16'h0000;
588
`endif
589
 
590
`ifdef DBG_HWBRK_3
591
// Hardware Breakpoint/Watchpoint Register read select
592
wire [3:0] brk3_reg_rd = {reg_rd[BRK3_ADDR1],
593
                          reg_rd[BRK3_ADDR0],
594
                          reg_rd[BRK3_STAT],
595
                          reg_rd[BRK3_CTL]};
596
 
597
// Hardware Breakpoint/Watchpoint Register write select
598
wire [3:0] brk3_reg_wr = {reg_wr[BRK3_ADDR1],
599
                          reg_wr[BRK3_ADDR0],
600
                          reg_wr[BRK3_STAT],
601
                          reg_wr[BRK3_CTL]};
602
 
603
omsp_dbg_hwbrk dbg_hwbr_3 (
604
 
605
// OUTPUTs
606
    .brk_halt   (brk3_halt),   // Hardware breakpoint command
607
    .brk_pnd    (brk3_pnd),    // Hardware break/watch-point pending
608
    .brk_dout   (brk3_dout),   // Hardware break/watch-point register data input
609
 
610
// INPUTs
611
    .brk_reg_rd (brk3_reg_rd), // Hardware break/watch-point register read select
612
    .brk_reg_wr (brk3_reg_wr), // Hardware break/watch-point register write select
613
    .dbg_clk    (dbg_clk),     // Debug unit clock
614
    .dbg_din    (dbg_din),     // Debug register data input
615
    .dbg_rst    (dbg_rst),     // Debug unit reset
616
    .eu_mab     (eu_mab),      // Execution-Unit Memory address bus
617
    .eu_mb_en   (eu_mb_en),    // Execution-Unit Memory bus enable
618
    .eu_mb_wr   (eu_mb_wr),    // Execution-Unit Memory bus write transfer
619
    .eu_mdb_in  (eu_mdb_in),   // Memory data bus input
620
    .eu_mdb_out (eu_mdb_out),  // Memory data bus output
621
    .exec_done  (exec_done),   // Execution completed
622
    .fe_mb_en   (fe_mb_en),    // Frontend Memory bus enable
623
    .pc         (pc)           // Program counter
624
);
625
 
626
`else
627
assign brk3_halt =  1'b0;
628
assign brk3_pnd  =  1'b0;
629
assign brk3_dout = 16'h0000;
630
`endif
631
 
632
 
633
//============================================================================
634
// 6) DATA OUTPUT GENERATION
635
//============================================================================
636
 
637
wire [15:0] cpu_id_lo_rd = cpu_id[15:0]           & {16{reg_rd[CPU_ID_LO]}};
638
wire [15:0] cpu_id_hi_rd = cpu_id[31:16]          & {16{reg_rd[CPU_ID_HI]}};
639
wire [15:0] cpu_ctl_rd   = {8'h00, cpu_ctl_full}  & {16{reg_rd[CPU_CTL]}};
640
wire [15:0] cpu_stat_rd  = {8'h00, cpu_stat_full} & {16{reg_rd[CPU_STAT]}};
641
wire [15:0] mem_ctl_rd   = {8'h00, mem_ctl_full}  & {16{reg_rd[MEM_CTL]}};
642
wire [15:0] mem_data_rd  = mem_data               & {16{reg_rd[MEM_DATA]}};
643
wire [15:0] mem_addr_rd  = mem_addr               & {16{reg_rd[MEM_ADDR]}};
644
wire [15:0] mem_cnt_rd   = mem_cnt                & {16{reg_rd[MEM_CNT]}};
645
wire [15:0] cpu_nr_rd    = cpu_nr                 & {16{reg_rd[CPU_NR]}};
646
 
647
wire [15:0] dbg_dout = cpu_id_lo_rd |
648
                       cpu_id_hi_rd |
649
                       cpu_ctl_rd   |
650
                       cpu_stat_rd  |
651
                       mem_ctl_rd   |
652
                       mem_data_rd  |
653
                       mem_addr_rd  |
654
                       mem_cnt_rd   |
655
                       brk0_dout    |
656
                       brk1_dout    |
657
                       brk2_dout    |
658
                       brk3_dout    |
659
                       cpu_nr_rd;
660
 
661
// Tell UART/I2C interface that the data is ready to be read
662
always @ (posedge dbg_clk or posedge dbg_rst)
663
  if (dbg_rst)                       dbg_rd_rdy  <=  1'b0;
664
  else if (mem_burst | mem_burst_rd) dbg_rd_rdy  <= (dbg_reg_rd | dbg_mem_rd_dly);
665
  else                               dbg_rd_rdy  <=  dbg_rd;
666
 
667
 
668
//============================================================================
669
// 7) CPU CONTROL
670
//============================================================================
671
 
672
// Reset CPU
673
//--------------------------
674
wire dbg_cpu_reset  = cpu_ctl[`CPU_RST];
675
 
676
 
677
// Break after reset
678
//--------------------------
679
wire halt_rst = cpu_ctl[`RST_BRK_EN] & dbg_en_s & puc_pnd_set;
680
 
681
 
682
// Freeze peripherals
683
//--------------------------
684
wire dbg_freeze = dbg_halt_st & (cpu_ctl[`FRZ_BRK_EN] | ~cpu_en_s);
685
 
686
 
687
// Software break
688
//--------------------------
689
assign dbg_swbrk = (fe_mdb_in==`DBG_SWBRK_OP) & decode_noirq & cpu_ctl[`SW_BRK_EN];
690
 
691
 
692
// Single step
693
//--------------------------
694
reg [1:0] inc_step;
695
always @(posedge dbg_clk or posedge dbg_rst)
696
  if (dbg_rst)    inc_step <= 2'b00;
697
  else if (istep) inc_step <= 2'b11;
698
  else            inc_step <= {inc_step[0], 1'b0};
699
 
700
 
701
// Run / Halt
702
//--------------------------
703
reg   halt_flag;
704
 
705
wire  mem_halt_cpu;
706
wire  mem_run_cpu;
707
 
708
wire  halt_flag_clr = run_cpu   | mem_run_cpu;
709
wire  halt_flag_set = halt_cpu  | halt_rst  | dbg_swbrk | mem_halt_cpu |
710
                      brk0_halt | brk1_halt | brk2_halt | brk3_halt;
711
 
712
always @(posedge dbg_clk or posedge dbg_rst)
713
  if (dbg_rst)            halt_flag <= 1'b0;
714
  else if (halt_flag_clr) halt_flag <= 1'b0;
715
  else if (halt_flag_set) halt_flag <= 1'b1;
716
 
717
wire dbg_halt_cmd = (halt_flag | halt_flag_set) & ~inc_step[1];
718
 
719
 
720
//============================================================================
721
// 8) MEMORY CONTROL
722
//============================================================================
723
 
724
// Control Memory bursts
725
//------------------------------
726
 
727
wire mem_burst_start = (mem_start             &  |mem_cnt);
728
wire mem_burst_end   = ((dbg_wr | dbg_rd_rdy) & ~|mem_cnt);
729
 
730
// Detect when burst is on going
731
always @(posedge dbg_clk or posedge dbg_rst)
732
  if (dbg_rst)              mem_burst <= 1'b0;
733
  else if (mem_burst_start) mem_burst <= 1'b1;
734
  else if (mem_burst_end)   mem_burst <= 1'b0;
735
 
736
// Control signals for UART/I2C interface
737
assign mem_burst_rd = (mem_burst_start & ~mem_ctl[1]);
738
assign mem_burst_wr = (mem_burst_start &  mem_ctl[1]);
739
 
740
// Trigger CPU Register or memory access during a burst
741
reg        mem_startb;
742
always @(posedge dbg_clk or posedge dbg_rst)
743
  if (dbg_rst) mem_startb <= 1'b0;
744
  else         mem_startb <= (mem_burst & (dbg_wr | dbg_rd)) | mem_burst_rd;
745
 
746
// Combine single and burst memory start of sequence
747
wire       mem_seq_start = ((mem_start & ~|mem_cnt) | mem_startb);
748
 
749
 
750
// Memory access state machine
751
//------------------------------
752
reg  [1:0] mem_state;
753
reg  [1:0] mem_state_nxt;
754
 
755
// State machine definition
756
parameter  M_IDLE       = 2'h0;
757
parameter  M_SET_BRK    = 2'h1;
758
parameter  M_ACCESS_BRK = 2'h2;
759
parameter  M_ACCESS     = 2'h3;
760
 
761
// State transition
762
always @(mem_state or mem_seq_start or dbg_halt_st)
763
  case (mem_state)
764
    M_IDLE       : mem_state_nxt = ~mem_seq_start ? M_IDLE       :
765
                                    dbg_halt_st   ? M_ACCESS     : M_SET_BRK;
766
    M_SET_BRK    : mem_state_nxt =  dbg_halt_st   ? M_ACCESS_BRK : M_SET_BRK;
767
    M_ACCESS_BRK : mem_state_nxt =  M_IDLE;
768
    M_ACCESS     : mem_state_nxt =  M_IDLE;
769
  // pragma coverage off
770
    default      : mem_state_nxt =  M_IDLE;
771
  // pragma coverage on
772
  endcase
773
 
774
// State machine
775
always @(posedge dbg_clk or posedge dbg_rst)
776
  if (dbg_rst) mem_state <= M_IDLE;
777
  else         mem_state <= mem_state_nxt;
778
 
779
// Utility signals
780
assign mem_halt_cpu = (mem_state==M_IDLE)       & (mem_state_nxt==M_SET_BRK);
781
assign mem_run_cpu  = (mem_state==M_ACCESS_BRK) & (mem_state_nxt==M_IDLE);
782
assign mem_access   = (mem_state==M_ACCESS)     | (mem_state==M_ACCESS_BRK);
783
 
784
 
785
// Interface to CPU Registers and Memory bacbkone
786
//------------------------------------------------
787
assign      dbg_mem_addr   =  mem_addr;
788
assign      dbg_mem_dout   = ~mem_bw      ? mem_data               :
789
                              mem_addr[0] ? {mem_data[7:0], 8'h00} :
790
                                            {8'h00, mem_data[7:0]};
791
 
792
assign      dbg_reg_wr     = mem_access &  mem_ctl[1] &  mem_ctl[2];
793
assign      dbg_reg_rd     = mem_access & ~mem_ctl[1] &  mem_ctl[2];
794
 
795
assign      dbg_mem_en     = mem_access & ~mem_ctl[2];
796
assign      dbg_mem_rd     = dbg_mem_en & ~mem_ctl[1];
797
 
798
wire  [1:0] dbg_mem_wr_msk = ~mem_bw      ? 2'b11 :
799
                              mem_addr[0] ? 2'b10 : 2'b01;
800
assign      dbg_mem_wr     = {2{dbg_mem_en & mem_ctl[1]}} & dbg_mem_wr_msk;
801
 
802
 
803
// It takes one additional cycle to read from Memory as from registers
804
always @(posedge dbg_clk or posedge dbg_rst)
805
  if (dbg_rst) dbg_mem_rd_dly <= 1'b0;
806
  else         dbg_mem_rd_dly <= dbg_mem_rd;
807
 
808
 
809
//=============================================================================
810
// 9)  UART COMMUNICATION
811
//=============================================================================
812
`ifdef DBG_UART
813
omsp_dbg_uart dbg_uart_0 (
814
 
815
// OUTPUTs
816
    .dbg_addr         (dbg_addr),         // Debug register address
817
    .dbg_din          (dbg_din),          // Debug register data input
818
    .dbg_rd           (dbg_rd),           // Debug register data read
819
    .dbg_uart_txd     (dbg_uart_txd),     // Debug interface: UART TXD
820
    .dbg_wr           (dbg_wr),           // Debug register data write
821
 
822
// INPUTs
823
    .dbg_clk          (dbg_clk),          // Debug unit clock
824
    .dbg_dout         (dbg_dout),         // Debug register data output
825
    .dbg_rd_rdy       (dbg_rd_rdy),       // Debug register data is ready for read
826
    .dbg_rst          (dbg_rst),          // Debug unit reset
827
    .dbg_uart_rxd     (dbg_uart_rxd),     // Debug interface: UART RXD
828
    .mem_burst        (mem_burst),        // Burst on going
829
    .mem_burst_end    (mem_burst_end),    // End TX/RX burst
830
    .mem_burst_rd     (mem_burst_rd),     // Start TX burst
831
    .mem_burst_wr     (mem_burst_wr),     // Start RX burst
832
    .mem_bw           (mem_bw)            // Burst byte width
833
);
834
 
835
`else
836
    assign dbg_uart_txd    =  1'b1;
837
  `ifdef DBG_I2C
838
  `else
839
    assign dbg_addr        =  6'h00;
840
    assign dbg_din         = 16'h0000;
841
    assign dbg_rd          =  1'b0;
842
    assign dbg_wr          =  1'b0;
843
  `endif
844
`endif
845
 
846
//=============================================================================
847
// 10)  I2C COMMUNICATION
848
//=============================================================================
849
`ifdef DBG_I2C
850
omsp_dbg_i2c dbg_i2c_0 (
851
 
852
// OUTPUTs
853
    .dbg_addr          (dbg_addr),          // Debug register address
854
    .dbg_din           (dbg_din),           // Debug register data input
855
    .dbg_i2c_sda_out   (dbg_i2c_sda_out),   // Debug interface: I2C SDA OUT
856
    .dbg_rd            (dbg_rd),            // Debug register data read
857
    .dbg_wr            (dbg_wr),            // Debug register data write
858
 
859
// INPUTs
860
    .dbg_clk           (dbg_clk),           // Debug unit clock
861
    .dbg_dout          (dbg_dout),          // Debug register data output
862
    .dbg_i2c_addr      (dbg_i2c_addr),      // Debug interface: I2C Address
863
    .dbg_i2c_broadcast (dbg_i2c_broadcast), // Debug interface: I2C Broadcast Address (for multicore systems)
864
    .dbg_i2c_scl       (dbg_i2c_scl),       // Debug interface: I2C SCL
865
    .dbg_i2c_sda_in    (dbg_i2c_sda_in),    // Debug interface: I2C SDA IN
866
    .dbg_rd_rdy        (dbg_rd_rdy),        // Debug register data is ready for read
867
    .dbg_rst           (dbg_rst),           // Debug unit reset
868
    .mem_burst         (mem_burst),         // Burst on going
869
    .mem_burst_end     (mem_burst_end),     // End TX/RX burst
870
    .mem_burst_rd      (mem_burst_rd),      // Start TX burst
871
    .mem_burst_wr      (mem_burst_wr),      // Start RX burst
872
    .mem_bw            (mem_bw)             // Burst byte width
873
);
874
 
875
`else
876
    assign dbg_i2c_sda_out =  1'b1;
877
`endif
878
 
879
endmodule // omsp_dbg
880
 
881
`ifdef OMSP_NO_INCLUDE
882
`else
883
`include "openMSP430_undefines.v"
884
`endif

powered by: WebSVN 2.1.0

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