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 562

Go to most recent revision | 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 562 lampret
// Revision 1.1.1.1  2001/11/04 19:00:09  lampret
48
// First import.
49 266 lampret
//
50 562 lampret
//
51 266 lampret
 
52
// synopsys translate_off
53
`include "timescale.v"
54
// synopsys translate_on
55 562 lampret
`include "bench_define.v"
56 266 lampret
 
57 562 lampret
`ifdef FLASH_GENERIC
58
 
59 266 lampret
module flash_top (
60
  clk, rstn,
61
 
62
  wb_dat_i, wb_dat_o, wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i,
63
  wb_stb_i, wb_ack_o, wb_err_o,
64
 
65
  flash_rstn, cen, oen, wen, rdy, d, a, a_oe
66
);
67
 
68
input   clk;
69
input   rstn;
70
 
71
input [31:0]  wb_dat_i;
72
output [31:0] wb_dat_o;
73
input [31:0]  wb_adr_i;
74
input [3:0] wb_sel_i;
75
input   wb_we_i;
76
input   wb_cyc_i;
77
input   wb_stb_i;
78
output    wb_ack_o;
79
output    wb_err_o;
80
 
81
output    flash_rstn;
82
output    oen;
83
output    cen;
84
output    wen;
85
input   rdy;
86
inout [7:0] d;
87
output [20:0] a;
88
output  a_oe;
89
 
90 562 lampret
reg [7:0] mem [65535:0];
91
wire [31:0] adr;
92
`ifdef FLASH_GENERIC_REGISTERED
93
reg             wb_ack_o;
94
reg     [31:0]   wb_dat_o;
95
`endif
96
 
97
assign flash_rstn = 1'b1;
98
assign oen = 1'b1;
99
assign cen = 1'b1;
100
assign wen = 1'b1;
101
assign a = 21'b0;
102
assign a_oe = 1'b1;
103
 
104
initial $readmemh("../src/flash.in", mem, 0);
105
assign adr = {wb_adr_i[31:2], 2'b00};
106
`ifdef FLASH_GENERIC_REGISTERED
107
always @(negedge rstn or posedge clk)
108
        if (!rstn)
109
                wb_dat_o <= #1 32'h0000_0000;
110
        else begin
111
                wb_dat_o[7:0] <= #1 wb_adr_i < 65535 ? mem[adr+3] : 8'h00;
112
                wb_dat_o[15:8] <= #1 wb_adr_i < 65535 ? mem[adr+2] : 8'h00;
113
                wb_dat_o[23:16] <= #1 wb_adr_i < 65535 ? mem[adr+1] : 8'h00;
114
                wb_dat_o[31:24] <= #1 wb_adr_i < 65535 ? mem[adr+0] : 8'h00;
115
        end
116
`else
117
assign wb_dat_o[7:0] = wb_adr_i < 65535 ? mem[adr+3] : 8'h00;
118
assign wb_dat_o[15:8] = wb_adr_i < 65535 ? mem[adr+2] : 8'h00;
119
assign wb_dat_o[23:16] = wb_adr_i < 65535 ? mem[adr+1] : 8'h00;
120
assign wb_dat_o[31:24] = wb_adr_i < 65535 ? mem[adr+0] : 8'h00;
121
`endif
122
 
123
`ifdef FLASH_GENERIC_REGISTERED
124
always @(posedge clk or negedge rstn)
125
        if (!rstn)
126
                wb_ack_o <= #1 1'b0;
127
        else
128
                wb_ack_o <= #1 wb_cyc_i & wb_stb_i & !wb_ack_o;
129
`else
130
assign wb_ack_o = wb_cyc_i & wb_stb_i;
131
`endif
132
 
133
assign wb_err_o = 1'b0;
134
 
135
// synopsys translate_off
136
integer fflash;
137
initial fflash = $fopen("flash.log");
138
always @(posedge clk)
139
        if (wb_cyc_i)
140
                if (wb_stb_i & wb_we_i) begin
141
                        $fdisplay(fflash, "%t Trying to write into flash at %h (%b)", $time, wb_adr_i, wb_we_i);
142
                        #100 $finish;
143
                end else if (wb_ack_o)
144
                        $fdisplay(fflash, "%t [%h] -> read %h", $time, wb_adr_i, wb_dat_o);
145
// synopsys translate_on
146
 
147
endmodule
148
 
149
`else
150
 
