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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [actel_m1a3pl_dev_kit/] [bench/] [verilog/] [tb_openMSP430_fpga.v] - Blame information for rev 111

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 80 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_fpga.v
26
// 
27
// *Module Description:
28
//                      openMSP430 FPGA testbench
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34
// $Rev: 37 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2009-12-29 21:58:14 +0100 (Tue, 29 Dec 2009) $
37
//----------------------------------------------------------------------------
38
`include "timescale.v"
39 104 olivier.gi
`ifdef OMSP_NO_INCLUDE
40
`else
41 80 olivier.gi
`include "openMSP430_defines.v"
42 104 olivier.gi
`endif
43 80 olivier.gi
 
44
module  tb_openMSP430_fpga;
45
 
46
//
47
// Wire & Register definition
48
//------------------------------
49
 
50
// Clock & Reset
51
reg               oscclk;
52
reg               porst_n;
53
reg               pbrst_n;
54
 
55
// Slide Switches
56
reg         [9:0] switch;
57
 
58
// LEDs
59
wire        [9:0] led;
60
 
61
// UART
62 107 olivier.gi
reg               dbg_uart_rxd;
63
wire              dbg_uart_txd;
64
reg        [15:0] dbg_uart_buf;
65 80 olivier.gi
 
66
// Core debug signals
67
wire   [8*32-1:0] i_state;
68
wire   [8*32-1:0] e_state;
69
wire       [31:0] inst_cycle;
70
wire   [8*32-1:0] inst_full;
71
wire       [31:0] inst_number;
72
wire       [15:0] inst_pc;
73
wire   [8*32-1:0] inst_short;
74
 
75
// Testbench variables
76
integer           i;
77
integer           error;
78
reg               stimulus_done;
79
wire       [11:0] vout_x;
80
wire       [11:0] vout_y;
81
 
82
//
83
// Include files
84
//------------------------------
85
 
86
// CPU & Memory registers
87
`include "registers.v"
88
 
89 107 olivier.gi
// Debug interface tasks
90
`include "dbg_uart_tasks.v"
91
 
92 80 olivier.gi
// Verilog stimulus
93
`include "stimulus.v"
94
 
95
//
96
// Initialize Program Memory
97
//------------------------------
98
 
99
initial
100
   begin
101
      // Read memory file
102 94 olivier.gi
      #10 $readmemh("./pmem.mem", pmem);
103 80 olivier.gi
 
104
      // Update Actel memory banks
105
      for (i=0; i<512; i=i+1)
106
        begin
107
           dut.dmem_hi.dmem_128B_R0C0.MEM_512_9[i] = {1'b0, 8'h00};
108
           dut.dmem_lo.dmem_128B_R0C0.MEM_512_9[i] = {1'b0, 8'h00};
109
 
