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

Subversion Repositories openmsp430

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

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

powered by: WebSVN 2.1.0

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