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

Subversion Repositories cfi_ctrl

[/] [cfi_ctrl/] [trunk/] [bench/] [verilog/] [cfi_ctrl_engine_wb_bench.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 julius
/* Testbench of Wishbone classic-slave wrapped CFI engine controller */
2
 
3
`include "def.h"
4
`include "data.h"
5
 
6
`timescale 1ns/1ps
7
 
8
module cfi_ctrl_engine_wb_bench();
9
 
10
 
11
  // Signal Bus
12
  wire [`ADDRBUS_dim - 1:0] A;         // Address Bus 
13
  wire [`DATABUS_dim - 1:0] DQ;        // Data I/0 Bus
14
  // Control Signal
15
  wire WE_N;                            // Write Enable 
16
  wire OE_N;                            // Output Enable
17
  wire CE_N;                            // Chip Enable
18
  wire RST_N;                           // Reset
19
  wire WP_N;                           // Write Protect
20
  wire ADV_N;                            // Latch Enable
21
  wire CLK;                              // Clock
22
  wire WAIT;                           // Wait
23
 
24
  // Voltage signal rappresentad by integer Vector which correspond to millivolts
25
  wire [`Voltage_range] VCC;  // Supply Voltage
26
  wire [`Voltage_range] VCCQ; // Supply Voltage for I/O Buffers
27
  wire [`Voltage_range] VPP; // Optional Supply Voltage for Fast Program & Erase  
28
 
29
  //wire STS;
30
 
31
  wire Info;      // Activate/Deactivate info device operation
32
assign Info = 1;
33
assign VCC = 36'd1700;
34
assign VCCQ = 36'd1700;
35
assign VPP = 36'd2000;
36
 
37
parameter sys_clk_half_period = 15.15/2; /* 66MHz */
38
parameter sys_clk_period = sys_clk_half_period*2;
39
   reg sys_clk;
40
   reg sys_rst;
41
 
42
initial begin
43
   sys_clk  = 0;
44
   forever
45
      #sys_clk_half_period sys_clk  = ~sys_clk;
46
end
47
 
48
initial begin
49
   sys_rst  = 1;
50
   #sys_clk_period;
51
   #sys_clk_period;
52
   sys_rst  = 0;
53
end
54
 
55
   reg [31:0] wb_adr_i;
56
   reg [31:0] wb_dat_i;
57
   reg        wb_stb_i;
58
   reg        wb_cyc_i;
59
   reg [3:0]  wb_sel_i;
60
   reg        wb_we_i;
61
   wire [31:0] wb_dat_o;
62
   wire        wb_ack_o;
63
 
64
   task wb_wait_for_ack;
65
      begin
66
         while (!wb_ack_o)
67
           #sys_clk_period;
68
 
69
         wb_stb_i = 0;
70
         wb_cyc_i = 0;
71
         /* Leave these deasserted for a cycle */
72
         #sys_clk_period;
73
      end
74
   endtask // wb_wait_for_ack
75
 
76
   task wb_write_16bits;
77
      input [31:0] address;
78
      input [15:0] dat;
79
      begin
