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

Subversion Repositories openmsp430

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

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
// 
25
// *File Name: tb_openMSP430.v
26
// 
27
// *Module Description:
28
//                      openMSP430 testbench
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 17 olivier.gi
// $Rev: 103 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
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 33 olivier.gi
wire         [7:0] per_addr;
66
wire        [15:0] per_din;
67
wire        [15:0] per_dout;
68
wire         [1:0] per_wen;
69
wire               per_en;
70 2 olivier.gi
 
71
// Digital I/O
72 33 olivier.gi
wire               irq_port1;
73
wire               irq_port2;
74
wire        [15:0] per_dout_dio;
75
wire         [7:0] p1_dout;
76
wire         [7:0] p1_dout_en;
77
wire         [7:0] p1_sel;
78
wire         [7:0] p2_dout;
79
wire         [7:0] p2_dout_en;
80
wire         [7:0] p2_sel;
81
wire         [7:0] p3_dout;
82
wire         [7:0] p3_dout_en;
83
wire         [7:0] p3_sel;
84
wire         [7:0] p4_dout;
85
wire         [7:0] p4_dout_en;
86
wire         [7:0] p4_sel;
87
wire         [7:0] p5_dout;
88
wire         [7:0] p5_dout_en;
89
wire         [7:0] p5_sel;
90
wire         [7:0] p6_dout;
91
wire         [7:0] p6_dout_en;
92
wire         [7:0] p6_sel;
93
reg          [7:0] p1_din;
94
reg          [7:0] p2_din;
95
reg          [7:0] p3_din;
96
reg          [7:0] p4_din;
97
reg          [7:0] p5_din;
98
reg          [7:0] p6_din;
99 2 olivier.gi
 
100
// Peripheral templates
101 33 olivier.gi
wire        [15:0] per_dout_temp_8b;
102
wire        [15:0] per_dout_temp_16b;
103 2 olivier.gi
 
104
// Timer A
105 33 olivier.gi
wire               irq_ta0;
106
wire               irq_ta1;
107
wire        [15:0] per_dout_timerA;
108
reg                inclk;
109
reg                taclk;
110
reg                ta_cci0a;
111
reg                ta_cci0b;
112
reg                ta_cci1a;
113
reg                ta_cci1b;
114
reg                ta_cci2a;
115
reg                ta_cci2b;
116
wire               ta_out0;
117
wire               ta_out0_en;
118
wire               ta_out1;
119
wire               ta_out1_en;
120
wire               ta_out2;
121
wire               ta_out2_en;
122 2 olivier.gi
 
123
// Clock / Reset & Interrupts
124 33 olivier.gi
reg                dco_clk;
125
reg                lfxt_clk;
126
wire               mclk;
127
wire               aclk_en;
128
wire               smclk_en;
129
reg                reset_n;
130
wire               puc;
131
reg                nmi;
132
reg         [13:0] irq;
133
wire        [13:0] irq_acc;
134
wire        [13:0] irq_in;
135 2 olivier.gi
 
136
// Debug interface
137 33 olivier.gi
wire               dbg_freeze;
138
wire               dbg_uart_txd;
139
reg                dbg_uart_rxd;
140
reg         [15:0] dbg_uart_buf;
141 2 olivier.gi
 
142
// Core testbench debuging signals
143 33 olivier.gi
wire    [8*32-1:0] i_state;
144
wire    [8*32-1:0] e_state;
145
wire        [31:0] inst_cycle;
146
wire    [8*32-1:0] inst_full;
147
wire        [31:0] inst_number;
148
wire        [15:0] inst_pc;
149
wire    [8*32-1:0] inst_short;
150 2 olivier.gi
 
151
// Testbench variables
152 33 olivier.gi
integer            error;
153
reg                stimulus_done;
154 2 olivier.gi
 
155
 
156
//
157
// Include files
158
//------------------------------
159
 
160
// CPU & Memory registers
161
`include "registers.v"
162
 
163
// Debug interface tasks
164
`include "dbg_uart_tasks.v"
165
 
