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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mp3/] [rtl/] [verilog/] [mem_if/] [flash_top.v] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 266 lampret
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  MP3 demo Flash interface                                    ////
4
////                                                              ////
5
////  This file is part of the MP3 demo application               ////
6
////  http://www.opencores.org/cores/or1k/mp3/                    ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Connects MP3 demo tp Flash found on XSV board.              ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   - nothing really                                           ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Lior Shtram, lior.shtram@flextronicssemi.com          ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2001 Authors                                   ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE.  See the GNU Lesser General Public License for more ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from http://www.opencores.org/lgpl.shtml                     ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
// CVS Revision History
45
//
46
// $Log: not supported by cvs2svn $
47 661 lampret
// Revision 1.3  2002/01/23 07:50:44  lampret
48
// Added wb_err_o to flash and sram i/f for testing the buserr exception.
49
//
50 609 lampret
// Revision 1.2  2002/01/14 06:18:22  lampret
51
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
52
//
53 562 lampret
// Revision 1.1.1.1  2001/11/04 19:00:09  lampret
54
// First import.
55 266 lampret
//
56 562 lampret
//
57 266 lampret
 
58
// synopsys translate_off
59
`include "timescale.v"
60
// synopsys translate_on
61 562 lampret
`include "bench_define.v"
62 266 lampret
 
63 562 lampret
`ifdef FLASH_GENERIC
64
 
65 266 lampret
module flash_top (
66
  clk, rstn,
67
 
68
  wb_dat_i, wb_dat_o, wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i,
69
  wb_stb_i, wb_ack_o, wb_err_o,
70
 
71
  flash_rstn, cen, oen, wen, rdy, d, a, a_oe
72
);
73
 
74
input   clk;
75
input   rstn;
76
 
77
input [31:0]  wb_dat_i;
78
output [31:0] wb_dat_o;
79
input [31:0]  wb_adr_i;
80
input [3:0] wb_sel_i;
81
input   wb_we_i;
82
input   wb_cyc_i;
83
input   wb_stb_i;
84
output    wb_ack_o;
85
output    wb_err_o;
86
 
87
output    flash_rstn;
88
output    oen;
89
output    cen;
90
output    wen;
91
input   rdy;
92
inout [7:0] d;
93
output [20:0] a;
94
output  a_oe;
95
 
96 562 lampret
reg [7:0] mem [65535:0];
97
wire [31:0] adr;
98
`ifdef FLASH_GENERIC_REGISTERED
99
reg             wb_ack_o;
100 609 lampret
reg             wb_err_o;
101 562 lampret
reg     [31:0]   wb_dat_o;
102
`endif
103 609 lampret
wire            wb_err;
104 562 lampret
 
105
assign flash_rstn = 1'b1;
106
assign oen = 1'b1;
107
assign cen = 1'b1;
108
assign wen = 1'b1;
109
assign a = 21'b0;
110
assign a_oe = 1'b1;
111
 
112
initial $readmemh("../src/flash.in", mem, 0);
113
assign adr = {wb_adr_i[31:2], 2'b00};
114
`ifdef FLASH_GENERIC_REGISTERED
115
always @(negedge rstn or posedge clk)
116
        if (!rstn)
117
                wb_dat_o <= #1 32'h0000_0000;
118
        else begin
119
                wb_dat_o[7:0] <= #1 wb_adr_i < 65535 ? mem[adr+3] : 8'h00;
120
                wb_dat_o[15:8] <= #1 wb_adr_i < 65535 ? mem[adr+2] : 8'h00;
121
                wb_dat_o[23:16] <= #1 wb_adr_i < 65535 ? mem[adr+1] : 8'h00;
122
                wb_dat_o[31:24] <= #1 wb_adr_i < 65535 ? mem[adr+0] : 8'h00;
123
        end
124
`else
125
assign wb_dat_o[7:0] = wb_adr_i < 65535 ? mem[adr+3] : 8'h00;
126
assign wb_dat_o[15:8] = wb_adr_i < 65535 ? mem[adr+2] : 8'h00;
127
assign wb_dat_o[23:16] = wb_adr_i < 65535 ? mem[adr+1] : 8'h00;
128
assign wb_dat_o[31:24] = wb_adr_i < 65535 ? mem[adr+0] : 8'h00;
129
`endif
130
 
131
`ifdef FLASH_GENERIC_REGISTERED
132
always @(posedge clk or negedge rstn)
133
        if (!rstn)
134
                wb_ack_o <= #1 1'b0;
135
        else
136
                wb_ack_o <= #1 wb_cyc_i & wb_stb_i & !wb_ack_o;
137
`else
138
assign wb_ack_o = wb_cyc_i & wb_stb_i;
139
`endif
140
 
141 609 lampret
assign wb_err = wb_cyc_i & wb_stb_i & (|wb_adr_i[27:21]);     // If Access to > 2MB (4-bit leading prefix ignored)
142 562 lampret
 
143 609 lampret
`ifdef FLASH_GENERIC_REGISTERED
144
always @(posedge clk or negedge rstn)
145
        if (!rstn)
146
                wb_err_o <= #1 1'b0;
147
        else
148
                wb_err_o <= #1 wb_err & !wb_err_o;
149
`else
150
assign wb_err_o = wb_err;
151
`endif
152
 
153 562 lampret
// synopsys translate_off
154
integer fflash;
155
initial fflash = $fopen("flash.log");
156
always @(posedge clk)
157
        if (wb_cyc_i)