151
module flash_top (
152
  clk, rstn,
153
 
154
  wb_dat_i, wb_dat_o, wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i,
155
  wb_stb_i, wb_ack_o, wb_err_o,
156
 
157
  flash_rstn, cen, oen, wen, rdy, d, a, a_oe
158
);
159
 
160
input   clk;
161
input   rstn;
162
 
163
input [31:0]  wb_dat_i;
164
output [31:0] wb_dat_o;
165
input [31:0]  wb_adr_i;
166
input [3:0] wb_sel_i;
167
input   wb_we_i;
168
input   wb_cyc_i;
169
input   wb_stb_i;
170
output    wb_ack_o;
171
output    wb_err_o;
172
 
173
output    flash_rstn;
174
output    oen;
175
output    cen;
176
output    wen;
177
input   rdy;
178
inout [7:0] d;
179
output [20:0] a;
180
output  a_oe;
181
 
182 266 lampret
reg [4:0] counter;
183
reg [31:0]  data_sr;
184
reg   f_ack;
185
reg [3:0] middle_tphqv;
186
 
187
always @(posedge clk or negedge rstn)
188
begin
189
  if(!rstn)
190 562 lampret
    counter <= #1 5'h0;
191 266 lampret
  else
192
  if(!wb_cyc_i | (counter == 5'h10) | (|middle_tphqv))
193
    counter <= #1 5'h0;
194
  else
195
    counter <= #1 counter + 1;
196
end
197
 
198
 
199
always @(posedge clk or negedge rstn)
200
begin
201
  if(!rstn)
202 562 lampret
    f_ack <= #1 1'h0;
203 266 lampret
  else
204
  if(counter == 5'h0f && !(|middle_tphqv))
205
    f_ack <= #1 1'h1;
206
  else
207
    f_ack <= #1 1'h0;
208
end
209
 
210
 
211
assign wb_ack_o = f_ack;
212
 
213
assign flash_rstn = rstn;
214
assign a = { ~wb_adr_i[20], wb_adr_i[19:2], counter[3:2] };
215
assign a_oe = (wb_cyc_i &! (|middle_tphqv));
216
assign wb_dat_o = data_sr;
217
assign oen = |middle_tphqv;
218
assign wen = 1'b1;
219
/* SIMON */
220
//assign cen = |middle_tphqv | (counter[1:0] == 2'b01);
221
assign cen = |middle_tphqv | (counter[1:0] == 2'b01) | (counter[4:0] == 5'b0);
222
assign wb_err_o = 1'b0;
223
 
224
 
225
// synopsys translate_off
226
integer fflash;
227
initial fflash = $fopen("flash.log");
228
always @(posedge clk)
229
        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
230
                if (wb_stb_i & wb_we_i) begin
231
//      $fdisplay(fflash, "%t Trying to write into flash at %h", $time, wb_adr_i);
232
//      #100 $finish;
233
                end else if (wb_ack_o)
234
                        $fdisplay(fflash, "%t [%h] -> read %h", $time, wb_adr_i, wb_dat_o);
235
        end
236
// synopsys translate_on
237
 
238
always @(posedge clk or negedge rstn)
239
        if (!rstn)
240
                middle_tphqv <= #1 4'hf;
241
        else if (middle_tphqv)
242
                middle_tphqv <= #1 middle_tphqv - 1;
243
 
244
always @(posedge clk or negedge rstn)
245
begin
246 562 lampret
  if (!rstn) data_sr <= #1 32'b0;
247 266 lampret
  else
248
  if (counter[1:0] == 2'h3)
249
    begin
250
      case (counter[3:2])
251
        2'h0 : data_sr[31:24] <= #1 d;
252
        2'h1 : data_sr[23:16] <= #1 d;
253
        2'h2 : data_sr[15:8]  <= #1 d;
254
        2'h3 : data_sr[7:0]   <= #1 d;
255 562 lampret
        default : data_sr <= #1 32'bx;
256 266 lampret
      endcase
257
    end
258
end
259
 
260
endmodule
261 562 lampret
 
262
`endif

powered by: WebSVN 2.1.0

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