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

Subversion Repositories openmsp430

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

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

powered by: WebSVN 2.1.0

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