1 |
3 |
hharte |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// $Id: wb_flash.v,v 1.1 2008-12-01 02:00:10 hharte Exp $ ////
|
4 |
|
|
//// wb_flash.v - Wishbone FLASH interface for the StrataFLASH ////
|
5 |
|
|
//// on the Xilinx Spartan3E Starter Kit ////
|
6 |
|
|
//// ////
|
7 |
|
|
//// This file is part of the wb_flash Project ////
|
8 |
|
|
//// http://www.opencores.org/projects/wb_flash/ ////
|
9 |
|
|
//// ////
|
10 |
|
|
//// Author: ////
|
11 |
|
|
//// - Howard M. Harte (hharte@opencores.org) ////
|
12 |
|
|
//// ////
|
13 |
|
|
//////////////////////////////////////////////////////////////////////
|
14 |
|
|
//// ////
|
15 |
|
|
//// Copyright (C) 2008 Howard M. Harte ////
|
16 |
|
|
//// ////
|
17 |
|
|
//// This source file may be used and distributed without ////
|
18 |
|
|
//// restriction provided that this copyright statement is not ////
|
19 |
|
|
//// removed from the file and that any derivative work contains ////
|
20 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
21 |
|
|
//// ////
|
22 |
|
|
//// This source file is free software; you can redistribute it ////
|
23 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
24 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
25 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
26 |
|
|
//// later version. ////
|
27 |
|
|
//// ////
|
28 |
|
|
//// This source is distributed in the hope that it will be ////
|
29 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
30 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
31 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
32 |
|
|
//// details. ////
|
33 |
|
|
//// ////
|
34 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
35 |
|
|
//// Public License along with this source; if not, download it ////
|
36 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
37 |
|
|
//// ////
|
38 |
|
|
//////////////////////////////////////////////////////////////////////
|
39 |
|
|
|
40 |
|
|
module wb_flash(
|
41 |
|
|
// Parallel FLASH Interface
|
42 |
|
|
clk_i, nrst_i, wb_adr_i, wb_dat_o, wb_dat_i, wb_sel_i, wb_we_i,
|
43 |
|
|
wb_stb_i, wb_cyc_i, wb_ack_o,
|
44 |
|
|
flash_adr_o, flash_dat_o, flash_dat_i,
|
45 |
|
|
flash_oe, flash_ce, flash_we
|
46 |
|
|
);
|
47 |
|
|
|
48 |
|
|
//
|
49 |
|
|
// Default address and data bus width
|
50 |
|
|
//
|
51 |
|
|
parameter aw = 19; // number of address-bits
|
52 |
|
|
parameter dw = 32; // number of data-bits
|
53 |
|
|
parameter ws = 4'hf; // number of wait-states
|
54 |
|
|
|
55 |
|
|
//
|
56 |
|
|
// FLASH interface
|
57 |
|
|
//
|
58 |
|
|
input clk_i;
|
59 |
|
|
input nrst_i;
|
60 |
|
|
input [aw-1:0] wb_adr_i;
|
61 |
|
|
output [dw-1:0] wb_dat_o;
|
62 |
|
|
input [dw-1:0] wb_dat_i;
|
63 |
|
|
input [3:0] wb_sel_i;
|
64 |
|
|
input wb_we_i;
|
65 |
|
|
input wb_stb_i;
|
66 |
|
|
input wb_cyc_i;
|
67 |
|
|
output reg wb_ack_o;
|
68 |
|
|
output [18:0] flash_adr_o;
|
69 |
|
|
output [7:0] flash_dat_o;
|
70 |
|
|
input [7:0] flash_dat_i;
|
71 |
|
|
output flash_oe;
|
72 |
|
|
output flash_ce;
|
73 |
|
|
output flash_we;
|
74 |
|
|
reg [3:0] waitstate;
|
75 |
|
|
|
76 |
|
|
wire [1:0] adr_low;
|
77 |
|
|
|
78 |
|
|
// Wishbone read/write accesses
|
79 |
|
|
wire wb_acc = wb_cyc_i & wb_stb_i; // WISHBONE access
|
80 |
|
|
wire wb_wr = wb_acc & wb_we_i; // WISHBONE write access
|
81 |
|
|
wire wb_rd = wb_acc & !wb_we_i; // WISHBONE read access
|
82 |
|
|
|
83 |
|
|
always @(posedge clk_i or negedge nrst_i)
|
84 |
|
|
if(~nrst_i)
|
85 |
|
|
begin
|
86 |
|
|
waitstate <= 4'b0;
|
87 |
|
|
wb_ack_o <= 1'b0;
|
88 |
|
|
end
|
89 |
|
|
else begin
|
90 |
|
|
if(waitstate == 4'b0) begin
|
91 |
|
|
wb_ack_o <= 1'b0;
|
92 |
|
|
if(wb_acc) begin
|
93 |
|
|
waitstate <= waitstate + 1;
|
94 |
|
|
end
|
95 |
|
|
end
|
96 |
|
|
else begin
|
97 |
|
|
waitstate <= waitstate + 1;
|
98 |
|
|
if(waitstate == ws)
|
99 |
|
|
wb_ack_o <= 1'b1;
|
100 |
|
|
end
|
101 |
|
|
end
|
102 |
|
|
|
103 |
|
|
assign flash_ce = !wb_acc;
|
104 |
|
|
assign flash_we = !wb_wr;
|
105 |
|
|
assign flash_oe = !wb_rd;
|
106 |
|
|
|
107 |
|
|
assign adr_low = wb_sel_i == 4'b0001 ? 2'b00 : wb_sel_i == 4'b0010 ? 2'b01 : wb_sel_i == 4'b0100 ? 2'b10 : 2'b11;
|
108 |
|
|
assign flash_adr_o = {wb_adr_i[18:2], adr_low};
|
109 |
|
|
assign flash_dat_o = wb_sel_i == 4'b0001 ? wb_dat_i[7:0] : wb_sel_i == 4'b0010 ? wb_dat_i[15:8] : wb_sel_i == 4'b0100 ? wb_dat_i[23:16] : wb_dat_i[31:24];
|
110 |
|
|
assign wb_dat_o = {flash_dat_i, flash_dat_i, flash_dat_i, flash_dat_i};
|
111 |
|
|
|
112 |
|
|
endmodule
|