166
// Verilog stimulus
167
`include "stimulus.v"
168
 
169
 
170
//
171
// Initialize ROM
172
//------------------------------
173
initial
174
  begin
175 94 olivier.gi
     #10 $readmemh("./pmem.mem", pmem_0.mem);
176 2 olivier.gi
  end
177
 
178
//
179
// Generate Clock & Reset
180
//------------------------------
181
initial
182
  begin
183
     dco_clk = 1'b0;
184
     forever #25 dco_clk <= ~dco_clk;   // 20 MHz
185
  end
186
initial
187
  begin
188
     lfxt_clk = 1'b0;
189
     forever #763 lfxt_clk <= ~lfxt_clk; // 655 kHz
190
  end
191
 
192
initial
193
  begin
194
     reset_n       = 1'b1;
195
     #100;
196
     reset_n       = 1'b0;
197
     #600;
198
     reset_n       = 1'b1;
199
  end
200
 
201
initial
202
  begin
203
     error         = 0;
204
     stimulus_done = 1;
205
     irq           = 14'b0000;
206
     nmi           = 1'b0;
207 54 olivier.gi
     dbg_uart_rxd  = 1'b1;
208 2 olivier.gi
     dbg_uart_buf  = 16'h0000;
209
     p1_din        = 8'h00;
210
     p2_din        = 8'h00;
211
     p3_din        = 8'h00;
212
     p4_din        = 8'h00;
213
     p5_din        = 8'h00;
214
     p6_din        = 8'h00;
215
     inclk         = 1'b0;
216
     taclk         = 1'b0;
217
     ta_cci0a      = 1'b0;
218
     ta_cci0b      = 1'b0;
219
     ta_cci1a      = 1'b0;
220
     ta_cci1b      = 1'b0;
221
     ta_cci2a      = 1'b0;
222
     ta_cci2b      = 1'b0;
223
  end
224
 
225
 
226
//
227 33 olivier.gi
// Program Memory
228 2 olivier.gi
//----------------------------------
229
 
230 72 olivier.gi
ram #(`PMEM_MSB, `PMEM_SIZE) pmem_0 (
231 2 olivier.gi
 
232
// OUTPUTs
233 33 olivier.gi
    .ram_dout    (pmem_dout),          // Program Memory data output
234 2 olivier.gi
 
235
// INPUTs
236 33 olivier.gi
    .ram_addr    (pmem_addr),          // Program Memory address
237
    .ram_cen     (pmem_cen),           // Program Memory chip enable (low active)
238
    .ram_clk     (mclk),               // Program Memory clock
239
    .ram_din     (pmem_din),           // Program Memory data input
240
    .ram_wen     (pmem_wen)            // Program Memory write enable (low active)
241 2 olivier.gi
);
242
 
243
 
244
//
245 33 olivier.gi
// Data Memory
246 2 olivier.gi
//----------------------------------
247
 
248 72 olivier.gi
ram #(`DMEM_MSB, `DMEM_SIZE) dmem_0 (
249 2 olivier.gi
 
250
// OUTPUTs
251 33 olivier.gi
    .ram_dout    (dmem_dout),          // Data Memory data output
252 2 olivier.gi
 
253
// INPUTs
254 33 olivier.gi
    .ram_addr    (dmem_addr),          // Data Memory address
255
    .ram_cen     (dmem_cen),           // Data Memory chip enable (low active)
256
    .ram_clk     (mclk),               // Data Memory clock
257
    .ram_din     (dmem_din),           // Data Memory data input
258
    .ram_wen     (dmem_wen)            // Data Memory write enable (low active)
259 2 olivier.gi
);
260
 
261
 
262
//
263
// openMSP430 Instance
264
//----------------------------------
265
 
266
openMSP430 dut (
267
 
268
// OUTPUTs
269
    .aclk_en      (aclk_en),           // ACLK enable
270
    .dbg_freeze   (dbg_freeze),        // Freeze peripherals
271
    .dbg_uart_txd (dbg_uart_txd),      // Debug interface: UART TXD
272 33 olivier.gi
    .dmem_addr    (dmem_addr),         // Data Memory address
273
    .dmem_cen     (dmem_cen),          // Data Memory chip enable (low active)
274
    .dmem_din     (dmem_din),          // Data Memory data input
275
    .dmem_wen     (dmem_wen),          // Data Memory write enable (low active)
276 2 olivier.gi
    .irq_acc      (irq_acc),           // Interrupt request accepted (one-hot signal)
277
    .mclk         (mclk),              // Main system clock
278
    .per_addr     (per_addr),          // Peripheral address
279
    .per_din      (per_din),           // Peripheral data input
280
    .per_wen      (per_wen),           // Peripheral write enable (high active)
281
    .per_en       (per_en),            // Peripheral enable (high active)
282 33 olivier.gi
    .pmem_addr    (pmem_addr),         // Program Memory address
283
    .pmem_cen     (pmem_cen),          // Program Memory chip enable (low active)
284
    .pmem_din     (pmem_din),          // Program Memory data input (optional)
285
    .pmem_wen     (pmem_wen),          // Program Memory write enable (low active) (optional)
286 2 olivier.gi
    .puc          (puc),               // Main system reset
287
    .smclk_en     (smclk_en),          // SMCLK enable
288
 
289
// INPUTs
290
    .dbg_uart_rxd (dbg_uart_rxd),      // Debug interface: UART RXD
291
    .dco_clk      (dco_clk),           // Fast oscillator (fast clock)
292 33 olivier.gi
    .dmem_dout    (dmem_dout),         // Data Memory data output
293 2 olivier.gi
    .irq          (irq_in),            // Maskable interrupts
294
    .lfxt_clk     (lfxt_clk),          // Low frequency oscillator (typ 32kHz)
295
    .nmi          (nmi),               // Non-maskable interrupt (asynchronous)
296
    .per_dout     (per_dout),          // Peripheral data output
297 33 olivier.gi
    .pmem_dout    (pmem_dout),         // Program Memory data output
298
    .reset_n      (reset_n)            // Reset Pin (low active)
299 2 olivier.gi
);
300
 
301
//
302
// Digital I/O
303
//----------------------------------
304
 
305 99 olivier.gi
`ifdef CVER
306
omsp_gpio #(1,
307
            1,