80
         wb_adr_i = {address[31:1],1'b0};
81
         wb_dat_i = {dat,dat};
82
         wb_sel_i = address[1] ? 4'h3 : 4'hc;
83
         wb_we_i = 1;
84
         wb_stb_i = 1;
85
         wb_cyc_i = 1;
86
         #sys_clk_period;
87
         wb_wait_for_ack();
88
      end
89
   endtask // wb_write_16bits
90
 
91
 
92
   task wb_write_32bits;
93
      input [31:0] address;
94
      input [31:0] dat;
95
      begin
96
         wb_adr_i = address;
97
         wb_dat_i = dat;
98
         wb_sel_i = 4'hf;
99
         wb_we_i = 1;
100
         wb_stb_i = 1;
101
         wb_cyc_i = 1;
102
         #sys_clk_period;
103
         wb_wait_for_ack();
104
      end
105
   endtask // wb_write_32bits
106
 
107
   task wb_read_8bits;
108
      input [31:0] address;
109
      output [7:0] dat;
110
      begin
111
         wb_adr_i = address[31:0];
112
         wb_sel_i = address[1:0] == 2'b00 ? 4'h8 :
113
                    address[1:0] == 2'b01 ? 4'h4 :
114
                    address[1:0] == 2'b10 ? 4'h2 : 4'h1;
115
         wb_we_i = 0;
116
         wb_stb_i = 1;
117
         wb_cyc_i = 1;
118
         #sys_clk_period;
119
         wb_wait_for_ack();
120
         dat = address[1:0] == 2'b00 ? wb_dat_o[31:24] :
121
               address[1:0] == 2'b01 ? wb_dat_o[23:16] :
122
               address[1:0] == 2'b10 ? wb_dat_o[15:8]  : wb_dat_o[7:0];
123
      end
124
   endtask // wb_read_16bits
125
 
126
   task wb_read_16bits;
127
      input [31:0] address;
128
      output [15:0] dat;
129
      begin
130
         wb_adr_i = {address[31:1],1'b0};
131
         wb_sel_i = address[1] ? 4'h3 : 4'hc;
132
         wb_we_i = 0;
133
         wb_stb_i = 1;
134
         wb_cyc_i = 1;
135
         #sys_clk_period;
136
         wb_wait_for_ack();
137
         dat = address[1] ? wb_dat_o[15:0] : wb_dat_o[31:16];
138
      end
139
   endtask // wb_read_16bits
140
 
141
   task wb_read_32bits;
142
      input [31:0] address;
143
      output [31:0] dat;
144
      begin
145
         wb_adr_i = address;
146
         wb_sel_i = 4'hf;
147
         wb_we_i = 0;
148
         wb_stb_i = 1;
149
         wb_cyc_i = 1;
150
         #sys_clk_period;
151
         wb_wait_for_ack();
152
         dat = wb_dat_o;
153
      end
154
   endtask // wb_read_32bits
155
 
156
   reg [31:0] temp_data;
157
   reg [7:0]  status_reg;
158
 
159
    task wb_cfi_write_16bits;
160
      input [31:0] address;
161
      input [15:0] dat;
162
      begin
163
         wb_write_16bits(address, dat);
164
         wb_read_32bits(32'h0c00_0004, temp_data);
165
         while (!temp_data[7])
166
           wb_read_32bits(32'h0c00_0004, temp_data);
167
      end
168
   endtask // wb_cfi_write_32bits
169
 
170
   task wb_cfi_write_32bits;
171
      input [31:0] address;
172
      input [31:0] dat;
173
      begin
174
         wb_cfi_write_16bits(address, dat[31:16]);
175
         wb_cfi_write_16bits(address+2, dat[15:0]);
176
      end
177
   endtask // wb_cfi_write_32bits
178
 
179
   task wb_cfi_unlock_and_erase_block;
180
      input [31:0] address;
181
      begin
182
         wb_write_32bits(32'h0400_0000+address, 32'd0);
183
         wb_write_32bits(32'h0800_0000+address, 32'd0);
184
         wb_read_32bits(32'h0c00_0004, temp_data);
185
         while (!temp_data[7])
186
           wb_read_32bits(32'h0c00_0004, temp_data);
187
      end
188
   endtask
189
 
190
   task wb_cfi_read_device_ident;
191
      input [31:0] address;
192
      output [15:0] data;
193
      begin
194
         wb_read_16bits(32'h0e00_0000+(address<<1), data);
195
      end
196
   endtask // wb_cfi_read_device_ident
197
 
198
   task wb_cfi_query;
199
      input [31:0] address;
200
      output [15:0] data;
201
      begin
202
         wb_read_16bits(32'h0e01_0000+(address<<1), data);
203
      end
204
   endtask // wb_cfi_query
205
 
206
   task wb_cfi_read_all_device_ident;
207
      begin
208
         $display("%t Reading device identifier information", $time);
209
         wb_cfi_read_device_ident(0,temp_data[15:0]);
210
         $display("%t Manufacturer code: %04h",$time,temp_data[15:0]);
211
         wb_cfi_read_device_ident(31'h1,temp_data[15:0]);
212
         $display("%t Device ID code: %04h",$time,temp_data[15:0]);
213
         wb_cfi_read_device_ident(31'h5,temp_data[15:0]);
214
         $display("%t RCR: %04h",$time,temp_data[15:0]);
215
         wb_cfi_read_device_ident(31'h2 + ((128*1024)>>1),temp_data[15:0]);
216
         $display("%t Block 0 locked?: %04h",$time,temp_data[15:0]);
217
      end
218
   endtask // wb_cfi_read_all_device_ident
219
 
220
   task wb_cfi_queries;
221
      begin
222
         $display("%t Querying CFI device", $time);
223
         wb_cfi_query(31'h10,temp_data[15:0]);
224
         $display("%t Query ID string: %04h",$time,temp_data[15:0]);
225
         wb_cfi_query(31'h13,temp_data[15:0]);
226
         $display("%t Vendor command set and control interface ID: %04h",$time,temp_data[15:0]);
227
         wb_cfi_query(31'h27,temp_data[15:0]);
228
         $display("%t size 2^n: %04h",$time,temp_data[15:0]);
229
         wb_cfi_query(31'h28,temp_data[15:0]);
230
         $display("%t device interface code: %04h",$time,temp_data[15:0]);
231
         wb_cfi_query(31'h2c,temp_data[15:0]);
232
         $display("%t number of erase block regions: %04h",$time,temp_data[15:0]);
233
 
234
      end
235
      endtask
236
 
237
   integer i;
238
 
239
 /* Main test stimulus block */
240
initial begin
241
 
242
   wb_adr_i = 0;
243
   wb_dat_i = 0;
244
   wb_stb_i = 0;
245
   wb_cyc_i = 0;
246
   wb_sel_i = 0;
247
   wb_we_i = 0;
248
 
249
   $dumpfile("../out/cfi_ctrl_wb_engine_bench.vcd");
250
   $dumpvars(0);
251
   $display("Starting CFI Wishbone controller test");
252
   #550; // Wait for the part to power up
253
 
254
 
255
   wb_cfi_read_all_device_ident();
256
   #500;
257
   wb_cfi_queries();
258
   #500;
259
 
260
   /* Ready first block for play*/
261
   wb_cfi_unlock_and_erase_block(0);
262
 
263
   /* Clear status register */
264
   wb_write_32bits(32'h0c00_0000, {29'd0,3'b010});
265
 
266
   /* Write a 32-bit word */
267
   wb_cfi_write_32bits(32'h0000_0000, 32'hdeadbeef);
268
 
269
   /* read it back */
270
   wb_read_32bits(32'h0000_0000, temp_data);
271
 
272
   /* Write 4k of data  */
273
   for (i = 0; i< ((4*1024)/4); i=i+1) begin
274
      wb_cfi_write_32bits(32'h0000_0000+i*4, 32'hdeadbeef+i);
275
   end
276
 
277
   /* Read it back 16-bits at a time and check it */
278
   for (i = 0; i< ((4*1024)/4); i=i+1) begin
279
      wb_read_16bits(32'h0000_0000+i*4, temp_data[31:16]);
280
      wb_read_16bits(32'h0000_0000+i*4+2, temp_data[15:0]);
281
      if (temp_data != (32'hdeadbeef+i))
282
        $display("Read verify error at %h",(i*4));
283
   end
284
   /* Read it back 8-bits at a time and check it */
285
   for (i = 0; i< ((4*1024)/4); i=i+1) begin
286
      wb_read_8bits(32'h0000_0000+i*4, temp_data[31:24]);
287
      wb_read_8bits(32'h0000_0000+i*4+1, temp_data[23:16]);
288
      wb_read_8bits(32'h0000_0000+i*4+2, temp_data[15:8]);
289
      wb_read_8bits(32'h0000_0000+i*4+3, temp_data[7:0]);
290
      if (temp_data != (32'hdeadbeef+i))
291
        $display("Read verify error at %h",(i*4));
292
   end
293
   $finish();
294
 
295
 
296
   /* Read it back and check it */
297
   for (i = 0; i< ((4*1024)/4); i=i+1) begin
298
      wb_read_32bits(32'h0000_0000+i*4, temp_data);
299
      if (temp_data != (32'hdeadbeef+i))
300
        $display("Read verify error at %h",(i*4));
301
   end
302
 
303
   /* Test doing things on next block */
304
   wb_cfi_unlock_and_erase_block(32'h20000);
305
 
306
   /* Write 4k of data  */
307
   for (i = 0; i< ((4*1024)/4); i=i+1) begin
308
      wb_cfi_write_32bits(32'h0002_0000+i*4, 32'hdeadbeef+i);
309
   end
310
   /* Read it back and check it */
311
   for (i = 0; i< ((4*1024)/4); i=i+1) begin
312
      wb_read_32bits(32'h0002_0000+i*4, temp_data);
313
      if (temp_data != (32'hdeadbeef+i))
314
        $display("Read verify error at %h",(i*4));
315
   end
316
 
317
   /* Read it back 16-bits at a time and check it */
318
   for (i = 0; i< ((4*1024)/4); i=i+1) begin
319
      wb_read_16bits(32'h0002_0000+i*4, temp_data[31:16]);
320
      wb_read_16bits(32'h0002_0000+i*4+2, temp_data[15:0]);
321
      if (temp_data != (32'hdeadbeef+i))
322
        $display("Read verify error at %h",(i*4));
323
   end
324
 
325
   $display("Finishing CFI Wishbone controller test");
326
   $finish;
327
end
328
 
329
/* timeout function - sim shouldn't run much longer than this */
330
/*
331
initial begin
332
   #55000;
333
   $display("Simulation finish due to timeout");
334
   $finish;
335
end
336
*/
337
cfi_ctrl
338
  #(.cfi_engine("ENABLED"))
339
  dut
340
   (
341
    .wb_clk_i(sys_clk),
342
    .wb_rst_i(sys_rst),
343
 
344
    .wb_adr_i(wb_adr_i),
345
    .wb_dat_i(wb_dat_i),
346
    .wb_stb_i(wb_stb_i),
347
    .wb_cyc_i(wb_cyc_i),
348
    .wb_we_i (wb_we_i ),
349
    .wb_sel_i(wb_sel_i),
350
    .wb_dat_o(wb_dat_o),
351
    .wb_ack_o(wb_ack_o),
352
 
353
    .flash_dq_io(DQ),
354
    .flash_adr_o(A),
355
    .flash_adv_n_o(ADV_N),
356
    .flash_ce_n_o(CE_N),
357
    .flash_clk_o(CLK),
358
    .flash_oe_n_o(OE_N),
359
    .flash_rst_n_o(RST_N),
360
    .flash_wait_i(WAIT),
361
    .flash_we_n_o(WE_N),
362
    .flash_wp_n_o(WP_N)
363
    );
364
 
365
x28fxxxp30 part(A, DQ, WE_N, OE_N, CE_N, ADV_N, CLK,
366
                WAIT, WP_N, RST_N, VCC, VCCQ, VPP, Info);
367
 
368
 
369
endmodule

powered by: WebSVN 2.1.0

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