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

Subversion Repositories or1k

[/] [or1k/] [tags/] [first/] [orp/] [orp_soc/] [rtl/] [verilog/] [mem_if/] [flash_top.v] - Blame information for rev 1778

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

Line No. Rev Author Line
1 746 lampret
//////////////////////////////////////////////////////////////////////
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: not supported by cvs2svn $
49
// Revision 1.4  2002/02/11 04:41:01  lampret
50
// Allow flash writes. Ugly workaround for something else...
51
//
52
// Revision 1.3  2002/01/23 07:50:44  lampret
53
// Added wb_err_o to flash and sram i/f for testing the buserr exception.
54
//
55
// Revision 1.2  2002/01/14 06:18:22  lampret
56
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
57
//
58
// Revision 1.1.1.1  2001/11/04 19:00:09  lampret
59
// First import.
60
//
61
//
62
 
63
// synopsys translate_off
64
`include "timescale.v"
65
// synopsys translate_on
66
//`include "bench_define.v"
67
 
68
`ifdef FLASH_GENERIC
69
 
70
module flash_top (
71
  wb_clk_i, wb_rst_i,
72
 
73
  wb_dat_i, wb_dat_o, wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i,
74
  wb_stb_i, wb_ack_o, wb_err_o,
75
 
76
  flash_rstn, cen, oen, wen, rdy, d, a, a_oe
77
);
78
 
79
//
80
// I/O Ports
81
//
82
 
83
//
84
// Common WB signals
85
//
86
input                   wb_clk_i;
87
input                   wb_rst_i;
88
 
89
//
90
// WB slave i/f
91
//
92
input   [31:0]           wb_dat_i;
93
output  [31:0]           wb_dat_o;
94
input   [31:0]           wb_adr_i;
95
input   [3:0]            wb_sel_i;
96
input                   wb_we_i;
97
input                   wb_cyc_i;
98
input                   wb_stb_i;
99
output                  wb_ack_o;
100
output                  wb_err_o;
101
 
102
//
103
// Flash i/f
104
//
105
output                  flash_rstn;
106
output                  oen;
107
output                  cen;
108
output                  wen;
109
input                   rdy;
110
inout   [7:0]            d;
111
output  [20:0]           a;
112
output                  a_oe;
113
 
114
//
115
// Internal wires and regs
116
//
117
reg     [7:0]            mem [65535:0];
118
wire    [31:0]           adr;
119
`ifdef FLASH_GENERIC_REGISTERED
120
reg                     wb_ack_o;
121
reg                     wb_err_o;
122
reg     [31:0]           wb_dat_o;
123
`endif
124
wire                    wb_err;
125
 
126
//
127
// Aliases and simple assignments
128
//
129
assign flash_rstn = 1'b1;
130
assign oen = 1'b1;
131
assign cen = 1'b1;
132
assign wen = 1'b1;
133
assign a = 21'b0;
134
assign a_oe = 1'b1;
135
assign wb_err = wb_cyc_i & wb_stb_i & (|wb_adr_i[27:21]);     // If Access to > 2MB (4-bit leading prefix ignored)
136
assign adr = {wb_adr_i[31:2], 2'b00};
137
 
138
//
139
// For simulation only
140
//
141
initial $readmemh("../src/flash.in", mem, 0);
142
`ifdef FLASH_GENERIC_REGISTERED
143
//
144
// Reading from flash model
145
//
146
always @(posedge wb_rst_i or posedge wb_clk_i)
147
        if (wb_rst_i)
148
                wb_dat_o <= #1 32'h0000_0000;
149
        else begin
150
                wb_dat_o[7:0] <= #1 wb_adr_i < 65535 ? mem[adr+3] : 8'h00;
151
                wb_dat_o[15:8] <= #1 wb_adr_i < 65535 ? mem[adr+2] : 8'h00;
152
                wb_dat_o[23:16] <= #1 wb_adr_i < 65535 ? mem[adr+1] : 8'h00;
