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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [bench/] [verilog/] [tb_openMSP430.v] - Blame information for rev 226

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

Line No. Rev Author Line
1 2 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2001 Authors
3
//
4
// This source file may be used and distributed without restriction provided
5
// that this copyright statement is not removed from the file and that any
6
// derivative work contains the original copyright notice and the associated
7
// disclaimer.
8
//
9
// This source file is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as published
11
// by the Free Software Foundation; either version 2.1 of the License, or
12
// (at your option) any later version.
13
//
14
// This source is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
// License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public License
20
// along with this source; if not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
//
23
//----------------------------------------------------------------------------
24 200 olivier.gi
//
25 2 olivier.gi
// *File Name: tb_openMSP430.v
26 200 olivier.gi
//
27 2 olivier.gi
// *Module Description:
28
//                      openMSP430 testbench
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 17 olivier.gi
// $Rev: 205 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2015-07-15 22:59:52 +0200 (Wed, 15 Jul 2015) $
37
//----------------------------------------------------------------------------
38 23 olivier.gi
`include "timescale.v"
39 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
40
`else
41 23 olivier.gi
`include "openMSP430_defines.v"
42 103 olivier.gi
`endif
43 2 olivier.gi
 
44
module  tb_openMSP430;
45
 
46
//
47
// Wire & Register definition
48
//------------------------------
49
 
50 33 olivier.gi
// Data Memory interface
51
wire [`DMEM_MSB:0] dmem_addr;
52
wire               dmem_cen;
53
wire        [15:0] dmem_din;
54
wire         [1:0] dmem_wen;
55
wire        [15:0] dmem_dout;
56 2 olivier.gi
 
57 33 olivier.gi
// Program Memory interface
58
wire [`PMEM_MSB:0] pmem_addr;
59
wire               pmem_cen;
60
wire        [15:0] pmem_din;
61
wire         [1:0] pmem_wen;
62
wire        [15:0] pmem_dout;
63 2 olivier.gi
 
64
// Peripherals interface
65 111 olivier.gi
wire        [13:0] per_addr;
66 33 olivier.gi
wire        [15:0] per_din;
67
wire        [15:0] per_dout;
68 106 olivier.gi
wire         [1:0] per_we;
69 33 olivier.gi
wire               per_en;
70 2 olivier.gi
 
71 202 olivier.gi
// Direct Memory Access interface
72
wire        [15:0] dma_dout;
73
wire               dma_ready;
74
wire               dma_resp;
75
reg         [15:1] dma_addr;
76
reg         [15:0] dma_din;
77
reg                dma_en;
78
reg                dma_priority;
79
reg          [1:0] dma_we;
80
reg                dma_wkup;
81
 
82 2 olivier.gi
// Digital I/O
83 33 olivier.gi
wire               irq_port1;
84
wire               irq_port2;
85
wire        [15:0] per_dout_dio;
86
wire         [7:0] p1_dout;
87
wire         [7:0] p1_dout_en;
88
wire         [7:0] p1_sel;
89
wire         [7:0] p2_dout;
90
wire         [7:0] p2_dout_en;
91
wire         [7:0] p2_sel;
92
wire         [7:0] p3_dout;
93
wire         [7:0] p3_dout_en;
94
wire         [7:0] p3_sel;
95
wire         [7:0] p4_dout;
96
wire         [7:0] p4_dout_en;
97
wire         [7:0] p4_sel;
98
wire         [7:0] p5_dout;
99
wire         [7:0] p5_dout_en;
100
wire         [7:0] p5_sel;
101
wire         [7:0] p6_dout;
102
wire         [7:0] p6_dout_en;
103
wire         [7:0] p6_sel;
104
reg          [7:0] p1_din;
105
reg          [7:0] p2_din;
106
reg          [7:0] p3_din;
107
reg          [7:0] p4_din;
108
reg          [7:0] p5_din;
109
reg          [7:0] p6_din;
110 2 olivier.gi
 
111
// Peripheral templates
112 33 olivier.gi
wire        [15:0] per_dout_temp_8b;
113
wire        [15:0] per_dout_temp_16b;
114 2 olivier.gi
 
115
// Timer A
116 33 olivier.gi
wire               irq_ta0;
117
wire               irq_ta1;
118
wire        [15:0] per_dout_timerA;
119
reg                inclk;
120
reg                taclk;
121
reg                ta_cci0a;
122
reg                ta_cci0b;
123
reg                ta_cci1a;
124
reg                ta_cci1b;
125
reg                ta_cci2a;
126
reg                ta_cci2b;
127
wire               ta_out0;
128
wire               ta_out0_en;
129
wire               ta_out1;
130
wire               ta_out1_en;
131
wire               ta_out2;
132
wire               ta_out2_en;
133 200 olivier.gi
 
