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

Subversion Repositories openmsp430

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

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: 200 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2015-01-21 23:01:31 +0100 (Wed, 21 Jan 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
// 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 200 olivier.gi
 
123 2 olivier.gi
// Clock / Reset & Interrupts
124 33 olivier.gi
reg                dco_clk;
125 134 olivier.gi
wire               dco_enable;
126
wire               dco_wkup;
127
reg                dco_local_enable;
128 33 olivier.gi
reg                lfxt_clk;
129 134 olivier.gi
wire               lfxt_enable;
130
wire               lfxt_wkup;
131
reg                lfxt_local_enable;
132 33 olivier.gi
wire               mclk;
133 134 olivier.gi
wire               aclk;
134 33 olivier.gi
wire               aclk_en;
135 134 olivier.gi
wire               smclk;
136 33 olivier.gi
wire               smclk_en;
137
reg                reset_n;
138 111 olivier.gi
wire               puc_rst;
139 33 olivier.gi
reg                nmi;
140 192 olivier.gi
reg  [`IRQ_NR-3:0] irq;
141
wire [`IRQ_NR-3:0] irq_acc;
142
wire [`IRQ_NR-3:0] irq_in;
143 106 olivier.gi
reg                cpu_en;
144 134 olivier.gi
reg         [13:0] wkup;
145
wire        [13:0] wkup_in;
146 200 olivier.gi
 
147 134 olivier.gi
// Scan (ASIC version only)
148
reg                scan_enable;
149
reg                scan_mode;
150
 
151 154 olivier.gi
// Debug interface: UART
152 106 olivier.gi
reg                dbg_en;
153 33 olivier.gi
wire               dbg_freeze;
154
wire               dbg_uart_txd;
155 134 olivier.gi
wire               dbg_uart_rxd;
156
reg                dbg_uart_rxd_sel;
157
reg                dbg_uart_rxd_dly;
158
reg                dbg_uart_rxd_pre;
159
reg                dbg_uart_rxd_meta;
160 33 olivier.gi
reg         [15:0] dbg_uart_buf;
161 134 olivier.gi
reg                dbg_uart_rx_busy;
162
reg                dbg_uart_tx_busy;
163 2 olivier.gi
 
164 154 olivier.gi
// Debug interface: I2C
165
wire               dbg_scl;
166
wire               dbg_sda;
167
wire               dbg_scl_slave;
168
wire               dbg_scl_master;
169
reg                dbg_scl_master_sel;
170
reg                dbg_scl_master_dly;
171
reg                dbg_scl_master_pre;
172
reg                dbg_scl_master_meta;
173
wire               dbg_sda_slave_out;
174
wire               dbg_sda_slave_in;
175
wire               dbg_sda_master_out;
176
reg                dbg_sda_master_out_sel;
177
reg                dbg_sda_master_out_dly;
178
reg                dbg_sda_master_out_pre;
179
reg                dbg_sda_master_out_meta;
180
wire               dbg_sda_master_in;
181
reg         [15:0] dbg_i2c_buf;
182
reg     [8*32-1:0] dbg_i2c_string;
183
 
184 2 olivier.gi
// Core testbench debuging signals
185 33 olivier.gi
wire    [8*32-1:0] i_state;
186
wire    [8*32-1:0] e_state;
187
wire        [31:0] inst_cycle;
188
wire    [8*32-1:0] inst_full;
189
wire        [31:0] inst_number;
190
wire        [15:0] inst_pc;
191
wire    [8*32-1:0] inst_short;
192 200 olivier.gi
 
193 2 olivier.gi
// Testbench variables
194 200 olivier.gi
integer            tb_idx;
195 33 olivier.gi
integer            error;
196
reg                stimulus_done;
197 2 olivier.gi
 
198
 
199
//
200
// Include files
201
//------------------------------
202
 
203
// CPU & Memory registers
204
`include "registers.v"
205
 
206
// Debug interface tasks
207
`include "dbg_uart_tasks.v"
208 154 olivier.gi
`include "dbg_i2c_tasks.v"
209 2 olivier.gi
 
210
// Verilog stimulus
211
`include "stimulus.v"
212
 
213 200 olivier.gi
 
214 2 olivier.gi
//
215 200 olivier.gi
// Initialize Memory
216 2 olivier.gi
//------------------------------
217
initial
218
  begin
219 200 olivier.gi
     // Initialize data memory
220
     for (tb_idx=0; tb_idx < `DMEM_SIZE/2; tb_idx=tb_idx+1)
221
       dmem_0.mem[tb_idx] = 16'h0000;
222
 
223
     // Initialize program memory
224 94 olivier.gi
     #10 $readmemh("./pmem.mem", pmem_0.mem);
225 2 olivier.gi
  end
226
 
227 200 olivier.gi
 
228 2 olivier.gi
//
229
// Generate Clock & Reset
230
//------------------------------
231
initial
232
  begin
233 134 olivier.gi
     dco_clk          = 1'b0;
234
     dco_local_enable = 1'b0;
235
     forever
236
       begin
237 192 olivier.gi
          #25;   // 20 MHz
238
          dco_local_enable = (dco_enable===1) ? dco_enable : (dco_wkup===1);
239
          if (dco_local_enable)
240
            dco_clk = ~dco_clk;
241 134 olivier.gi
       end
242 2 olivier.gi
  end
243 134 olivier.gi
 
244 2 olivier.gi
initial
245
  begin
246 134 olivier.gi
     lfxt_clk          = 1'b0;
247
     lfxt_local_enable = 1'b0;
248
     forever
249
       begin
250 192 olivier.gi
          #763;  // 655 kHz
251
          lfxt_local_enable = (lfxt_enable===1) ? lfxt_enable : (lfxt_wkup===1);
252
          if (lfxt_local_enable)
253
            lfxt_clk = ~lfxt_clk;
254 134 olivier.gi
       end
255 2 olivier.gi
  end
256
 
257
initial
258
  begin
259
     reset_n       = 1'b1;
260 106 olivier.gi
     #93;
261 2 olivier.gi
     reset_n       = 1'b0;
262 106 olivier.gi
     #593;
263 2 olivier.gi
     reset_n       = 1'b1;
264
  end
265
 
266
initial
267
  begin
268 154 olivier.gi
     error                   = 0;
269
     stimulus_done           = 1;
270 192 olivier.gi
     irq                     = {`IRQ_NR-2{1'b0}};
271 154 olivier.gi
     nmi                     = 1'b0;
272
     wkup                    = 14'h0000;
273
     cpu_en                  = 1'b1;
274
     dbg_en                  = 1'b0;
275
     dbg_uart_rxd_sel        = 1'b0;
276
     dbg_uart_rxd_dly        = 1'b1;
277
     dbg_uart_rxd_pre        = 1'b1;
278
     dbg_uart_rxd_meta       = 1'b0;
279
     dbg_uart_buf            = 16'h0000;
280
     dbg_uart_rx_busy        = 1'b0;
281
     dbg_uart_tx_busy        = 1'b0;
282
     dbg_scl_master_sel      = 1'b0;
283
     dbg_scl_master_dly      = 1'b1;
284
     dbg_scl_master_pre      = 1'b1;
285
     dbg_scl_master_meta     = 1'b0;
286
     dbg_sda_master_out_sel  = 1'b0;
287
     dbg_sda_master_out_dly  = 1'b1;
288
     dbg_sda_master_out_pre  = 1'b1;
289
     dbg_sda_master_out_meta = 1'b0;
290
     dbg_i2c_string          = "";
291
     p1_din                  = 8'h00;
292
     p2_din                  = 8'h00;
293
     p3_din                  = 8'h00;
294
     p4_din                  = 8'h00;
295
     p5_din                  = 8'h00;
296
     p6_din                  = 8'h00;
297
     inclk                   = 1'b0;
298
     taclk                   = 1'b0;
299
     ta_cci0a                = 1'b0;
300
     ta_cci0b                = 1'b0;
301
     ta_cci1a                = 1'b0;
302
     ta_cci1b                = 1'b0;
303
     ta_cci2a                = 1'b0;
304
     ta_cci2b                = 1'b0;
305
     scan_enable             = 1'b0;
306
     scan_mode               = 1'b0;
307 2 olivier.gi
  end
308
 
309 200 olivier.gi
 
310 2 olivier.gi
//
311 33 olivier.gi
// Program Memory
312 2 olivier.gi
//----------------------------------
313
 
314 72 olivier.gi
ram #(`PMEM_MSB, `PMEM_SIZE) pmem_0 (
315 2 olivier.gi
 
316
// OUTPUTs
317 33 olivier.gi
    .ram_dout    (pmem_dout),          // Program Memory data output
318 2 olivier.gi
 
319
// INPUTs
320 33 olivier.gi
    .ram_addr    (pmem_addr),          // Program Memory address
321
    .ram_cen     (pmem_cen),           // Program Memory chip enable (low active)
322
    .ram_clk     (mclk),               // Program Memory clock
323
    .ram_din     (pmem_din),           // Program Memory data input
324
    .ram_wen     (pmem_wen)            // Program Memory write enable (low active)
325 2 olivier.gi
);
326
 
327
 
328
//
329 33 olivier.gi
// Data Memory
330 2 olivier.gi
//----------------------------------
331
 
332 72 olivier.gi
ram #(`DMEM_MSB, `DMEM_SIZE) dmem_0 (
333 2 olivier.gi
 
334
// OUTPUTs
335 33 olivier.gi
    .ram_dout    (dmem_dout),          // Data Memory data output
336 2 olivier.gi
 
337
// INPUTs
338 33 olivier.gi
    .ram_addr    (dmem_addr),          // Data Memory address
339
    .ram_cen     (dmem_cen),           // Data Memory chip enable (low active)
340
    .ram_clk     (mclk),               // Data Memory clock
341
    .ram_din     (dmem_din),           // Data Memory data input
342
    .ram_wen     (dmem_wen)            // Data Memory write enable (low active)
343 2 olivier.gi
);
344
 
345
 
346
//
347
// openMSP430 Instance
348
//----------------------------------
349
 
350
openMSP430 dut (
351
 
352
// OUTPUTs
353 154 olivier.gi
    .aclk              (aclk),              // ASIC ONLY: ACLK
354
    .aclk_en           (aclk_en),           // FPGA ONLY: ACLK enable
355
    .dbg_freeze        (dbg_freeze),        // Freeze peripherals
356
    .dbg_i2c_sda_out   (dbg_sda_slave_out), // Debug interface: I2C SDA OUT
357
    .dbg_uart_txd      (dbg_uart_txd),      // Debug interface: UART TXD
358
    .dco_enable        (dco_enable),        // ASIC ONLY: Fast oscillator enable
359
    .dco_wkup          (dco_wkup),          // ASIC ONLY: Fast oscillator wake-up (asynchronous)
360
    .dmem_addr         (dmem_addr),         // Data Memory address
361
    .dmem_cen          (dmem_cen),          // Data Memory chip enable (low active)
362
    .dmem_din          (dmem_din),          // Data Memory data input
363
    .dmem_wen          (dmem_wen),          // Data Memory write enable (low active)
364
    .irq_acc           (irq_acc),           // Interrupt request accepted (one-hot signal)
365
    .lfxt_enable       (lfxt_enable),       // ASIC ONLY: Low frequency oscillator enable
366
    .lfxt_wkup         (lfxt_wkup),         // ASIC ONLY: Low frequency oscillator wake-up (asynchronous)
367
    .mclk              (mclk),              // Main system clock
368
    .per_addr          (per_addr),          // Peripheral address
369
    .per_din           (per_din),           // Peripheral data input
370
    .per_we            (per_we),            // Peripheral write enable (high active)
371
    .per_en            (per_en),            // Peripheral enable (high active)
372
    .pmem_addr         (pmem_addr),         // Program Memory address
373
    .pmem_cen          (pmem_cen),          // Program Memory chip enable (low active)
374
    .pmem_din          (pmem_din),          // Program Memory data input (optional)
375
    .pmem_wen          (pmem_wen),          // Program Memory write enable (low active) (optional)
376
    .puc_rst           (puc_rst),           // Main system reset
377
    .smclk             (smclk),             // ASIC ONLY: SMCLK
378
    .smclk_en          (smclk_en),          // FPGA ONLY: SMCLK enable
379 2 olivier.gi
 
380
// INPUTs
381 154 olivier.gi
    .cpu_en            (cpu_en),            // Enable CPU code execution (asynchronous)
382
    .dbg_en            (dbg_en),            // Debug interface enable (asynchronous)
383
    .dbg_i2c_addr      (I2C_ADDR),          // Debug interface: I2C Address
384
    .dbg_i2c_broadcast (I2C_BROADCAST),     // Debug interface: I2C Broadcast Address (for multicore systems)
385
    .dbg_i2c_scl       (dbg_scl_slave),     // Debug interface: I2C SCL
386
    .dbg_i2c_sda_in    (dbg_sda_slave_in),  // Debug interface: I2C SDA IN
387
    .dbg_uart_rxd      (dbg_uart_rxd),      // Debug interface: UART RXD (asynchronous)
388
    .dco_clk           (dco_clk),           // Fast oscillator (fast clock)
389
    .dmem_dout         (dmem_dout),         // Data Memory data output
390
    .irq               (irq_in),            // Maskable interrupts
391
    .lfxt_clk          (lfxt_clk),          // Low frequency oscillator (typ 32kHz)
392
    .nmi               (nmi),               // Non-maskable interrupt (asynchronous)
393
    .per_dout          (per_dout),          // Peripheral data output
394
    .pmem_dout         (pmem_dout),         // Program Memory data output
395
    .reset_n           (reset_n),           // Reset Pin (low active, asynchronous)
396
    .scan_enable       (scan_enable),       // ASIC ONLY: Scan enable (active during scan shifting)
397
    .scan_mode         (scan_mode),         // ASIC ONLY: Scan mode
398
    .wkup              (|wkup_in)           // ASIC ONLY: System Wake-up (asynchronous)
399 2 olivier.gi
);
400
 
401
//
402
// Digital I/O
403
//----------------------------------
404
 
405 99 olivier.gi
`ifdef CVER
406
omsp_gpio #(1,
407
            1,
408
            1,
409
            1,
410
            1,
411
            1)         gpio_0 (
412
`else
413 34 olivier.gi
omsp_gpio #(.P1_EN(1),
414
            .P2_EN(1),
415
            .P3_EN(1),
416
            .P4_EN(1),
417
            .P5_EN(1),
418
            .P6_EN(1)) gpio_0 (
419 99 olivier.gi
`endif
420 2 olivier.gi
 
421
// OUTPUTs
422
    .irq_port1    (irq_port1),         // Port 1 interrupt
423
    .irq_port2    (irq_port2),         // Port 2 interrupt
424
    .p1_dout      (p1_dout),           // Port 1 data output
425
    .p1_dout_en   (p1_dout_en),        // Port 1 data output enable
426
    .p1_sel       (p1_sel),            // Port 1 function select
427
    .p2_dout      (p2_dout),           // Port 2 data output
428
    .p2_dout_en   (p2_dout_en),        // Port 2 data output enable
429
    .p2_sel       (p2_sel),            // Port 2 function select
430
    .p3_dout      (p3_dout),           // Port 3 data output
431
    .p3_dout_en   (p3_dout_en),        // Port 3 data output enable
432
    .p3_sel       (p3_sel),            // Port 3 function select
433
    .p4_dout      (p4_dout),           // Port 4 data output
434
    .p4_dout_en   (p4_dout_en),        // Port 4 data output enable
435
    .p4_sel       (p4_sel),            // Port 4 function select
436
    .p5_dout      (p5_dout),           // Port 5 data output
437
    .p5_dout_en   (p5_dout_en),        // Port 5 data output enable
438
    .p5_sel       (p5_sel),            // Port 5 function select
439
    .p6_dout      (p6_dout),           // Port 6 data output
440
    .p6_dout_en   (p6_dout_en),        // Port 6 data output enable
441
    .p6_sel       (p6_sel),            // Port 6 function select
442
    .per_dout     (per_dout_dio),      // Peripheral data output
443 200 olivier.gi
 
444 2 olivier.gi
// INPUTs
445
    .mclk         (mclk),              // Main system clock
446
    .p1_din       (p1_din),            // Port 1 data input
447
    .p2_din       (p2_din),            // Port 2 data input
448
    .p3_din       (p3_din),            // Port 3 data input
449
    .p4_din       (p4_din),            // Port 4 data input
450
    .p5_din       (p5_din),            // Port 5 data input
451
    .p6_din       (p6_din),            // Port 6 data input
452
    .per_addr     (per_addr),          // Peripheral address
453
    .per_din      (per_din),           // Peripheral data input
454
    .per_en       (per_en),            // Peripheral enable (high active)
455 106 olivier.gi
    .per_we       (per_we),            // Peripheral write enable (high active)
456 111 olivier.gi
    .puc_rst      (puc_rst)            // Main system reset
457 2 olivier.gi
);
458
 
459
//
460
// Timers
461
//----------------------------------
462
 
463 34 olivier.gi
omsp_timerA timerA_0 (
464 2 olivier.gi
 
465
// OUTPUTs
466
    .irq_ta0      (irq_ta0),           // Timer A interrupt: TACCR0
467
    .irq_ta1      (irq_ta1),           // Timer A interrupt: TAIV, TACCR1, TACCR2
468
    .per_dout     (per_dout_timerA),   // Peripheral data output
469
    .ta_out0      (ta_out0),           // Timer A output 0
470
    .ta_out0_en   (ta_out0_en),        // Timer A output 0 enable
471
    .ta_out1      (ta_out1),           // Timer A output 1
472
    .ta_out1_en   (ta_out1_en),        // Timer A output 1 enable
473
    .ta_out2      (ta_out2),           // Timer A output 2
474
    .ta_out2_en   (ta_out2_en),        // Timer A output 2 enable
475
 
476
// INPUTs
477
    .aclk_en      (aclk_en),           // ACLK enable (from CPU)
478
    .dbg_freeze   (dbg_freeze),        // Freeze Timer A counter
479
    .inclk        (inclk),             // INCLK external timer clock (SLOW)
480 192 olivier.gi
    .irq_ta0_acc  (irq_acc[`IRQ_NR-7]),// Interrupt request TACCR0 accepted
481 2 olivier.gi
    .mclk         (mclk),              // Main system clock
482
    .per_addr     (per_addr),          // Peripheral address
483
    .per_din      (per_din),           // Peripheral data input
484
    .per_en       (per_en),            // Peripheral enable (high active)
485 106 olivier.gi
    .per_we       (per_we),            // Peripheral write enable (high active)
486 111 olivier.gi
    .puc_rst      (puc_rst),           // Main system reset
487 2 olivier.gi
    .smclk_en     (smclk_en),          // SMCLK enable (from CPU)
488
    .ta_cci0a     (ta_cci0a),          // Timer A compare 0 input A
489
    .ta_cci0b     (ta_cci0b),          // Timer A compare 0 input B
490
    .ta_cci1a     (ta_cci1a),          // Timer A compare 1 input A
491
    .ta_cci1b     (ta_cci1b),          // Timer A compare 1 input B
492
    .ta_cci2a     (ta_cci2a),          // Timer A compare 2 input A
493
    .ta_cci2b     (ta_cci2b),          // Timer A compare 2 input B
494
    .taclk        (taclk)              // TACLK external timer clock (SLOW)
495
);
496 134 olivier.gi
 
497
 
498
//
499 2 olivier.gi
// Peripheral templates
500
//----------------------------------
501
 
502
template_periph_8b template_periph_8b_0 (
503
 
504
// OUTPUTs
505
    .per_dout     (per_dout_temp_8b),  // Peripheral data output
506
 
507
// INPUTs
508
    .mclk         (mclk),              // Main system clock
509
    .per_addr     (per_addr),          // Peripheral address
510
    .per_din      (per_din),           // Peripheral data input
511
    .per_en       (per_en),            // Peripheral enable (high active)
512 106 olivier.gi
    .per_we       (per_we),            // Peripheral write enable (high active)
513 111 olivier.gi
    .puc_rst      (puc_rst)            // Main system reset
514 2 olivier.gi
);
515
 
516 111 olivier.gi
`ifdef CVER
517
template_periph_16b #(15'h0190)             template_periph_16b_0 (
518
`else
519 151 olivier.gi
template_periph_16b #(.BASE_ADDR((15'd`PER_SIZE-15'h0070) & 15'h7ff8)) template_periph_16b_0 (
520 111 olivier.gi
`endif
521 2 olivier.gi
// OUTPUTs
522
    .per_dout     (per_dout_temp_16b), // Peripheral data output
523
 
524
// INPUTs
525
    .mclk         (mclk),              // Main system clock
526
    .per_addr     (per_addr),          // Peripheral address
527
    .per_din      (per_din),           // Peripheral data input
528
    .per_en       (per_en),            // Peripheral enable (high active)
529 106 olivier.gi
    .per_we       (per_we),            // Peripheral write enable (high active)
530 111 olivier.gi
    .puc_rst      (puc_rst)            // Main system reset
531 2 olivier.gi
);
532
 
533
 
534
//
535
// Combine peripheral data bus
536
//----------------------------------
537
 
538
assign per_dout = per_dout_dio       |
539
                  per_dout_timerA    |
540
                  per_dout_temp_8b   |
541
                  per_dout_temp_16b;
542
 
543
 
544
//
545 134 olivier.gi
// Map peripheral interrupts & wakeups
546 2 olivier.gi
//----------------------------------------
547
 
548 192 olivier.gi
assign irq_in  = irq  | {1'b0,                 // Vector 13  (0xFFFA)
549
                         1'b0,                 // Vector 12  (0xFFF8)
550
                         1'b0,                 // Vector 11  (0xFFF6)
551
                         1'b0,                 // Vector 10  (0xFFF4) - Watchdog -
552
                         irq_ta0,              // Vector  9  (0xFFF2)
553
                         irq_ta1,              // Vector  8  (0xFFF0)
554 200 olivier.gi
                         1'b0,                 // Vector  7  (0xFFEE)
555
                         1'b0,                 // Vector  6  (0xFFEC)
556 192 olivier.gi
                         1'b0,                 // Vector  5  (0xFFEA)
557
                         1'b0,                 // Vector  4  (0xFFE8)
558
                         irq_port2,            // Vector  3  (0xFFE6)
559
                         irq_port1,            // Vector  2  (0xFFE4)
560
                         1'b0,                 // Vector  1  (0xFFE2)
561
                         {`IRQ_NR-15{1'b0}}};  // Vector  0  (0xFFE0)
562 2 olivier.gi
 
563 192 olivier.gi
assign wkup_in = wkup | {1'b0,                 // Vector 13  (0xFFFA)
564
                         1'b0,                 // Vector 12  (0xFFF8)
565
                         1'b0,                 // Vector 11  (0xFFF6)
566
                         1'b0,                 // Vector 10  (0xFFF4) - Watchdog -
567
                         1'b0,                 // Vector  9  (0xFFF2)
568
                         1'b0,                 // Vector  8  (0xFFF0)
569
                         1'b0,                 // Vector  7  (0xFFEE)
570
                         1'b0,                 // Vector  6  (0xFFEC)
571
                         1'b0,                 // Vector  5  (0xFFEA)
572
                         1'b0,                 // Vector  4  (0xFFE8)
573
                         1'b0,                 // Vector  3  (0xFFE6)
574
                         1'b0,                 // Vector  2  (0xFFE4)
575
                         1'b0,                 // Vector  1  (0xFFE2)
576
                         1'b0};                // Vector  0  (0xFFE0)
577 2 olivier.gi
 
578 134 olivier.gi
 
579 2 olivier.gi
//
580 154 olivier.gi
// I2C serial debug interface
581
//----------------------------------
582
 
583
// I2C Bus
584
//.........................
585 200 olivier.gi
pullup dbg_scl_inst (dbg_scl);
586
pullup dbg_sda_inst (dbg_sda);
587 154 olivier.gi
 
588
// I2C Slave (openMSP430)
589
//.........................
590
io_cell scl_slave_inst (
591
  .pad         (dbg_scl),             // I/O pad
592
  .data_in     (dbg_scl_slave),       // Input
593
  .data_out_en (1'b0),                // Output enable
594
  .data_out    (1'b0)                 // Output
595
);
596 200 olivier.gi
 
597 154 olivier.gi
io_cell sda_slave_inst (
598
  .pad         (dbg_sda),             // I/O pad
599
  .data_in     (dbg_sda_slave_in),    // Input
600
  .data_out_en (!dbg_sda_slave_out),  // Output enable
601
  .data_out    (1'b0)                 // Output
602
);
603
 
604
// I2C Master (Debugger)
605
//.........................
606
io_cell scl_master_inst (
607
  .pad         (dbg_scl),             // I/O pad
608
  .data_in     (),                    // Input
609
  .data_out_en (!dbg_scl_master),     // Output enable
610
  .data_out    (1'b0)                 // Output
611
);
612 200 olivier.gi
 
613 154 olivier.gi
io_cell sda_master_inst (
614
  .pad         (dbg_sda),             // I/O pad
615
  .data_in     (dbg_sda_master_in),   // Input
616
  .data_out_en (!dbg_sda_master_out), // Output enable
617
  .data_out    (1'b0)                 // Output
618
);
619
 
620
 
621
//
622 2 olivier.gi
// Debug utility signals
623
//----------------------------------------
624
msp_debug msp_debug_0 (
625
 
626
// OUTPUTs
627
    .e_state      (e_state),           // Execution state
628
    .i_state      (i_state),           // Instruction fetch state
629
    .inst_cycle   (inst_cycle),        // Cycle number within current instruction
630
    .inst_full    (inst_full),         // Currently executed instruction (full version)
631
    .inst_number  (inst_number),       // Instruction number since last system reset
632
    .inst_pc      (inst_pc),           // Instruction Program counter
633
    .inst_short   (inst_short),        // Currently executed instruction (short version)
634
 
635
// INPUTs
636
    .mclk         (mclk),              // Main system clock
637 111 olivier.gi
    .puc_rst      (puc_rst)            // Main system reset
638 2 olivier.gi
);
639
 
640
 
641
//
642
// Generate Waveform
643
//----------------------------------------
644
initial
645
  begin
646 65 olivier.gi
   `ifdef NODUMP
647 2 olivier.gi
   `else
648 65 olivier.gi
     `ifdef VPD_FILE
649
        $vcdplusfile("tb_openMSP430.vpd");
650
        $vcdpluson();
651
     `else
652 98 olivier.gi
       `ifdef TRN_FILE
653
          $recordfile ("tb_openMSP430.trn");
654
          $recordvars;
655
       `else
656
          $dumpfile("tb_openMSP430.vcd");
657
          $dumpvars(0, tb_openMSP430);
658
       `endif
659 65 olivier.gi
     `endif
660 2 olivier.gi
   `endif
661
  end
662
 
663
//
664
// End of simulation
665
//----------------------------------------
666
 
667
initial // Timeout
668
  begin
669 67 olivier.gi
   `ifdef NO_TIMEOUT
670
   `else
671 134 olivier.gi
     `ifdef VERY_LONG_TIMEOUT
672
       #500000000;
673 200 olivier.gi
     `else
674 67 olivier.gi
     `ifdef LONG_TIMEOUT
675
       #5000000;
676 200 olivier.gi
     `else
677 67 olivier.gi
       #500000;
678
     `endif
679 134 olivier.gi
     `endif
680 67 olivier.gi
       $display(" ===============================================");
681
       $display("|               SIMULATION FAILED               |");
682
       $display("|              (simulation Timeout)             |");
683
       $display(" ===============================================");
684
       $finish;
685 2 olivier.gi
   `endif
686
  end
687
 
688
initial // Normal end of test
689
  begin
690 94 olivier.gi
     @(negedge stimulus_done);
691
     wait(inst_pc=='hffff);
692 200 olivier.gi
 
693 2 olivier.gi
     $display(" ===============================================");
694
     if (error!=0)
695
       begin
696 192 olivier.gi
          $display("|               SIMULATION FAILED               |");
697
          $display("|     (some verilog stimulus checks failed)     |");
698 2 olivier.gi
       end
699
     else if (~stimulus_done)
700
       begin
701 192 olivier.gi
          $display("|               SIMULATION FAILED               |");
702
          $display("|     (the verilog stimulus didn't complete)    |");
703 2 olivier.gi
       end
704 200 olivier.gi
     else
705 2 olivier.gi
       begin
706 192 olivier.gi
          $display("|               SIMULATION PASSED               |");
707 2 olivier.gi
       end
708
     $display(" ===============================================");
709
     $finish;
710
  end
711
 
712
 
713
//
714
// Tasks Definition
715
//------------------------------
716
 
717
   task tb_error;
718
      input [65*8:0] error_string;
719
      begin
720 192 olivier.gi
         $display("ERROR: %s %t", error_string, $time);
721
         error = error+1;
722 2 olivier.gi
      end
723
   endtask
724
 
725
 
726
endmodule

powered by: WebSVN 2.1.0

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