308
            1,
309
            1,
310
            1,
311
            1)         gpio_0 (
312
`else
313 34 olivier.gi
omsp_gpio #(.P1_EN(1),
314
            .P2_EN(1),
315
            .P3_EN(1),
316
            .P4_EN(1),
317
            .P5_EN(1),
318
            .P6_EN(1)) gpio_0 (
319 99 olivier.gi
`endif
320 2 olivier.gi
 
321
// OUTPUTs
322
    .irq_port1    (irq_port1),         // Port 1 interrupt
323
    .irq_port2    (irq_port2),         // Port 2 interrupt
324
    .p1_dout      (p1_dout),           // Port 1 data output
325
    .p1_dout_en   (p1_dout_en),        // Port 1 data output enable
326
    .p1_sel       (p1_sel),            // Port 1 function select
327
    .p2_dout      (p2_dout),           // Port 2 data output
328
    .p2_dout_en   (p2_dout_en),        // Port 2 data output enable
329
    .p2_sel       (p2_sel),            // Port 2 function select
330
    .p3_dout      (p3_dout),           // Port 3 data output
331
    .p3_dout_en   (p3_dout_en),        // Port 3 data output enable
332
    .p3_sel       (p3_sel),            // Port 3 function select
333
    .p4_dout      (p4_dout),           // Port 4 data output
334
    .p4_dout_en   (p4_dout_en),        // Port 4 data output enable
335
    .p4_sel       (p4_sel),            // Port 4 function select
336
    .p5_dout      (p5_dout),           // Port 5 data output
337
    .p5_dout_en   (p5_dout_en),        // Port 5 data output enable
338
    .p5_sel       (p5_sel),            // Port 5 function select
339
    .p6_dout      (p6_dout),           // Port 6 data output
340
    .p6_dout_en   (p6_dout_en),        // Port 6 data output enable
341
    .p6_sel       (p6_sel),            // Port 6 function select
342
    .per_dout     (per_dout_dio),      // Peripheral data output
343
 
344
// INPUTs
345
    .mclk         (mclk),              // Main system clock
346
    .p1_din       (p1_din),            // Port 1 data input
347
    .p2_din       (p2_din),            // Port 2 data input
348
    .p3_din       (p3_din),            // Port 3 data input
349
    .p4_din       (p4_din),            // Port 4 data input
350
    .p5_din       (p5_din),            // Port 5 data input
351
    .p6_din       (p6_din),            // Port 6 data input
352
    .per_addr     (per_addr),          // Peripheral address
353
    .per_din      (per_din),           // Peripheral data input
354
    .per_en       (per_en),            // Peripheral enable (high active)
355
    .per_wen      (per_wen),           // Peripheral write enable (high active)
356
    .puc          (puc)                // Main system reset
357
);
358
 
