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

Subversion Repositories openmsp430

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

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

powered by: WebSVN 2.1.0

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