153
                wb_dat_o[31:24] <= #1 wb_adr_i < 65535 ? mem[adr+0] : 8'h00;
154
        end
155
`else
156
assign wb_dat_o[7:0] = wb_adr_i < 65535 ? mem[adr+3] : 8'h00;
157
assign wb_dat_o[15:8] = wb_adr_i < 65535 ? mem[adr+2] : 8'h00;
158
assign wb_dat_o[23:16] = wb_adr_i < 65535 ? mem[adr+1] : 8'h00;
159
assign wb_dat_o[31:24] = wb_adr_i < 65535 ? mem[adr+0] : 8'h00;
160
`endif
161
 
162
`ifdef FLASH_GENERIC_REGISTERED
163
//
164
// WB Acknowledge
165
//
166
always @(posedge wb_clk_i or posedge wb_rst_i)
167
        if (wb_rst_i)
168
                wb_ack_o <= #1 1'b0;
169
        else
170
                wb_ack_o <= #1 wb_cyc_i & wb_stb_i & !wb_ack_o;
171
`else
172
assign wb_ack_o = wb_cyc_i & wb_stb_i;
173
`endif
174
 
175
`ifdef FLASH_GENERIC_REGISTERED
176
//
177
// WB Error
178
//
179
always @(posedge wb_clk_i or posedge wb_rst_i)
180
        if (wb_rst_i)
181
                wb_err_o <= #1 1'b0;
182
        else
183
                wb_err_o <= #1 wb_err & !wb_err_o;
184
`else
185
assign wb_err_o = wb_err;
186
`endif
187
 
188
//
189
// Flash i/f monitor
190
//
191
// synopsys translate_off
192
integer fflash;
193
initial fflash = $fopen("flash.log");
194
always @(posedge wb_clk_i)
195
        if (wb_cyc_i)
196
                if (wb_stb_i & wb_we_i) begin
197
//                      $fdisplay(fflash, "%t Trying to write into flash at %h (%b)", $time, wb_adr_i, wb_we_i);
198
//                      #100 $finish;
199
                        if (wb_sel_i[3])