134 2 olivier.gi
// Clock / Reset & Interrupts
135 33 olivier.gi
reg                dco_clk;
136 134 olivier.gi
wire               dco_enable;
137
wire               dco_wkup;
138
reg                dco_local_enable;
139 33 olivier.gi
reg                lfxt_clk;
140 134 olivier.gi
wire               lfxt_enable;
141
wire               lfxt_wkup;
142
reg                lfxt_local_enable;
143 33 olivier.gi
wire               mclk;
144 134 olivier.gi
wire               aclk;
145 33 olivier.gi
wire               aclk_en;
146 134 olivier.gi
wire               smclk;
147 33 olivier.gi
wire               smclk_en;
148
reg                reset_n;
149 111 olivier.gi
wire               puc_rst;
150 33 olivier.gi
reg                nmi;
151 192 olivier.gi
reg  [`IRQ_NR-3:0] irq;
152
wire [`IRQ_NR-3:0] irq_acc;
153
wire [`IRQ_NR-3:0] irq_in;
154 106 olivier.gi
reg                cpu_en;
155 134 olivier.gi
reg         [13:0] wkup;
156
wire        [13:0] wkup_in;
157 200 olivier.gi
 
158 134 olivier.gi
// Scan (ASIC version only)
159
reg                scan_enable;
160
reg                scan_mode;
161
 
162 154 olivier.gi
// Debug interface: UART
163 106 olivier.gi
reg                dbg_en;
164 33 olivier.gi
wire               dbg_freeze;
165
wire               dbg_uart_txd;
166 134 olivier.gi
wire               dbg_uart_rxd;
167
reg                dbg_uart_rxd_sel;
168
reg                dbg_uart_rxd_dly;
169
reg                dbg_uart_rxd_pre;
170
reg                dbg_uart_rxd_meta;
171 33 olivier.gi
reg         [15:0] dbg_uart_buf;
172 134 olivier.gi
reg                dbg_uart_rx_busy;
173
reg                dbg_uart_tx_busy;
174 2 olivier.gi
 
175 154 olivier.gi
// Debug interface: I2C
176
wire               dbg_scl;
177
wire               dbg_sda;
178
wire               dbg_scl_slave;
179
wire               dbg_scl_master;
180
reg                dbg_scl_master_sel;
181
reg                dbg_scl_master_dly;
182
reg                dbg_scl_master_pre;
183
reg                dbg_scl_master_meta;
184
wire               dbg_sda_slave_out;
185
wire               dbg_sda_slave_in;
186
wire               dbg_sda_master_out;
187
reg                dbg_sda_master_out_sel;
188
reg                dbg_sda_master_out_dly;
189
reg                dbg_sda_master_out_pre;
190
reg                dbg_sda_master_out_meta;
191
wire               dbg_sda_master_in;
192
reg         [15:0] dbg_i2c_buf;
193
reg     [8*32-1:0] dbg_i2c_string;
194
 
195 2 olivier.gi
// Core testbench debuging signals
196 33 olivier.gi
wire    [8*32-1:0] i_state;
197
wire    [8*32-1:0] e_state;
198
wire        [31:0] inst_cycle;
199
wire    [8*32-1:0] inst_full;
200
wire        [31:0] inst_number;
201
wire        [15:0] inst_pc;
202
wire    [8*32-1:0] inst_short;
203 200 olivier.gi
 
204 2 olivier.gi
// Testbench variables
205 200 olivier.gi
integer            tb_idx;
206 202 olivier.gi
integer            tmp_seed;
207 33 olivier.gi
integer            error;
208
reg                stimulus_done;
209 2 olivier.gi
 
210
 
211
//
212
// Include files
213
//------------------------------
214
 
215
// CPU & Memory registers
216
`include "registers.v"
217
 
218
// Debug interface tasks
219
`include "dbg_uart_tasks.v"
220 154 olivier.gi
`include "dbg_i2c_tasks.v"
221 2 olivier.gi
 
222 202 olivier.gi
// Direct Memory Access interface tasks
223
`include "dma_tasks.v"
224
 
225 2 olivier.gi
// Verilog stimulus
226
`include "stimulus.v"
227
 
228 200 olivier.gi
 
229 2 olivier.gi
//
230 200 olivier.gi
// Initialize Memory
231 2 olivier.gi
//------------------------------
232
initial
233
  begin
234 200 olivier.gi
     // Initialize data memory
235
     for (tb_idx=0; tb_idx < `DMEM_SIZE/2; tb_idx=tb_idx+1)
236
       dmem_0.mem[tb_idx] = 16'h0000;
237
 
238
     // Initialize program memory
239 94 olivier.gi
     #10 $readmemh("./pmem.mem", pmem_0.mem);
240 2 olivier.gi
  end
241
 
242 200 olivier.gi
 
243 2 olivier.gi
//
244
// Generate Clock & Reset
245
//------------------------------
246
initial
247
  begin
248 134 olivier.gi
     dco_clk          = 1'b0;
249
     dco_local_enable = 1'b0;
250
     forever
251
       begin
252 192 olivier.gi
          #25;   // 20 MHz
253
          dco_local_enable = (dco_enable===1) ? dco_enable : (dco_wkup===1);
254 205 olivier.gi
          if (dco_local_enable | scan_mode)
255 192 olivier.gi
            dco_clk = ~dco_clk;
256 134 olivier.gi
       end
257 2 olivier.gi
  end
258 134 olivier.gi
 
259 2 olivier.gi
initial
260
  begin
261 134 olivier.gi
     lfxt_clk          = 1'b0;
262
     lfxt_local_enable = 1'b0;
263
     forever
264
       begin
265 192 olivier.gi
          #763;  // 655 kHz
266
          lfxt_local_enable = (lfxt_enable===1) ? lfxt_enable : (lfxt_wkup===1);
267
          if (lfxt_local_enable)
268
            lfxt_clk = ~lfxt_clk;
269 134 olivier.gi
       end
270 2 olivier.gi
  end
271
 
272
initial
273
  begin
274
     reset_n       = 1'b1;
275 106 olivier.gi
     #93;
276 2 olivier.gi
     reset_n       = 1'b0;
277 106 olivier.gi
     #593;
278 2 olivier.gi
     reset_n       = 1'b1;
279
  end
280
 
281
initial
282
  begin
283 202 olivier.gi
     tmp_seed                = `SEED;
284
     tmp_seed                = $urandom(tmp_seed);
285 154 olivier.gi
     error                   = 0;
286
     stimulus_done           = 1;
287 192 olivier.gi
     irq                     = {`IRQ_NR-2{1'b0}};
288 154 olivier.gi
     nmi                     = 1'b0;
289
     wkup                    = 14'h0000;
290 202 olivier.gi
     dma_addr                = 15'h0000;
291
     dma_din                 = 16'h0000;
292
     dma_en                  = 1'b0;
293
     dma_priority            = 1'b0;
294
     dma_we                  = 2'b00;
295
     dma_wkup                = 1'b0;
296
     dma_tfx_cancel          = 1'b0;
297 154 olivier.gi
     cpu_en                  = 1'b1;
298
     dbg_en                  = 1'b0;
299
     dbg_uart_rxd_sel        = 1'b0;
300
     dbg_uart_rxd_dly        = 1'b1;
301
     dbg_uart_rxd_pre        = 1'b1;
302
     dbg_uart_rxd_meta       = 1'b0;
303
     dbg_uart_buf            = 16'h0000;
304
     dbg_uart_rx_busy        = 1'b0;
305
     dbg_uart_tx_busy        = 1'b0;
306
     dbg_scl_master_sel      = 1'b0;
307
     dbg_scl_master_dly      = 1'b1;
308
     dbg_scl_master_pre      = 1'b1;
309
     dbg_scl_master_meta     = 1'b0;
310
     dbg_sda_master_out_sel  = 1'b0;
311
     dbg_sda_master_out_dly  = 1'b1;
312
     dbg_sda_master_out_pre  = 1'b1;
313
     dbg_sda_master_out_meta = 1'b0;
314
     dbg_i2c_string          = "";
315
     p1_din                  = 8'h00;
316
     p2_din                  = 8'h00;
317
     p3_din                  = 8'h00;
318
     p4_din                  = 8'h00;
319
     p5_din                  = 8'h00;
320
     p6_din                  = 8'h00;
321
     inclk                   = 1'b0;
322
     taclk                   = 1'b0;
323
     ta_cci0a                = 1'b0;
324
     ta_cci0b                = 1'b0;
325
     ta_cci1a                = 1'b0;
326
     ta_cci1b                = 1'b0;
327
     ta_cci2a                = 1'b0;
328
     ta_cci2b                = 1'b0;
329
     scan_enable             = 1'b0;
330
     scan_mode               = 1'b0;
331 2 olivier.gi
  end
332
 
333 200 olivier.gi
 
334 2 olivier.gi
//
335 33 olivier.gi
// Program Memory
336 2 olivier.gi
//----------------------------------
337
 
338 72 olivier.gi
ram #(`PMEM_MSB, `PMEM_SIZE) pmem_0 (
339 2 olivier.gi
 
340
// OUTPUTs
341 202 olivier.gi
    .ram_dout          (pmem_dout),            // Program Memory data output
342 2 olivier.gi
 
343
// INPUTs
344 202 olivier.gi
    .ram_addr          (pmem_addr),            // Program Memory address
345
    .ram_cen           (pmem_cen),             // Program Memory chip enable (low active)
346
    .ram_clk           (mclk),                 // Program Memory clock
347
    .ram_din           (pmem_din),             // Program Memory data input
348
    .ram_wen           (pmem_wen)              // Program Memory write enable (low active)
349 2 olivier.gi
);
350
 
351
 
352
//
353 33 olivier.gi
// Data Memory
354 2 olivier.gi
//----------------------------------
355
 
356 72 olivier.gi
ram #(`DMEM_MSB, `DMEM_SIZE) dmem_0 (
357 2 olivier.gi
 
358
// OUTPUTs
359 202 olivier.gi
    .ram_dout          (dmem_dout),            // Data Memory data output
360 2 olivier.gi
 
361
// INPUTs
362 202 olivier.gi
    .ram_addr          (dmem_addr),            // Data Memory address
363
    .ram_cen           (dmem_cen),             // Data Memory chip enable (low active)
364
    .ram_clk           (mclk),                 // Data Memory clock
365
    .ram_din           (dmem_din),             // Data Memory data input
366
    .ram_wen           (dmem_wen)              // Data Memory write enable (low active)
367 2 olivier.gi
);
368
 
369
 
370
//
371
// openMSP430 Instance
372
//----------------------------------
373
 
374
openMSP430 dut (
375
 
376
// OUTPUTs
377 202 olivier.gi
    .aclk              (aclk),                 // ASIC ONLY: ACLK
378
    .aclk_en           (aclk_en),              // FPGA ONLY: ACLK enable
379
    .dbg_freeze        (dbg_freeze),           // Freeze peripherals
380
    .dbg_i2c_sda_out   (dbg_sda_slave_out),    // Debug interface: I2C SDA OUT
381
    .dbg_uart_txd      (dbg_uart_txd),         // Debug interface: UART TXD
382
    .dco_enable        (dco_enable),           // ASIC ONLY: Fast oscillator enable
383
    .dco_wkup          (dco_wkup),             // ASIC ONLY: Fast oscillator wake-up (asynchronous)
384
    .dmem_addr         (dmem_addr),            // Data Memory address
385
    .dmem_cen          (dmem_cen),             // Data Memory chip enable (low active)
386
    .dmem_din          (dmem_din),             // Data Memory data input
387
    .dmem_wen          (dmem_wen),             // Data Memory write byte enable (low active)
388
    .irq_acc           (irq_acc),              // Interrupt request accepted (one-hot signal)
389
    .lfxt_enable       (lfxt_enable),          // ASIC ONLY: Low frequency oscillator enable
390
    .lfxt_wkup         (lfxt_wkup),            // ASIC ONLY: Low frequency oscillator wake-up (asynchronous)
391
    .mclk              (mclk),                 // Main system clock
392
    .dma_dout          (dma_dout),             // Direct Memory Access data output
393
    .dma_ready         (dma_ready),            // Direct Memory Access is complete
394
    .dma_resp          (dma_resp),             // Direct Memory Access response (0:Okay / 1:Error)
395
    .per_addr          (per_addr),             // Peripheral address
396
    .per_din           (per_din),              // Peripheral data input
397
    .per_en            (per_en),               // Peripheral enable (high active)
398
    .per_we            (per_we),               // Peripheral write byte enable (high active)
399
    .pmem_addr         (pmem_addr),            // Program Memory address
400
    .pmem_cen          (pmem_cen),             // Program Memory chip enable (low active)
401
    .pmem_din          (pmem_din),             // Program Memory data input (optional)
402
    .pmem_wen          (pmem_wen),             // Program Memory write byte enable (low active) (optional)
403
    .puc_rst           (puc_rst),              // Main system reset
404
    .smclk             (smclk),                // ASIC ONLY: SMCLK
405
    .smclk_en          (smclk_en),             // FPGA ONLY: SMCLK enable
406 2 olivier.gi
 
407
// INPUTs
408 202 olivier.gi
    .cpu_en            (cpu_en),               // Enable CPU code execution (asynchronous)
409
    .dbg_en            (dbg_en),               // Debug interface enable (asynchronous)
410
    .dbg_i2c_addr      (I2C_ADDR),             // Debug interface: I2C Address
411
    .dbg_i2c_broadcast (I2C_BROADCAST),        // Debug interface: I2C Broadcast Address (for multicore systems)
412
    .dbg_i2c_scl       (dbg_scl_slave),        // Debug interface: I2C SCL
413
    .dbg_i2c_sda_in    (dbg_sda_slave_in),     // Debug interface: I2C SDA IN
414
    .dbg_uart_rxd      (dbg_uart_rxd),         // Debug interface: UART RXD (asynchronous)
415
    .dco_clk           (dco_clk),              // Fast oscillator (fast clock)
416
    .dmem_dout         (dmem_dout),            // Data Memory data output
417
    .irq               (irq_in),               // Maskable interrupts
418
    .lfxt_clk          (lfxt_clk),             // Low frequency oscillator (typ 32kHz)
419
    .dma_addr          (dma_addr),             // Direct Memory Access address
420
    .dma_din           (dma_din),              // Direct Memory Access data input
421
    .dma_en            (dma_en),               // Direct Memory Access enable (high active)
422
    .dma_priority      (dma_priority),         // Direct Memory Access priority (0:low / 1:high)
423
    .dma_we            (dma_we),               // Direct Memory Access write byte enable (high active)
424
    .dma_wkup          (dma_wkup),             // ASIC ONLY: DMA Sub-System Wake-up (asynchronous and non-glitchy)
425
    .nmi               (nmi),                  // Non-maskable interrupt (asynchronous)
426
    .per_dout          (per_dout),             // Peripheral data output
427
    .pmem_dout         (pmem_dout),            // Program Memory data output
428
    .reset_n           (reset_n),              // Reset Pin (low active, asynchronous)
429
    .scan_enable       (scan_enable),          // ASIC ONLY: Scan enable (active during scan shifting)
430
    .scan_mode         (scan_mode),            // ASIC ONLY: Scan mode
431
    .wkup              (|wkup_in)              // ASIC ONLY: System Wake-up (asynchronous)
432 2 olivier.gi
);
433
 
434
//
435
// Digital I/O
436
//----------------------------------
437
 
438 99 olivier.gi
`ifdef CVER
439
omsp_gpio #(1,
440
            1,
441
            1,
442
            1,
443
            1,
444
            1)         gpio_0 (
445
`else
446 34 olivier.gi
omsp_gpio #(.P1_EN(1),
447
            .P2_EN(1),
448
            .P3_EN(1),
449
            .P4_EN(1),
450
            .P5_EN(1),
451
            .P6_EN(1)) gpio_0 (
452 99 olivier.gi
`endif
453 2 olivier.gi
 
454
// OUTPUTs
455 202 olivier.gi
    .irq_port1         (irq_port1),            // Port 1 interrupt
456
    .irq_port2         (irq_port2),            // Port 2 interrupt
457
    .p1_dout           (p1_dout),              // Port 1 data output
458
    .p1_dout_en        (p1_dout_en),           // Port 1 data output enable
459
    .p1_sel            (p1_sel),               // Port 1 function select
460
    .p2_dout           (p2_dout),              // Port 2 data output
461
    .p2_dout_en        (p2_dout_en),           // Port 2 data output enable
462
    .p2_sel            (p2_sel),               // Port 2 function select
463
    .p3_dout           (p3_dout),              // Port 3 data output
464
    .p3_dout_en        (p3_dout_en),           // Port 3 data output enable
465
    .p3_sel            (p3_sel),               // Port 3 function select
466
    .p4_dout           (p4_dout),              // Port 4 data output
467
    .p4_dout_en        (p4_dout_en),           // Port 4 data output enable
468
    .p4_sel            (p4_sel),               // Port 4 function select
469
    .p5_dout           (p5_dout),              // Port 5 data output
470
    .p5_dout_en        (p5_dout_en),           // Port 5 data output enable
471
    .p5_sel            (p5_sel),               // Port 5 function select
472
    .p6_dout           (p6_dout),              // Port 6 data output
473
    .p6_dout_en        (p6_dout_en),           // Port 6 data output enable
474
    .p6_sel            (p6_sel),               // Port 6 function select
475
    .per_dout          (per_dout_dio),         // Peripheral data output
476 200 olivier.gi
 
477 2 olivier.gi
// INPUTs
478 202 olivier.gi
    .mclk              (mclk),                 // Main system clock
479
    .p1_din            (p1_din),               // Port 1 data input
480
    .p2_din            (p2_din),               // Port 2 data input
481
    .p3_din            (p3_din),               // Port 3 data input
482
    .p4_din            (p4_din),               // Port 4 data input
483
    .p5_din            (p5_din),               // Port 5 data input
484
    .p6_din            (p6_din),               // Port 6 data input
485
    .per_addr          (per_addr),             // Peripheral address
486
    .per_din           (per_din),              // Peripheral data input
487
    .per_en            (per_en),               // Peripheral enable (high active)
488
    .per_we            (per_we),               // Peripheral write enable (high active)
489
    .puc_rst           (puc_rst)               // Main system reset
490 2 olivier.gi
);
491
 
492
//
493
// Timers
494
//----------------------------------
495
 
496 34 olivier.gi
omsp_timerA timerA_0 (
497 2 olivier.gi
 
498
// OUTPUTs
499 202 olivier.gi
    .irq_ta0           (irq_ta0),              // Timer A interrupt: TACCR0
500
    .irq_ta1           (irq_ta1),              // Timer A interrupt: TAIV, TACCR1, TACCR2
501
    .per_dout          (per_dout_timerA),      // Peripheral data output
502
    .ta_out0           (ta_out0),              // Timer A output 0
503
    .ta_out0_en        (ta_out0_en),           // Timer A output 0 enable
504
    .ta_out1           (ta_out1),              // Timer A output 1
505
    .ta_out1_en        (ta_out1_en),           // Timer A output 1 enable
506
    .ta_out2           (ta_out2),              // Timer A output 2
507
    .ta_out2_en        (ta_out2_en),           // Timer A output 2 enable
508 2 olivier.gi
 
509
// INPUTs
510 202 olivier.gi
    .aclk_en           (aclk_en),              // ACLK enable (from CPU)
511
    .dbg_freeze        (dbg_freeze),           // Freeze Timer A counter
512
    .inclk             (inclk),                // INCLK external timer clock (SLOW)
513
    .irq_ta0_acc       (irq_acc[`IRQ_NR-7]),   // Interrupt request TACCR0 accepted
514
    .mclk              (mclk),                 // Main system clock
515
    .per_addr          (per_addr),             // Peripheral address
516
    .per_din           (per_din),              // Peripheral data input
517
    .per_en            (per_en),               // Peripheral enable (high active)
518
    .per_we            (per_we),               // Peripheral write enable (high active)
519
    .puc_rst           (puc_rst),              // Main system reset
520
    .smclk_en          (smclk_en),             // SMCLK enable (from CPU)
521
    .ta_cci0a          (ta_cci0a),             // Timer A compare 0 input A
522
    .ta_cci0b          (ta_cci0b),             // Timer A compare 0 input B
523
    .ta_cci1a          (ta_cci1a),             // Timer A compare 1 input A
524
    .ta_cci1b          (ta_cci1b),             // Timer A compare 1 input B
525
    .ta_cci2a          (ta_cci2a),             // Timer A compare 2 input A
526
    .ta_cci2b          (ta_cci2b),             // Timer A compare 2 input B
527
    .taclk             (taclk)                 // TACLK external timer clock (SLOW)
528 2 olivier.gi
);
529 134 olivier.gi
 
530
//
531 2 olivier.gi
// Peripheral templates
532
//----------------------------------
533
 
534
template_periph_8b template_periph_8b_0 (
535
 
536
// OUTPUTs
537 202 olivier.gi
    .per_dout          (per_dout_temp_8b),     // Peripheral data output
538 2 olivier.gi
 
539
// INPUTs
540 202 olivier.gi
    .mclk              (mclk),                 // Main system clock
541
    .per_addr          (per_addr),             // Peripheral address
542
    .per_din           (per_din),              // Peripheral data input
543
    .per_en            (per_en),               // Peripheral enable (high active)
544
    .per_we            (per_we),               // Peripheral write enable (high active)
545
    .puc_rst           (puc_rst)               // Main system reset
546 2 olivier.gi
);
547
 
548 111 olivier.gi
`ifdef CVER
549 202 olivier.gi
template_periph_16b #(15'h0190)                                        template_periph_16b_0 (
550 111 olivier.gi
`else
551 151 olivier.gi
template_periph_16b #(.BASE_ADDR((15'd`PER_SIZE-15'h0070) & 15'h7ff8)) template_periph_16b_0 (
552 111 olivier.gi
`endif
553 2 olivier.gi
// OUTPUTs
554 202 olivier.gi
    .per_dout          (per_dout_temp_16b),    // Peripheral data output
555 2 olivier.gi
 
556
// INPUTs
557 202 olivier.gi
    .mclk              (mclk),                 // Main system clock
558
    .per_addr          (per_addr),             // Peripheral address
559
    .per_din           (per_din),              // Peripheral data input
560
    .per_en            (per_en),               // Peripheral enable (high active)
561
    .per_we            (per_we),               // Peripheral write enable (high active)
562
    .puc_rst           (puc_rst)               // Main system reset
563 2 olivier.gi
);
564
 
565
 
566
//
567
// Combine peripheral data bus
568
//----------------------------------
569
 
570
assign per_dout = per_dout_dio       |
571
                  per_dout_timerA    |
572
                  per_dout_temp_8b   |
573
                  per_dout_temp_16b;
574
 
575
 
576
//
577 134 olivier.gi
// Map peripheral interrupts & wakeups
578 2 olivier.gi
//----------------------------------------
579
 
580 192 olivier.gi
assign irq_in  = irq  | {1'b0,                 // Vector 13  (0xFFFA)
581
                         1'b0,                 // Vector 12  (0xFFF8)
582
                         1'b0,                 // Vector 11  (0xFFF6)
583
                         1'b0,                 // Vector 10  (0xFFF4) - Watchdog -
584
                         irq_ta0,              // Vector  9  (0xFFF2)
585
                         irq_ta1,              // Vector  8  (0xFFF0)
586 200 olivier.gi
                         1'b0,                 // Vector  7  (0xFFEE)
587
                         1'b0,                 // Vector  6  (0xFFEC)
588 192 olivier.gi
                         1'b0,                 // Vector  5  (0xFFEA)
589
                         1'b0,                 // Vector  4  (0xFFE8)
590
                         irq_port2,            // Vector  3  (0xFFE6)
591
                         irq_port1,            // Vector  2  (0xFFE4)
592
                         1'b0,                 // Vector  1  (0xFFE2)
593
                         {`IRQ_NR-15{1'b0}}};  // Vector  0  (0xFFE0)
594 2 olivier.gi
 
595 192 olivier.gi
assign wkup_in = wkup | {1'b0,                 // Vector 13  (0xFFFA)
596
                         1'b0,                 // Vector 12  (0xFFF8)
597
                         1'b0,                 // Vector 11  (0xFFF6)
598
                         1'b0,                 // Vector 10  (0xFFF4) - Watchdog -
599
                         1'b0,                 // Vector  9  (0xFFF2)
600
                         1'b0,                 // Vector  8  (0xFFF0)
601
                         1'b0,                 // Vector  7  (0xFFEE)
602
                         1'b0,                 // Vector  6  (0xFFEC)
603
                         1'b0,                 // Vector  5  (0xFFEA)
604
                         1'b0,                 // Vector  4  (0xFFE8)
605
                         1'b0,                 // Vector  3  (0xFFE6)
606
                         1'b0,                 // Vector  2  (0xFFE4)
607
                         1'b0,                 // Vector  1  (0xFFE2)
608
                         1'b0};                // Vector  0  (0xFFE0)
609 2 olivier.gi
 
610 134 olivier.gi
 
611 2 olivier.gi
//
612 154 olivier.gi
// I2C serial debug interface
613
//----------------------------------
614
 
615
// I2C Bus
616
//.........................
617 200 olivier.gi
pullup dbg_scl_inst (dbg_scl);
618
pullup dbg_sda_inst (dbg_sda);
619 154 olivier.gi
 
620
// I2C Slave (openMSP430)
621
//.........................
622
io_cell scl_slave_inst (
623 202 olivier.gi
    .pad               (dbg_scl),              // I/O pad
624
    .data_in           (dbg_scl_slave),        // Input
625
    .data_out_en       (1'b0),                 // Output enable
626
    .data_out          (1'b0)                  // Output
627 154 olivier.gi
);
628 200 olivier.gi
 
629 154 olivier.gi
io_cell sda_slave_inst (
630 202 olivier.gi
    .pad               (dbg_sda),              // I/O pad
631
    .data_in           (dbg_sda_slave_in),     // Input
632
    .data_out_en       (!dbg_sda_slave_out),   // Output enable
633
    .data_out          (1'b0)                  // Output
634 154 olivier.gi
);
635
 
636
// I2C Master (Debugger)
637
//.........................
638
io_cell scl_master_inst (
639 202 olivier.gi
    .pad               (dbg_scl),              // I/O pad
640
    .data_in           (),                     // Input
641
    .data_out_en       (!dbg_scl_master),      // Output enable
642
    .data_out          (1'b0)                  // Output
643 154 olivier.gi
);
644 200 olivier.gi
 
645 154 olivier.gi
io_cell sda_master_inst (
646 202 olivier.gi
    .pad               (dbg_sda),              // I/O pad
647
    .data_in           (dbg_sda_master_in),    // Input
648
    .data_out_en       (!dbg_sda_master_out),  // Output enable
649
    .data_out          (1'b0)                  // Output
650 154 olivier.gi
);
651
 
652
 
653
//
654 2 olivier.gi
// Debug utility signals
655
//----------------------------------------
656
msp_debug msp_debug_0 (
657
 
658
// OUTPUTs
659 202 olivier.gi
    .e_state           (e_state),              // Execution state
660
    .i_state           (i_state),              // Instruction fetch state
661
    .inst_cycle        (inst_cycle),           // Cycle number within current instruction
662
    .inst_full         (inst_full),            // Currently executed instruction (full version)
663
    .inst_number       (inst_number),          // Instruction number since last system reset
664
    .inst_pc           (inst_pc),              // Instruction Program counter
665
    .inst_short        (inst_short),           // Currently executed instruction (short version)
666 2 olivier.gi
 
667
// INPUTs
668 202 olivier.gi
    .mclk              (mclk),                 // Main system clock
669
    .puc_rst           (puc_rst)               // Main system reset
670 2 olivier.gi
);
671
 
672
 
673
//
674
// Generate Waveform
675
//----------------------------------------
676
initial
677
  begin
678 65 olivier.gi
   `ifdef NODUMP
679 2 olivier.gi
   `else
680 65 olivier.gi
     `ifdef VPD_FILE
681
        $vcdplusfile("tb_openMSP430.vpd");
682
        $vcdpluson();
683
     `else
684 98 olivier.gi
       `ifdef TRN_FILE
685
          $recordfile ("tb_openMSP430.trn");
686
          $recordvars;
687
       `else
688
          $dumpfile("tb_openMSP430.vcd");
689
          $dumpvars(0, tb_openMSP430);
690
       `endif
691 65 olivier.gi
     `endif
692 2 olivier.gi
   `endif
693
  end
694
 
695
//
696
// End of simulation
697
//----------------------------------------
698
 
699
initial // Timeout
700
  begin
701 67 olivier.gi
   `ifdef NO_TIMEOUT
702
   `else
703 134 olivier.gi
     `ifdef VERY_LONG_TIMEOUT
704
       #500000000;
705 200 olivier.gi
     `else
706 67 olivier.gi
     `ifdef LONG_TIMEOUT
707
       #5000000;
708 200 olivier.gi
     `else
709 67 olivier.gi
       #500000;
710
     `endif
711 134 olivier.gi
     `endif
712 67 olivier.gi
       $display(" ===============================================");
713
       $display("|               SIMULATION FAILED               |");
714
       $display("|              (simulation Timeout)             |");
715
       $display(" ===============================================");
716 202 olivier.gi
       $display("");
717
       tb_extra_report;
718 67 olivier.gi
       $finish;
719 2 olivier.gi
   `endif
720
  end
721
 
722
initial // Normal end of test
723
  begin
724 94 olivier.gi
     @(negedge stimulus_done);
725
     wait(inst_pc=='hffff);
726 200 olivier.gi
 
727 2 olivier.gi
     $display(" ===============================================");
728 202 olivier.gi
     if ((dma_rd_error!=0) || (dma_wr_error!=0))
729 2 olivier.gi
       begin
730 192 olivier.gi
          $display("|               SIMULATION FAILED               |");
731 202 olivier.gi
          $display("|           (some DMA transfer failed)          |");
732
       end
733
     else if (error!=0)
734
       begin
735
          $display("|               SIMULATION FAILED               |");
736 192 olivier.gi
          $display("|     (some verilog stimulus checks failed)     |");
737 2 olivier.gi
       end
738
     else if (~stimulus_done)
739
       begin
740 192 olivier.gi
          $display("|               SIMULATION FAILED               |");
741
          $display("|     (the verilog stimulus didn't complete)    |");
742 2 olivier.gi
       end
743 200 olivier.gi
     else
744 2 olivier.gi
       begin
745 192 olivier.gi
          $display("|               SIMULATION PASSED               |");
746 2 olivier.gi
       end
747
     $display(" ===============================================");
748 202 olivier.gi
     $display("");
749
     tb_extra_report;
750 2 olivier.gi
     $finish;
751
  end
752
 
753
 
754
//
755
// Tasks Definition
756
//------------------------------
757
 
758
   task tb_error;
759
      input [65*8:0] error_string;
760
      begin
761 192 olivier.gi
         $display("ERROR: %s %t", error_string, $time);
762
         error = error+1;
763 2 olivier.gi
      end
764
   endtask
765
 
766 202 olivier.gi
   task tb_extra_report;
767
      begin
768
         $display("DMA REPORT: Total Accesses: %-d Total RD: %-d Total WR: %-d", dma_cnt_rd+dma_cnt_wr,     dma_cnt_rd,   dma_cnt_wr);
769
         $display("            Total Errors:   %-d Error RD: %-d Error WR: %-d", dma_rd_error+dma_wr_error, dma_rd_error, dma_wr_error);
770
         if (!((`PMEM_SIZE>=4092) && (`DMEM_SIZE>=1024)))
771
           begin
772
              $display("");
773
              $display("Note: DMA if verification disabled (PMEM must be 4kB or bigger, DMEM must be 1kB or bigger)");
774
           end
775
         $display("");
776
         $display("SIMULATION SEED: %d", `SEED);
777
         $display("");
778
      end
779
   endtask
780 2 olivier.gi
 
781 202 olivier.gi
   task tb_skip_finish;
782
      input [65*8-1:0] skip_string;
783
      begin
784
         $display(" ===============================================");
785
         $display("|               SIMULATION SKIPPED              |");
786
         $display("%s", skip_string);
787
         $display(" ===============================================");
788
         $display("");
789
         tb_extra_report;
790
         $finish;
791
      end
792
   endtask
793
 
794 2 olivier.gi
endmodule

powered by: WebSVN 2.1.0

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