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

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [rtl/] [flash_sram/] [flash_top.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 xianfeng
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  XESS Flash interface                                        ////
4
////                                                              ////
5
////  This file is part of the OR1K test application              ////
6
////  http://www.opencores.org/cores/or1k/                        ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Connects the SoC to the Flash found on XSV board. It also   ////
10
////  implements a generic flash model for simulations.           ////
11
////                                                              ////
12
////  To Do:                                                      ////
13
////   - nothing really                                           ////
14
////                                                              ////
15
////  Author(s):                                                  ////
16
////      - Lior Shtram, lior.shtram@flextronicssemi.com          ////
17
////      - Damjan Lampret, lampret@opencores.org                 ////
18
////                                                              ////
19
//////////////////////////////////////////////////////////////////////
20
////                                                              ////
21
//// Copyright (C) 2001 Authors                                   ////
22
////                                                              ////
23
//// This source file may be used and distributed without         ////
24
//// restriction provided that this copyright statement is not    ////
25
//// removed from the file and that any derivative work contains  ////
26
//// the original copyright notice and the associated disclaimer. ////
27
////                                                              ////
28
//// This source file is free software; you can redistribute it   ////
29
//// and/or modify it under the terms of the GNU Lesser General   ////
30
//// Public License as published by the Free Software Foundation; ////
31
//// either version 2.1 of the License, or (at your option) any   ////
32
//// later version.                                               ////
33
////                                                              ////
34
//// This source is distributed in the hope that it will be       ////
35
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
36
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
37
//// PURPOSE.  See the GNU Lesser General Public License for more ////
38
//// details.                                                     ////
39
////                                                              ////
40
//// You should have received a copy of the GNU Lesser General    ////
41
//// Public License along with this source; if not, download it   ////
42
//// from http://www.opencores.org/lgpl.shtml                     ////
43
////                                                              ////
44
//////////////////////////////////////////////////////////////////////
45
//
46
// CVS Revision History
47
//
48
// $Log: flash_top.v,v $
49
// Revision 1.4  2002/09/16 02:51:23  lampret
50
// Delayed wb_err_o. Disabled wb_ack_o when wb_err_o is asserted.
51
//
52
// Revision 1.3  2002/08/14 06:24:43  lampret
53
// Fixed size of generic flash/sram to exactly 2MB
54
//
55
// Revision 1.2  2002/08/12 05:33:50  lampret
56
// Changed logic when FLASH_GENERIC_REGISTERED
57
//
58
// Revision 1.1.1.1  2002/03/21 16:55:44  lampret
59
// First import of the "new" XESS XSV environment.
60
//
61
//
62
// Revision 1.4  2002/02/11 04:41:01  lampret
63
// Allow flash writes. Ugly workaround for something else...
64
//
65
// Revision 1.3  2002/01/23 07:50:44  lampret
66
// Added wb_err_o to flash and sram i/f for testing the buserr exception.
67
//
68
// Revision 1.2  2002/01/14 06:18:22  lampret
69
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
70
//
71
// Revision 1.1.1.1  2001/11/04 19:00:09  lampret
72
// First import.
73
//
74
//
75
 
76
// synopsys translate_off
77
//`include "timescale.v"
78
// synopsys translate_on
79
//`include "bench_define.v"
80
 
81
`ifdef FLASH_GENERIC
82
 
83
module flash_top (
84
  wb_clk_i, wb_rst_i,
85
 
86
  wb_dat_i, wb_dat_o, wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i,
87
  wb_stb_i, wb_ack_o, wb_err_o,
88
 
89
  flash_rstn, cen, oen, wen, rdy, d, a, a_oe
90
);
91
 
92
//
93
// I/O Ports
94
//
95
 
96
//
97
// Common WB signals
98
//
99
input                   wb_clk_i;
100
input                   wb_rst_i;
101
 
102
//
103
// WB slave i/f
104
//
105
input   [31:0]           wb_dat_i;
106
output  [31:0]           wb_dat_o;
107
input   [31:0]           wb_adr_i;
108
input   [3:0]            wb_sel_i;
109
input                   wb_we_i;
110
input                   wb_cyc_i;
111
input                   wb_stb_i;
112
output                  wb_ack_o;
113
output                  wb_err_o;
114
 
115
//
116
// Flash i/f
117
//
118
output                  flash_rstn;
119
output                  oen;
120
output                  cen;
121
output                  wen;
122
input                   rdy;
123
inout   [7:0]            d;
124
output  [20:0]           a;
125
output                  a_oe;
126
 
127
//
128
// Internal wires and regs
129
//
130
reg     [7:0]            mem [8388607:0];
131
wire    [31:0]           adr;
132
`ifdef FLASH_GENERIC_REGISTERED
133
reg                     wb_err_o;
134
reg     [31:0]           prev_adr;
135
reg     [1:0]            delay;
136
`else
137
wire    [1:0]            delay;
138
`endif
139
wire                    wb_err;
140
 
141
//
142
// Aliases and simple assignments
143
//
144
assign flash_rstn = 1'b1;
145
assign oen = 1'b1;
146
assign cen = 1'b1;
147
assign wen = 1'b1;
148
assign a = 23'b0;
149
assign a_oe = 1'b1;
150
assign wb_err = wb_cyc_i & wb_stb_i & (delay == 2'd0) & (|wb_adr_i[25:23]);     // If Access to > 8MB (8-bit leading prefix ignored)
151
assign adr = {6'h00, wb_adr_i[25:2], 2'b00};
152
 
153
//
154
// For simulation only
155
//
156
initial $readmemh("../src/flash.in", mem, 0);
157
 
158
//
159
// Reading from flash model
160
//
161
assign wb_dat_o[7:0] = wb_adr_i[23:0] < 65535 ? mem[adr+3] : 8'h00;
162
assign wb_dat_o[15:8] = wb_adr_i[23:0] < 65535 ? mem[adr+2] : 8'h00;
163
assign wb_dat_o[23:16] = wb_adr_i[23:0] < 65535 ? mem[adr+1] : 8'h00;
164
assign wb_dat_o[31:24] = wb_adr_i[23:0] < 65535 ? mem[adr+0] : 8'h00;
165
 
166
 
167
`ifdef FLASH_GENERIC_REGISTERED
168
//
169
// WB Acknowledge
170
//
171
always @(posedge wb_clk_i or posedge wb_rst_i)
172
        if (wb_rst_i) begin
173
                delay <= #1 2'd3;
174
                prev_adr <= #1 32'h0000_0000;
175
        end
176
        else if (delay && (wb_adr_i == prev_adr) && wb_cyc_i && wb_stb_i)
177
                delay <= #1 delay - 2'd1;
178
        else if (wb_ack_o || wb_err_o || (wb_adr_i != prev_adr) || ~wb_stb_i) begin
179
                delay <= #1 2'd0;       // delay ... can range from 3 to 0
180
                prev_adr <= #1 wb_adr_i;
181
        end
182
`else
183
assign delay = 2'd0;
184
`endif
185
 
186
assign wb_ack_o = wb_cyc_i & wb_stb_i & ~wb_err & (delay == 2'd0)
187
`ifdef FLASH_GENERIC_REGISTERED
188
        & (wb_adr_i == prev_adr)
189
`endif
190
        ;
191
 
192
`ifdef FLASH_GENERIC_REGISTERED
193
//
194
// WB Error
195
//
196
always @(posedge wb_clk_i or posedge wb_rst_i)
197
        if (wb_rst_i)
198
                wb_err_o <= #1 1'b0;
199
        else
200
                wb_err_o <= #1 wb_err & !wb_err_o;
201
`else
202
assign wb_err_o = wb_err;
203
`endif
204
 
205
//
206
// Flash i/f monitor
207
//
208
// synopsys translate_off
209
integer fflash;
210
initial fflash = $fopen("flash.log");
211
always @(posedge wb_clk_i)
212
        if (wb_cyc_i)
213
                if (wb_stb_i & wb_we_i) begin
214
//                      $fdisplay(fflash, "%t Trying to write into flash at %h (%b)", $time, wb_adr_i, wb_we_i);
215
//                      #100 $finish;
216
                        if (wb_sel_i[3])
217
                                mem[{wb_adr_i[23:2], 2'b00}+0] = wb_dat_i[31:24];
218
                        if (wb_sel_i[2])
219
                                mem[{wb_adr_i[23:2], 2'b00}+1] = wb_dat_i[23:16];
220
                        if (wb_sel_i[1])
221
                                mem[{wb_adr_i[23:2], 2'b00}+2] = wb_dat_i[15:8];
222
                        if (wb_sel_i[0])
223
                                mem[{wb_adr_i[23:2], 2'b00}+3] = wb_dat_i[7:0];
224
                        $fdisplay(fflash, "%t [%h] <- write %h, byte sel %b", $time, wb_adr_i, wb_dat_i, wb_sel_i);
225
                end else if (wb_ack_o)
226
                        $fdisplay(fflash, "%t [%h] -> read %h", $time, wb_adr_i, wb_dat_o);
227
// synopsys translate_on
228
 
229
endmodule
230
 
231
`else
232
 
233
module flash_top (
234
  wb_clk_i, wb_rst_i,
235
 
236
  wb_dat_i, wb_dat_o, wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i,
237
  wb_stb_i, wb_ack_o, wb_err_o,
238
 
239
  flash_rstn, cen, oen, wen, rdy, d, a, a_oe
240
);
241
 
242
//
243
// I/O Ports
244
//
245
 
246
//
247
// Common WB signals
248
//
249
input                   wb_clk_i;
250
input                   wb_rst_i;
251
 
252
//
253
// WB slave i/f
254
//
255
input   [31:0]           wb_dat_i;
256
output  [31:0]           wb_dat_o;
257
input   [31:0]           wb_adr_i;
258
input   [3:0]            wb_sel_i;
259
input                   wb_we_i;
260
input                   wb_cyc_i;
261
input                   wb_stb_i;
262
output                  wb_ack_o;
263
output                  wb_err_o;
264
 
265
//
266
// Flash i/f
267
//
268
output                  flash_rstn;
269
output                  oen;
270
output                  cen;
271
output                  wen;
272
input                   rdy;
273
inout   [7:0]            d;
274
output  [20:0]           a;
275
output                  a_oe;
276
 
277
//
278
// Internal wires and regs
279
//
280
reg                     ack;
281
reg     [3:0]            middle_tphqv;
282
reg     [31:0]           wb_dat_o;
283
reg     [4:0]            counter;
284
 
285
//
286
// Aliases and simple assignments
287
//
288
assign wb_ack_o = ~wb_err_o & ack;
289
assign wb_err_o = 1'b0;
290
assign flash_rstn = ~wb_rst_i;
291
assign a = { ~wb_adr_i[20], wb_adr_i[19:2], counter[3:2] };     // Lower 1MB is used by FPGA design conf.
292
assign a_oe = (wb_cyc_i &! (|middle_tphqv));
293
assign oen = |middle_tphqv;
294
assign wen = 1'b1;
295
assign cen = ~wb_cyc_i | ~wb_stb_i | (|middle_tphqv) | (counter[1:0] == 2'b00);
296
 
297
//
298
// Flash access time counter
299
//
300
always @(posedge wb_clk_i or posedge wb_rst_i)
301
begin
302
  if (wb_rst_i)
303
    counter <= #1 5'h0;
304
  else
305
  if (!wb_cyc_i | (counter == 5'h10) | (|middle_tphqv))
306
    counter <= #1 5'h0;
307
  else
308
    counter <= #1 counter + 1;
309
end
310
 
311
//
312
// Acknowledge
313
//
314
always @(posedge wb_clk_i or posedge wb_rst_i)
315
begin
316
  if (wb_rst_i)
317
    ack <= #1 1'h0;
318
  else
319
  if (counter == 5'h0f && !(|middle_tphqv))
320
    ack <= #1 1'h1;
321
  else
322
    ack <= #1 1'h0;
323
end
324
 
325
//
326
// Flash i/f monitor
327
//
328
// synopsys translate_off
329
integer fflash;
330
initial fflash = $fopen("flash.log");
331
 
332
always @(posedge wb_clk_i)
333
begin
334
  if (wb_cyc_i & !(|middle_tphqv)) begin
335
    if (wb_stb_i & wb_we_i) begin
336
      $fdisplay(fflash, "%t Trying to write into flash at %h", $time, wb_adr_i);
337
//    #100 $finish;
338
    end
339
    else if (ack)
340
      $fdisplay(fflash, "%t [%h] -> read %h", $time, wb_adr_i, wb_dat_o);
341
  end
342
end
343
// synopsys translate_on
344
 
345
always @(posedge wb_clk_i or posedge wb_rst_i)
346
  if (wb_rst_i)
347
    middle_tphqv <= #1 4'hf;
348
  else if (middle_tphqv)
349
    middle_tphqv <= #1 middle_tphqv - 1;
350
 
351
//
352
// Flash 8-bit data expand into 32-bit WB data
353
//
354
always @(posedge wb_clk_i or posedge wb_rst_i)
355
begin
356
  if (wb_rst_i)
357
    wb_dat_o <= #1 32'h0000_0000;
358
  else
359
  if (counter[1:0] == 2'h3)
360
    begin
361
      case (counter[3:2])
362
        2'h0 : wb_dat_o[31:24] <= #1 d;
363
        2'h1 : wb_dat_o[23:16] <= #1 d;
364
        2'h2 : wb_dat_o[15:8]  <= #1 d;
365
        2'h3 : wb_dat_o[7:0]   <= #1 d;
366
      endcase
367
    end
368
end
369
 
370
endmodule
371
 
372
`endif

powered by: WebSVN 2.1.0

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