200
                                mem[{wb_adr_i[31:2], 2'b00}+0] = wb_dat_i[31:24];
201
                        if (wb_sel_i[2])
202
                                mem[{wb_adr_i[31:2], 2'b00}+1] = wb_dat_i[23:16];
203
                        if (wb_sel_i[1])
204
                                mem[{wb_adr_i[31:2], 2'b00}+2] = wb_dat_i[15:8];
205
                        if (wb_sel_i[0])
206
                                mem[{wb_adr_i[31:2], 2'b00}+3] = wb_dat_i[7:0];
207
                        $fdisplay(fflash, "%t [%h] <- write %h, byte sel %b", $time, wb_adr_i, wb_dat_i, wb_sel_i);
208
                end else if (wb_ack_o)
209
                        $fdisplay(fflash, "%t [%h] -> read %h", $time, wb_adr_i, wb_dat_o);
210
// synopsys translate_on
211
 
212
endmodule
213
 
214
`else
215
 
216
module flash_top (
217
  wb_clk_i, wb_rst_i,
218
 
219
  wb_dat_i, wb_dat_o, wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i,
220
  wb_stb_i, wb_ack_o, wb_err_o,
221
 
222
  flash_rstn, cen, oen, wen, rdy, d, a, a_oe
223
);
224
 
225
//
226
// I/O Ports
227
//
228
 
229
//
230
// Common WB signals
231
//
232
input                   wb_clk_i;
233
input                   wb_rst_i;
234
 
235
//
236
// WB slave i/f
237
//
238
input   [31:0]           wb_dat_i;
239
output  [31:0]           wb_dat_o;
240
input   [31:0]           wb_adr_i;
241
input   [3:0]            wb_sel_i;
242
input                   wb_we_i;
243
input                   wb_cyc_i;
244
input                   wb_stb_i;
245
output                  wb_ack_o;
246
output                  wb_err_o;
247
 
248
//
249
// Flash i/f
250
//
251
output                  flash_rstn;
252
output                  oen;
253
output                  cen;
254
output                  wen;
255
input                   rdy;
256
inout   [7:0]            d;
257
output  [20:0]           a;
258
output                  a_oe;
259
 
260
//
261
// Internal wires and regs
262
//
263
reg                     ack;
264
reg     [3:0]            middle_tphqv;
265
reg     [31:0]           wb_dat_o;
266
reg     [4:0]            counter;
267
 
268
//
269
// Aliases and simple assignments
270
//
271
assign wb_ack_o = ack;
272
assign wb_err_o = 1'b0;
273
assign flash_rstn = ~wb_rst_i;
274
assign a = { ~wb_adr_i[20], wb_adr_i[19:2], counter[3:2] };     // Lower 1MB is used by FPGA design conf.
275
assign a_oe = (wb_cyc_i &! (|middle_tphqv));
276
assign oen = |middle_tphqv;
277
assign wen = 1'b1;
278
assign cen = ~wb_cyc_i | ~wb_stb_i | (|middle_tphqv) | (counter[1:0] == 2'b00);
279
 
280
//
281
// Flash access time counter
282
//
283
always @(posedge wb_clk_i or posedge wb_rst_i)
284
begin
285
  if (wb_rst_i)
286
    counter <= #1 5'h0;
287
  else
288
  if (!wb_cyc_i | (counter == 5'h10) | (|middle_tphqv))
289
    counter <= #1 5'h0;
290
  else
291
    counter <= #1 counter + 1;
292
end
293
 
294
//
295
// Acknowledge
296
//
297
always @(posedge wb_clk_i or posedge wb_rst_i)
298
begin
299
  if (wb_rst_i)
300
    ack <= #1 1'h0;
301
  else
302
  if (counter == 5'h0f && !(|middle_tphqv))
303
    ack <= #1 1'h1;
304
  else
305
    ack <= #1 1'h0;
306
end
307
 
308
//
309
// Flash i/f monitor
310
//
311
// synopsys translate_off
312
integer fflash;
313
initial fflash = $fopen("flash.log");
314
 
315
always @(posedge wb_clk_i)
316
begin
317
  if (wb_cyc_i & !(|middle_tphqv)) begin
318
    if (wb_stb_i & wb_we_i) begin
319
      $fdisplay(fflash, "%t Trying to write into flash at %h", $time, wb_adr_i);
320
//    #100 $finish;
321
    end
322
    else if (ack)
323
      $fdisplay(fflash, "%t [%h] -> read %h", $time, wb_adr_i, wb_dat_o);
324
  end
325
end
326
// synopsys translate_on
327
 
328
always @(posedge wb_clk_i or posedge wb_rst_i)
329
  if (wb_rst_i)
330
    middle_tphqv <= #1 4'hf;
331
  else if (middle_tphqv)
332
    middle_tphqv <= #1 middle_tphqv - 1;
333
 
334
//
335
// Flash 8-bit data expand into 32-bit WB data
336
//
337
always @(posedge wb_clk_i or posedge wb_rst_i)
338
begin
339
  if (wb_rst_i)
340
    wb_dat_o <= #1 32'h0000_0000;
341
  else
342
  if (counter[1:0] == 2'h3)
343
    begin
344
      case (counter[3:2])
345
        2'h0 : wb_dat_o[31:24] <= #1 d;
346
        2'h1 : wb_dat_o[23:16] <= #1 d;
347
        2'h2 : wb_dat_o[15:8]  <= #1 d;
348
        2'h3 : wb_dat_o[7:0]   <= #1 d;
349
      endcase
350
    end
351
end
352
 
353
endmodule
354
 
355
`endif

powered by: WebSVN 2.1.0

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