359
//
360
// Timers
361
//----------------------------------
362
 
363 34 olivier.gi
omsp_timerA timerA_0 (
364 2 olivier.gi
 
365
// OUTPUTs
366
    .irq_ta0      (irq_ta0),           // Timer A interrupt: TACCR0
367
    .irq_ta1      (irq_ta1),           // Timer A interrupt: TAIV, TACCR1, TACCR2
368
    .per_dout     (per_dout_timerA),   // Peripheral data output
369
    .ta_out0      (ta_out0),           // Timer A output 0
370
    .ta_out0_en   (ta_out0_en),        // Timer A output 0 enable
371
    .ta_out1      (ta_out1),           // Timer A output 1
372
    .ta_out1_en   (ta_out1_en),        // Timer A output 1 enable
373
    .ta_out2      (ta_out2),           // Timer A output 2
374
    .ta_out2_en   (ta_out2_en),        // Timer A output 2 enable
375
 
376
// INPUTs
377
    .aclk_en      (aclk_en),           // ACLK enable (from CPU)
378
    .dbg_freeze   (dbg_freeze),        // Freeze Timer A counter
379
    .inclk        (inclk),             // INCLK external timer clock (SLOW)
380
    .irq_ta0_acc  (irq_acc[9]),        // Interrupt request TACCR0 accepted
381
    .mclk         (mclk),              // Main system clock
382
    .per_addr     (per_addr),          // Peripheral address
383
    .per_din      (per_din),           // Peripheral data input
384
    .per_en       (per_en),            // Peripheral enable (high active)
385
    .per_wen      (per_wen),           // Peripheral write enable (high active)
386
    .puc          (puc),               // Main system reset
387
    .smclk_en     (smclk_en),          // SMCLK enable (from CPU)
388
    .ta_cci0a     (ta_cci0a),          // Timer A compare 0 input A
389
    .ta_cci0b     (ta_cci0b),          // Timer A compare 0 input B
390
    .ta_cci1a     (ta_cci1a),          // Timer A compare 1 input A
391
    .ta_cci1b     (ta_cci1b),          // Timer A compare 1 input B
392
    .ta_cci2a     (ta_cci2a),          // Timer A compare 2 input A
393
    .ta_cci2b     (ta_cci2b),          // Timer A compare 2 input B
394
    .taclk        (taclk)              // TACLK external timer clock (SLOW)
395
);
396
 
397
//
398
// Peripheral templates
399
//----------------------------------
400
 
401
template_periph_8b template_periph_8b_0 (
402
 
403
// OUTPUTs
404
    .per_dout     (per_dout_temp_8b),  // Peripheral data output
405
 
406
// INPUTs
407
    .mclk         (mclk),              // Main system clock
408
    .per_addr     (per_addr),          // Peripheral address
409
    .per_din      (per_din),           // Peripheral data input
410
    .per_en       (per_en),            // Peripheral enable (high active)
411
    .per_wen      (per_wen),           // Peripheral write enable (high active)
412
    .puc          (puc)                // Main system reset
413
);
414
 
415
template_periph_16b template_periph_16b_0 (
416
 
417
// OUTPUTs
418
    .per_dout     (per_dout_temp_16b), // Peripheral data output
419
 
420
// INPUTs
421
    .mclk         (mclk),              // Main system clock
422
    .per_addr     (per_addr),          // Peripheral address
423
    .per_din      (per_din),           // Peripheral data input
424
    .per_en       (per_en),            // Peripheral enable (high active)
425
    .per_wen      (per_wen),           // Peripheral write enable (high active)
426
    .puc          (puc)                // Main system reset
427
);
428
 
429
 
430
//
431
// Combine peripheral data bus
432
//----------------------------------
433
 
434
assign per_dout = per_dout_dio       |
435
                  per_dout_timerA    |
436
                  per_dout_temp_8b   |
437
                  per_dout_temp_16b;
438
 
439
 
440
//
441
// Map peripheral interrupts
442
//----------------------------------------
443
 