110
           dut.pmem_hi.pmem_2kB_R0C0.MEM_512_9[i] = {1'b0, pmem[i*4+3][9:8],   pmem[i*4+2][9:8],   pmem[i*4+1][9:8],   pmem[i*4+0][9:8]};
111
           dut.pmem_hi.pmem_2kB_R0C1.MEM_512_9[i] = {1'b0, pmem[i*4+3][11:10], pmem[i*4+2][11:10], pmem[i*4+1][11:10], pmem[i*4+0][11:10]};
112
           dut.pmem_hi.pmem_2kB_R0C2.MEM_512_9[i] = {1'b0, pmem[i*4+3][13:12], pmem[i*4+2][13:12], pmem[i*4+1][13:12], pmem[i*4+0][13:12]};
113
           dut.pmem_hi.pmem_2kB_R0C3.MEM_512_9[i] = {1'b0, pmem[i*4+3][15:14], pmem[i*4+2][15:14], pmem[i*4+1][15:14], pmem[i*4+0][15:14]};
114
 
115
           dut.pmem_lo.pmem_2kB_R0C0.MEM_512_9[i] = {1'b0, pmem[i*4+3][1:0],   pmem[i*4+2][1:0],   pmem[i*4+1][1:0],   pmem[i*4+0][1:0]};
116
           dut.pmem_lo.pmem_2kB_R0C1.MEM_512_9[i] = {1'b0, pmem[i*4+3][3:2],   pmem[i*4+2][3:2],   pmem[i*4+1][3:2],   pmem[i*4+0][3:2]};
117
           dut.pmem_lo.pmem_2kB_R0C2.MEM_512_9[i] = {1'b0, pmem[i*4+3][5:4],   pmem[i*4+2][5:4],   pmem[i*4+1][5:4],   pmem[i*4+0][5:4]};
118
           dut.pmem_lo.pmem_2kB_R0C3.MEM_512_9[i] = {1'b0, pmem[i*4+3][7:6],   pmem[i*4+2][7:6],   pmem[i*4+1][7:6],   pmem[i*4+0][7:6]};
119
        end
120
  end
121
 
122
//
123
// Generate Clock & Reset
124
//------------------------------
125
initial
126
  begin
127
     oscclk = 1'b0;
128
     forever #10.4 oscclk <= ~oscclk; // 48 MHz
129
  end
130
 
131
initial
132
  begin
133
     porst_n       = 1'b1;
134
     pbrst_n       = 1'b1;
135
     #100;
136
     porst_n       = 1'b0;
137
     pbrst_n       = 1'b0;
138
     #600;
139
     porst_n       = 1'b1;
140
     pbrst_n       = 1'b1;
141
  end
142
 
143
//
144
// Global initialization
145
//------------------------------
146
initial
147
  begin
148
     error         = 0;
149
     stimulus_done = 1;
150
     switch        = 10'h000;
151 107 olivier.gi
     dbg_uart_rxd  = 1'b1;
152 80 olivier.gi
  end
153
 
154
//
155
// openMSP430 FPGA Instance
156
//----------------------------------
157
 
158
openMSP430_fpga dut (
159
 
160
// OUTPUTs
161
    .din_x        (din_x),          // SPI Serial Data
162
    .din_y        (din_y),          // SPI Serial Data
163
    .led          (led),            // Board LEDs
164
    .sclk_x       (sclk_x),         // SPI Serial Clock
165
    .sclk_y       (sclk_y),         // SPI Serial Clock
166
    .sync_n_x     (sync_n_x),       // SPI Frame synchronization signal (low active)
167
    .sync_n_y     (sync_n_y),       // SPI Frame synchronization signal (low active)
168 107 olivier.gi
    .uart_tx      (dbg_uart_txd),   // Board UART TX pin
169 80 olivier.gi
 
170
// INPUTs
171
    .oscclk       (oscclk),         // Board Oscillator (?? MHz)
172
    .porst_n      (porst_n),        // Board Power-On reset (active low)
173
    .pbrst_n      (pbrst_n),        // Board Push-Button reset (active low)
174 107 olivier.gi
    .uart_rx      (dbg_uart_rxd),   // Board UART RX pin
175 80 olivier.gi
    .switch       (switch)          // Board Switches
176
);
177
 
178
 
179
//
180
// 12 BIT DACs
181
//----------------------------------------
182
 
183
DAC121S101 DAC121S101_x (
184
 
185
// OUTPUTs
186
    .vout         (vout_x),        // Peripheral data output
187
 
188
// INPUTs
189
    .din          (din_x),         // SPI Serial Data
190
    .sclk         (sclk_x),        // SPI Serial Clock
191
    .sync_n       (sync_n_x)       // SPI Frame synchronization signal (low active)
192
);
193
 
194
DAC121S101 DAC121S101_y (
195
 
196
// OUTPUTs
197
    .vout         (vout_y),        // Peripheral data output
198
 
199
// INPUTs
200
    .din          (din_y),         // SPI Serial Data
201
    .sclk         (sclk_y),        // SPI Serial Clock
202
    .sync_n       (sync_n_y)       // SPI Frame synchronization signal (low active)
203
);
204
 
205
 
206
//
207
// Debug utility signals
208
//----------------------------------------
209
msp_debug msp_debug_0 (
210
 
211
// OUTPUTs
212
    .e_state      (e_state),       // Execution state
213
    .i_state      (i_state),       // Instruction fetch state
214
    .inst_cycle   (inst_cycle),    // Cycle number within current instruction
215
    .inst_full    (inst_full),     // Currently executed instruction (full version)
216
    .inst_number  (inst_number),   // Instruction number since last system reset
217
    .inst_pc      (inst_pc),       // Instruction Program counter
218
    .inst_short   (inst_short),    // Currently executed instruction (short version)
219
 
220
// INPUTs
221
    .mclk         (mclk),          // Main system clock
222 111 olivier.gi
    .puc_rst      (puc_rst)        // Main system reset
223 80 olivier.gi
);
224
 
225
//
226
// Generate Waveform
227
//----------------------------------------
228
initial
229
  begin
230
   `ifdef VPD_FILE
231
     $vcdplusfile("tb_openMSP430_fpga.vpd");
232
     $vcdpluson();
233
   `else
234 98 olivier.gi
     `ifdef TRN_FILE
235
        $recordfile ("tb_openMSP430_fpga.trn");
236
        $recordvars;
237
     `else
238
        $dumpfile("tb_openMSP430_fpga.vcd");
239
        $dumpvars(0, tb_openMSP430_fpga);
240
     `endif
241 80 olivier.gi
   `endif
242
  end
243
 
244
//
245
// End of simulation
246
//----------------------------------------
247
 
248
initial // Timeout
249
  begin
250
     #500000;
251
     $display(" ===============================================");
252
     $display("|               SIMULATION FAILED               |");
253
     $display("|              (simulation Timeout)             |");
254
     $display(" ===============================================");
255
     $finish;
256
  end
257
 
258
initial // Normal end of test
259
  begin
260
     @(inst_pc===16'hffff)
261
     $display(" ===============================================");
262
     if (error!=0)
263
       begin
264
          $display("|               SIMULATION FAILED               |");
265
          $display("|     (some verilog stimulus checks failed)     |");
266
       end
267
     else if (~stimulus_done)
268
       begin
269
          $display("|               SIMULATION FAILED               |");
270
          $display("|     (the verilog stimulus didn't complete)    |");
271
       end
272
     else
273
       begin
274
          $display("|               SIMULATION PASSED               |");
275
       end
276
     $display(" ===============================================");
277
     $finish;
278
  end
279
 
280
 
281
//
282
// Tasks Definition
283
//------------------------------
284
 
285
   task tb_error;
286
      input [65*8:0] error_string;
287
      begin
288
         $display("ERROR: %s %t", error_string, $time);
289
         error = error+1;
290
      end
291
   endtask
292
 
293
 
294
endmodule

powered by: WebSVN 2.1.0

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