[6] | 1 | `timescale 1ns / 1ps |
---|
| 2 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 3 | // Company: (C) Athree, 2009 |
---|
| 4 | // Engineer: Dmitry Rozhdestvenskiy |
---|
| 5 | // Email dmitry.rozhdestvenskiy@srisc.com dmitryr@a3.spb.ru divx4log@narod.ru |
---|
| 6 | // |
---|
| 7 | // Design Name: Wishbone NOR flash controller |
---|
| 8 | // Module Name: wbflash |
---|
| 9 | // Project Name: SPARC SoC single-core |
---|
| 10 | // |
---|
| 11 | // LICENSE: |
---|
| 12 | // This is a Free Hardware Design; you can redistribute it and/or |
---|
| 13 | // modify it under the terms of the GNU General Public License |
---|
| 14 | // version 2 as published by the Free Software Foundation. |
---|
| 15 | // The above named program is distributed in the hope that it will |
---|
| 16 | // be useful, but WITHOUT ANY WARRANTY; without even the implied |
---|
| 17 | // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
---|
| 18 | // See the GNU General Public License for more details. |
---|
| 19 | // |
---|
| 20 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 21 | module WBFLASH( |
---|
| 22 | input wb_clk_i, |
---|
| 23 | input wb_rst_i, |
---|
| 24 | |
---|
| 25 | input [63:0] wb_dat_i, |
---|
| 26 | output [63:0] wb_dat_o, |
---|
| 27 | input [63:0] wb_adr_i, |
---|
| 28 | input [ 7:0] wb_sel_i, |
---|
| 29 | input wb_we_i, |
---|
| 30 | input wb_cyc_i, |
---|
| 31 | input wb_stb_i, |
---|
| 32 | output reg wb_ack_o, |
---|
| 33 | output wb_err_o, |
---|
| 34 | output wb_rty_o, |
---|
| 35 | input wb_cab_i, |
---|
| 36 | |
---|
| 37 | input [63:0] wb1_dat_i, |
---|
| 38 | output [63:0] wb1_dat_o, |
---|
| 39 | input [63:0] wb1_adr_i, |
---|
| 40 | input [ 7:0] wb1_sel_i, |
---|
| 41 | input wb1_we_i, |
---|
| 42 | input wb1_cyc_i, |
---|
| 43 | input wb1_stb_i, |
---|
| 44 | output reg wb1_ack_o, |
---|
| 45 | output wb1_err_o, |
---|
| 46 | output wb1_rty_o, |
---|
| 47 | input wb1_cab_i, |
---|
| 48 | |
---|
[8] | 49 | output reg [21:0] flash_addr, |
---|
[6] | 50 | input [15:0] flash_data, |
---|
| 51 | output flash_oen, |
---|
| 52 | output flash_wen, |
---|
[8] | 53 | output flash_cen |
---|
| 54 | //input [ 1:0] flash_rev |
---|
[6] | 55 | //output flash_ldn |
---|
| 56 | ); |
---|
| 57 | |
---|
| 58 | assign wb_err_o=0; |
---|
| 59 | assign wb_rty_o=0; |
---|
[27] | 60 | assign wb1_err_o=0; |
---|
| 61 | assign wb1_rty_o=0; |
---|
[6] | 62 | |
---|
| 63 | reg [1:0] wordcnt; |
---|
| 64 | reg [2:0] cyclecnt; |
---|
| 65 | reg [63:0] wb_dat; |
---|
| 66 | reg [63:0] wb1_dat; |
---|
| 67 | reg [63:0] wb_dat_inv; |
---|
| 68 | reg [63:0] cache_addr; |
---|
| 69 | reg [63:0] cache_addr1; |
---|
| 70 | |
---|
| 71 | always @(posedge wb_clk_i or posedge wb_rst_i) |
---|
| 72 | if(wb_rst_i) |
---|
| 73 | begin |
---|
[27] | 74 | wb_ack_o<=0; |
---|
| 75 | wb1_ack_o<=0; |
---|
[6] | 76 | cache_addr<=64'b0; |
---|
| 77 | cache_addr1<=64'b0; |
---|
| 78 | end |
---|
| 79 | else |
---|
| 80 | if((!wb_cyc_i || !wb_stb_i) && (!wb1_cyc_i || !wb1_stb_i)) |
---|
| 81 | begin |
---|
| 82 | wordcnt<=2'b00; |
---|
| 83 | cyclecnt<=3'b000; |
---|
| 84 | wb_ack_o<=0; |
---|
| 85 | wb1_ack_o<=0; |
---|
| 86 | end |
---|
| 87 | else |
---|
| 88 | if(wb_stb_i) |
---|
| 89 | if(wb_adr_i==cache_addr) |
---|
| 90 | wb_ack_o<=1; |
---|
| 91 | else |
---|
| 92 | if(cyclecnt!=3'b111) |
---|
| 93 | cyclecnt<=cyclecnt+1; |
---|
| 94 | else |
---|
| 95 | begin |
---|
| 96 | cyclecnt<=0; |
---|
| 97 | case(wordcnt) |
---|
| 98 | 2'b00:wb_dat[63:48]<={flash_data[7:0],flash_data[15:8]}; |
---|
| 99 | 2'b01:wb_dat[47:32]<={flash_data[7:0],flash_data[15:8]}; |
---|
| 100 | 2'b10:wb_dat[31:16]<={flash_data[7:0],flash_data[15:8]}; |
---|
| 101 | 2'b11:wb_dat[15: 0]<={flash_data[7:0],flash_data[15:8]}; |
---|
| 102 | endcase |
---|
| 103 | if(wordcnt!=2'b11) |
---|
| 104 | wordcnt<=wordcnt+1; |
---|
| 105 | else |
---|
| 106 | begin |
---|
| 107 | wb_ack_o<=1; |
---|
| 108 | cache_addr<=wb_adr_i; |
---|
| 109 | end |
---|
| 110 | end |
---|
| 111 | else |
---|
| 112 | if(wb1_adr_i==cache_addr1) |
---|
| 113 | wb1_ack_o<=1; |
---|
| 114 | else |
---|
| 115 | if(cyclecnt!=3'b111) |
---|
| 116 | cyclecnt<=cyclecnt+1; |
---|
| 117 | else |
---|
| 118 | begin |
---|
| 119 | cyclecnt<=0; |
---|
| 120 | case(wordcnt) |
---|
| 121 | 2'b00:wb1_dat[63:48]<={flash_data[7:0],flash_data[15:8]}; |
---|
| 122 | 2'b01:wb1_dat[47:32]<={flash_data[7:0],flash_data[15:8]}; |
---|
| 123 | 2'b10:wb1_dat[31:16]<={flash_data[7:0],flash_data[15:8]}; |
---|
| 124 | 2'b11:wb1_dat[15: 0]<={flash_data[7:0],flash_data[15:8]}; |
---|
| 125 | endcase |
---|
| 126 | if(wordcnt!=2'b11) |
---|
| 127 | wordcnt<=wordcnt+1; |
---|
| 128 | else |
---|
| 129 | begin |
---|
| 130 | wb1_ack_o<=1; |
---|
| 131 | cache_addr1<=wb1_adr_i; |
---|
| 132 | end |
---|
| 133 | end |
---|
| 134 | |
---|
| 135 | assign wb_dat_o=wb_dat; |
---|
| 136 | assign wb1_dat_o=wb1_dat; |
---|
| 137 | |
---|
[8] | 138 | //wire [1:0] flash_rev_d; |
---|
[6] | 139 | |
---|
[8] | 140 | //assign flash_rev_d=wb_rst_i ? flash_rev:flash_rev_d; |
---|
[6] | 141 | |
---|
[8] | 142 | /*always @( * ) |
---|
[6] | 143 | case({wb1_stb_i,flash_rev_d}) |
---|
| 144 | 3'b000:flash_addr<={wb_adr_i[25:3],wordcnt}+25'h0000000; |
---|
| 145 | 3'b001:flash_addr<={wb_adr_i[25:3],wordcnt}+25'h0100000; |
---|
| 146 | 3'b010:flash_addr<={wb_adr_i[25:3],wordcnt}+25'h0200000; |
---|
| 147 | 3'b011:flash_addr<={wb_adr_i[25:3],wordcnt}+25'h0300000; |
---|
| 148 | 3'b100:flash_addr<={wb1_adr_i[25:3],wordcnt}+25'h0400000; |
---|
| 149 | 3'b101:flash_addr<={wb1_adr_i[25:3],wordcnt}+25'h0400000; |
---|
| 150 | 3'b110:flash_addr<={wb1_adr_i[25:3],wordcnt}+25'h0400000; |
---|
| 151 | 3'b111:flash_addr<={wb1_adr_i[25:3],wordcnt}+25'h0400000; |
---|
[8] | 152 | endcase*/ |
---|
[6] | 153 | |
---|
[8] | 154 | always @( * ) |
---|
| 155 | if (wb1_stb_i) |
---|
| 156 | flash_addr<={wb_adr_i[25:3],wordcnt}+25'h0400000; |
---|
| 157 | else |
---|
| 158 | flash_addr<={wb_adr_i[25:3],wordcnt}+25'h0000000; |
---|
| 159 | |
---|
[6] | 160 | assign flash_oen=((wb_cyc_i && wb_stb_i) || (wb1_cyc_i && wb1_stb_i) ? 0:1); |
---|
[22] | 161 | assign flash_wen= !wb_we_i; |
---|
[6] | 162 | assign flash_cen=0; |
---|
| 163 | |
---|
| 164 | endmodule |
---|