444
assign irq_in = irq | {1'b0,           // Vector 13  (0xFFFA)
445
                       1'b0,           // Vector 12  (0xFFF8)
446
                       1'b0,           // Vector 11  (0xFFF6)
447
                       1'b0,           // Vector 10  (0xFFF4) - Watchdog -
448
                       irq_ta0,        // Vector  9  (0xFFF2)
449
                       irq_ta1,        // Vector  8  (0xFFF0)
450
                       1'b0,           // Vector  7  (0xFFEE)
451
                       1'b0,           // Vector  6  (0xFFEC)
452
                       1'b0,           // Vector  5  (0xFFEA)
453
                       1'b0,           // Vector  4  (0xFFE8)
454
                       irq_port2,      // Vector  3  (0xFFE6)
455
                       irq_port1,      // Vector  2  (0xFFE4)
456
                       1'b0,           // Vector  1  (0xFFE2)
457
                       1'b0};          // Vector  0  (0xFFE0)
458
 
459
 
460
//
461
// Debug utility signals
462
//----------------------------------------
463
msp_debug msp_debug_0 (
464
 
465
// OUTPUTs
466
    .e_state      (e_state),           // Execution state
467
    .i_state      (i_state),           // Instruction fetch state
468
    .inst_cycle   (inst_cycle),        // Cycle number within current instruction
469
    .inst_full    (inst_full),         // Currently executed instruction (full version)
470
    .inst_number  (inst_number),       // Instruction number since last system reset
471
    .inst_pc      (inst_pc),           // Instruction Program counter
472
    .inst_short   (inst_short),        // Currently executed instruction (short version)
473
 
474
// INPUTs
475
    .mclk         (mclk),              // Main system clock
476
    .puc          (puc)                // Main system reset
477
);
478
 
479
 
480
//
481
// Generate Waveform
482
//----------------------------------------
483
initial
484
  begin
485 65 olivier.gi
   `ifdef NODUMP
486 2 olivier.gi
   `else
487 65 olivier.gi
     `ifdef VPD_FILE
488
        $vcdplusfile("tb_openMSP430.vpd");
489
        $vcdpluson();
490
     `else
491 98 olivier.gi
       `ifdef TRN_FILE
492
          $recordfile ("tb_openMSP430.trn");
493
          $recordvars;
494
       `else
495
          $dumpfile("tb_openMSP430.vcd");
496
          $dumpvars(0, tb_openMSP430);
497
       `endif
498 65 olivier.gi
     `endif
499 2 olivier.gi
   `endif
500
  end
501
 
502
//
503
// End of simulation
504
//----------------------------------------
505
 
506
initial // Timeout
507
  begin
508 67 olivier.gi
   `ifdef NO_TIMEOUT
509
   `else
510
     `ifdef LONG_TIMEOUT
511
       #5000000;
512
     `else
513
       #500000;
514
     `endif
515
       $display(" ===============================================");
516
       $display("|               SIMULATION FAILED               |");
517
       $display("|              (simulation Timeout)             |");
518
       $display(" ===============================================");
519
       $finish;
520 2 olivier.gi
   `endif
521
  end
522
 
523
initial // Normal end of test
524
  begin
525 94 olivier.gi
     @(negedge stimulus_done);
526
     wait(inst_pc=='hffff);
527
 
528 2 olivier.gi
     $display(" ===============================================");
529
     if (error!=0)
530
       begin
531
          $display("|               SIMULATION FAILED               |");
532
          $display("|     (some verilog stimulus checks failed)     |");
533
       end
534
     else if (~stimulus_done)
535
       begin
536
          $display("|               SIMULATION FAILED               |");
537
          $display("|     (the verilog stimulus didn't complete)    |");
538
       end
539
     else
540
       begin
541
          $display("|               SIMULATION PASSED               |");
542
       end
543
     $display(" ===============================================");
544
     $finish;
545
  end
546
 
547
 
548
//
549
// Tasks Definition
550
//------------------------------
551
 
552
   task tb_error;
553
      input [65*8:0] error_string;
554
      begin
555
         $display("ERROR: %s %t", error_string, $time);
556
         error = error+1;
557
      end
558
   endtask
559
 
560
 
561
endmodule

powered by: WebSVN 2.1.0

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