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 104

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

powered by: WebSVN 2.1.0

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