158
                if (wb_stb_i & wb_we_i) begin
159 661 lampret
//                      $fdisplay(fflash, "%t Trying to write into flash at %h (%b)", $time, wb_adr_i, wb_we_i);
160
//                      #100 $finish;
161
                        if (wb_sel_i[3])
162
                                mem[{wb_adr_i[31:2], 2'b00}+0] = wb_dat_i[31:24];
163
                        if (wb_sel_i[2])
164
                                mem[{wb_adr_i[31:2], 2'b00}+1] = wb_dat_i[23:16];
165
                        if (wb_sel_i[1])
166
                                mem[{wb_adr_i[31:2], 2'b00}+2] = wb_dat_i[15:8];
167
                        if (wb_sel_i[0])
168
                                mem[{wb_adr_i[31:2], 2'b00}+3] = wb_dat_i[7:0];
169
                        $fdisplay(fflash, "%t [%h] <- write %h, byte sel %b", $time, wb_adr_i, wb_dat_i, wb_sel_i);
170 562 lampret
                end else if (wb_ack_o)
171
                        $fdisplay(fflash, "%t [%h] -> read %h", $time, wb_adr_i, wb_dat_o);
172
// synopsys translate_on
173
 
174
endmodule
175
 
176
`else
177
 
178
module flash_top (
179
  clk, rstn,
180
 
181
  wb_dat_i, wb_dat_o, wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i,
182
  wb_stb_i, wb_ack_o, wb_err_o,
183
 
184
  flash_rstn, cen, oen, wen, rdy, d, a, a_oe
185
);
186
 
187
input   clk;
188
input   rstn;
189
 
190
input [31:0]  wb_dat_i;
191
output [31:0] wb_dat_o;
192
input [31:0]  wb_adr_i;
193
input [3:0] wb_sel_i;
194
input   wb_we_i;
195
input   wb_cyc_i;
196
input   wb_stb_i;
197
output    wb_ack_o;
198
output    wb_err_o;
199
 
200
output    flash_rstn;
201
output    oen;
202
output    cen;
203
output    wen;
204
input   rdy;
205
inout [7:0] d;
206
output [20:0] a;
207
output  a_oe;
208
 
209 266 lampret
reg [4:0] counter;
210
reg [31:0]  data_sr;
211
reg   f_ack;
212
reg [3:0] middle_tphqv;
213
 
214
always @(posedge clk or negedge rstn)
215
begin
216
  if(!rstn)
217 562 lampret
    counter <= #1 5'h0;
218 266 lampret
  else
219
  if(!wb_cyc_i | (counter == 5'h10) | (|middle_tphqv))
220
    counter <= #1 5'h0;
221
  else
222
    counter <= #1 counter + 1;
223
end
224
 
225
 
226
always @(posedge clk or negedge rstn)
227
begin
228
  if(!rstn)
229 562 lampret
    f_ack <= #1 1'h0;
230 266 lampret
  else
231
  if(counter == 5'h0f && !(|middle_tphqv))
232
    f_ack <= #1 1'h1;
233
  else
234
    f_ack <= #1 1'h0;
235
end
236
 
237
 
238
assign wb_ack_o = f_ack;
239
 
240
assign flash_rstn = rstn;
241
assign a = { ~wb_adr_i[20], wb_adr_i[19:2], counter[3:2] };
242
assign a_oe = (wb_cyc_i &! (|middle_tphqv));
243
assign wb_dat_o = data_sr;
244
assign oen = |middle_tphqv;
245
assign wen = 1'b1;
246
/* SIMON */
247
//assign cen = |middle_tphqv | (counter[1:0] == 2'b01);
248
assign cen = |middle_tphqv | (counter[1:0] == 2'b01) | (counter[4:0] == 5'b0);
249
assign wb_err_o = 1'b0;
250
 
251
 
252
// synopsys translate_off
253
integer fflash;
254
initial fflash = $fopen("flash.log");
255
always @(posedge clk)
256
        if (wb_cyc_i & !(|middle_tphqv)) begin // wb_ack_o should be qualified with wb_stb_i as well however OR1200 doesn't do this currently
257
                if (wb_stb_i & wb_we_i) begin
258
//      $fdisplay(fflash, "%t Trying to write into flash at %h", $time, wb_adr_i);
259
//      #100 $finish;
260
                end else if (wb_ack_o)
261
                        $fdisplay(fflash, "%t [%h] -> read %h", $time, wb_adr_i, wb_dat_o);
262
        end
263
// synopsys translate_on
264
 
265
always @(posedge clk or negedge rstn)
266
        if (!rstn)
267
                middle_tphqv <= #1 4'hf;
268
        else if (middle_tphqv)
269
                middle_tphqv <= #1 middle_tphqv - 1;
270
 
271
always @(posedge clk or negedge rstn)
272
begin
273 562 lampret
  if (!rstn) data_sr <= #1 32'b0;
274 266 lampret
  else
275
  if (counter[1:0] == 2'h3)
276
    begin
277
      case (counter[3:2])
278
        2'h0 : data_sr[31:24] <= #1 d;
279
        2'h1 : data_sr[23:16] <= #1 d;
280
        2'h2 : data_sr[15:8]  <= #1 d;
281
        2'h3 : data_sr[7:0]   <= #1 d;
282 562 lampret
        default : data_sr <= #1 32'bx;
283 266 lampret
      endcase
284
    end
285
end
286
 
287
endmodule
288 562 lampret
 
289
`endif

powered by: WebSVN 2.1.0

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