| 1 |
31 |
dinesha |
/*********************************************************************
|
| 2 |
|
|
|
| 3 |
|
|
This file is part of the sdram controller project
|
| 4 |
|
|
http://www.opencores.org/cores/sdr_ctrl/
|
| 5 |
|
|
|
| 6 |
|
|
Description: WISHBONE to SDRAM Controller Bus Transalator
|
| 7 |
|
|
This module translate the WISHBONE protocol to custom sdram controller i/f
|
| 8 |
|
|
|
| 9 |
|
|
To Do:
|
| 10 |
|
|
nothing
|
| 11 |
|
|
|
| 12 |
|
|
Author(s): Dinesh Annayya, dinesha@opencores.org
|
| 13 |
|
|
|
| 14 |
|
|
Copyright (C) 2000 Authors and OPENCORES.ORG
|
| 15 |
|
|
|
| 16 |
|
|
This source file may be used and distributed without
|
| 17 |
|
|
restriction provided that this copyright statement is not
|
| 18 |
|
|
removed from the file and that any derivative work contains
|
| 19 |
|
|
the original copyright notice and the associated disclaimer.
|
| 20 |
|
|
|
| 21 |
|
|
This source file is free software; you can redistribute it
|
| 22 |
|
|
and/or modify it under the terms of the GNU Lesser General
|
| 23 |
|
|
Public License as published by the Free Software Foundation;
|
| 24 |
|
|
either version 2.1 of the License, or (at your option) any
|
| 25 |
|
|
later version.
|
| 26 |
|
|
|
| 27 |
|
|
This source is distributed in the hope that it will be
|
| 28 |
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied
|
| 29 |
|
|
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
| 30 |
|
|
PURPOSE. See the GNU Lesser General Public License for more
|
| 31 |
|
|
details.
|
| 32 |
|
|
|
| 33 |
|
|
You should have received a copy of the GNU Lesser General
|
| 34 |
|
|
Public License along with this source; if not, download it
|
| 35 |
|
|
from http://www.opencores.org/lgpl.shtml
|
| 36 |
|
|
|
| 37 |
|
|
*******************************************************************/
|
| 38 |
|
|
|
| 39 |
|
|
|
| 40 |
|
|
module wb2sdrc (
|
| 41 |
|
|
// WB bus
|
| 42 |
|
|
wb_rst_i ,
|
| 43 |
|
|
wb_clk_i ,
|
| 44 |
|
|
|
| 45 |
|
|
wb_stb_i ,
|
| 46 |
|
|
wb_ack_o ,
|
| 47 |
|
|
wb_addr_i ,
|
| 48 |
|
|
wb_we_i ,
|
| 49 |
|
|
wb_dat_i ,
|
| 50 |
|
|
wb_sel_i ,
|
| 51 |
|
|
wb_dat_o ,
|
| 52 |
|
|
wb_cyc_i ,
|
| 53 |
|
|
wb_cti_i ,
|
| 54 |
|
|
|
| 55 |
|
|
|
| 56 |
|
|
//SDRAM Controller Hand-Shake Signal
|
| 57 |
|
|
sdram_clk ,
|
| 58 |
|
|
sdram_resetn ,
|
| 59 |
|
|
sdr_req ,
|
| 60 |
|
|
sdr_req_addr ,
|
| 61 |
|
|
sdr_req_len ,
|
| 62 |
|
|
sdr_req_wr_n ,
|
| 63 |
|
|
sdr_req_ack ,
|
| 64 |
|
|
sdr_busy_n ,
|
| 65 |
|
|
sdr_wr_en_n ,
|
| 66 |
|
|
sdr_wr_next ,
|
| 67 |
|
|
sdr_rd_valid ,
|
| 68 |
|
|
sdr_last_rd ,
|
| 69 |
|
|
sdr_wr_data ,
|
| 70 |
|
|
sdr_rd_data
|
| 71 |
|
|
|
| 72 |
|
|
);
|
| 73 |
|
|
|
| 74 |
|
|
parameter dw = 32; // data width
|
| 75 |
|
|
parameter tw = 8; // tag id width
|
| 76 |
|
|
parameter bl = 9; // burst_lenght_width
|
| 77 |
|
|
//--------------------------------------
|
| 78 |
|
|
// Wish Bone Interface
|
| 79 |
|
|
// -------------------------------------
|
| 80 |
|
|
input wb_rst_i ;
|
| 81 |
|
|
input wb_clk_i ;
|
| 82 |
|
|
|
| 83 |
|
|
input wb_stb_i ;
|
| 84 |
|
|
output wb_ack_o ;
|
| 85 |
|
|
input [29:0] wb_addr_i ;
|
| 86 |
|
|
input wb_we_i ; // 1 - Write, 0 - Read
|
| 87 |
|
|
input [dw-1:0] wb_dat_i ;
|
| 88 |
|
|
input [dw/8-1:0]wb_sel_i ; // Byte enable
|
| 89 |
|
|
output [dw-1:0] wb_dat_o ;
|
| 90 |
|
|
input wb_cyc_i ;
|
| 91 |
|
|
input [2:0] wb_cti_i ;
|
| 92 |
|
|
/***************************************************
|
| 93 |
|
|
The Cycle Type Idenfier [CTI_IO()] Address Tag provides
|
| 94 |
|
|
additional information about the current cycle.
|
| 95 |
|
|
The MASTER sends this information to the SLAVE. The SLAVE can use this
|
| 96 |
|
|
information to prepare the response for the next cycle.
|
| 97 |
|
|
Table 4-2 Cycle Type Identifiers
|
| 98 |
|
|
CTI_O(2:0) Description
|
| 99 |
|
|
‘000’ Classic cycle.
|
| 100 |
|
|
‘001’ Constant address burst cycle
|
| 101 |
|
|
‘010’ Incrementing burst cycle
|
| 102 |
|
|
‘011’ Reserved
|
| 103 |
|
|
‘100’ Reserved
|
| 104 |
|
|
‘101 Reserved
|
| 105 |
|
|
‘110’ Reserved
|
| 106 |
|
|
‘111’ End-of-Burst
|
| 107 |
|
|
****************************************************/
|
| 108 |
|
|
//--------------------------------------------
|
| 109 |
|
|
// SDRAM controller Interface
|
| 110 |
|
|
//--------------------------------------------
|
| 111 |
|
|
input sdram_clk ; // sdram clock
|
| 112 |
|
|
input sdram_resetn ; // sdram reset
|
| 113 |
|
|
output sdr_req ; // SDRAM request
|
| 114 |
|
|
output [29:0] sdr_req_addr ; // SDRAM Request Address
|
| 115 |
|
|
output [bl-1:0] sdr_req_len ;
|
| 116 |
|
|
output sdr_req_wr_n ; // 0 - Write, 1 -> Read
|
| 117 |
|
|
input sdr_req_ack ; // SDRAM request Accepted
|
| 118 |
|
|
input sdr_busy_n ; // 0 -> sdr busy
|
| 119 |
|
|
output [dw/8-1:0] sdr_wr_en_n ; // Active low sdr byte-wise write data valid
|
| 120 |
|
|
input sdr_wr_next ; // Ready to accept the next write
|
| 121 |
|
|
input sdr_rd_valid ; // sdr read valid
|
| 122 |
|
|
input sdr_last_rd ; // Indicate last Read of Burst Transfer
|
| 123 |
|
|
output [dw-1:0] sdr_wr_data ; // sdr write data
|
| 124 |
|
|
input [dw-1:0] sdr_rd_data ; // sdr read data
|
| 125 |
|
|
|
| 126 |
|
|
//----------------------------------------------------
|
| 127 |
|
|
// Wire Decleration
|
| 128 |
|
|
// ---------------------------------------------------
|
| 129 |
|
|
wire cmdfifo_full;
|
| 130 |
|
|
wire cmdfifo_empty;
|
| 131 |
|
|
wire wrdatafifo_full;
|
| 132 |
|
|
wire wrdatafifo_empty;
|
| 133 |
|
|
wire tagfifo_full;
|
| 134 |
|
|
wire tagfifo_empty;
|
| 135 |
|
|
wire rddatafifo_empty;
|
| 136 |
|
|
wire rddatafifo_full;
|
| 137 |
|
|
|
| 138 |
|
|
reg pending_read;
|
| 139 |
|
|
|
| 140 |
|
|
|
| 141 |
|
|
// Generate Address Enable only when internal fifo (Address + data are not full
|
| 142 |
|
|
|
| 143 |
|
|
assign wb_ack_o = (wb_stb_i && wb_cyc_i && wb_we_i) ? // Write Phase
|
| 144 |
|
|
((!cmdfifo_full) && (!wrdatafifo_full)) :
|
| 145 |
|
|
(wb_stb_i && wb_cyc_i && !wb_we_i) ? // Read Phase
|
| 146 |
|
|
!rddatafifo_empty : 1'b0;
|
| 147 |
|
|
|
| 148 |
|
|
// Accept the cmdfifo only when burst start + address enable + address
|
| 149 |
|
|
// valid is asserted
|
| 150 |
|
|
wire cmdfifo_wr = (wb_stb_i && wb_cyc_i && wb_we_i) ? wb_ack_o :
|
| 151 |
|
|
(wb_stb_i && wb_cyc_i && !wb_we_i) ? !pending_read: 1'b0 ;
|
| 152 |
|
|
wire cmdfifo_rd = sdr_req_ack;
|
| 153 |
|
|
assign sdr_req = !cmdfifo_empty;
|
| 154 |
|
|
|
| 155 |
|
|
wire [bl-1:0] burst_length = 1; // 0 Mean 1 Transfer
|
| 156 |
|
|
|
| 157 |
|
|
always @(posedge wb_rst_i or posedge wb_clk_i) begin
|
| 158 |
|
|
if(wb_rst_i) begin
|
| 159 |
|
|
pending_read <= 1'b0;
|
| 160 |
|
|
end else begin
|
| 161 |
|
|
pending_read <= wb_stb_i & wb_cyc_i & !wb_we_i & !wb_ack_o;
|
| 162 |
|
|
end
|
| 163 |
|
|
end
|
| 164 |
|
|
|
| 165 |
|
|
// Address + Burst Length + W/R Request
|
| 166 |
|
|
async_fifo #(.W(30+bl+1),.DP(4)) u_cmdfifo (
|
| 167 |
|
|
// Write Path Sys CLock Domain
|
| 168 |
|
|
.wr_clk (wb_clk_i),
|
| 169 |
|
|
.wr_reset_n (!wb_rst_i),
|
| 170 |
|
|
.wr_en (cmdfifo_wr),
|
| 171 |
|
|
.wr_data ({burst_length,
|
| 172 |
|
|
!wb_we_i,
|
| 173 |
|
|
wb_addr_i}),
|
| 174 |
|
|
.afull (),
|
| 175 |
|
|
.full (cmdfifo_full),
|
| 176 |
|
|
|
| 177 |
|
|
// Read Path, SDRAM clock domain
|
| 178 |
|
|
.rd_clk (sdram_clk),
|
| 179 |
|
|
.rd_reset_n (sdram_resetn),
|
| 180 |
|
|
.aempty (),
|
| 181 |
|
|
.empty (cmdfifo_empty),
|
| 182 |
|
|
.rd_en (cmdfifo_rd),
|
| 183 |
|
|
.rd_data ({sdr_req_len,
|
| 184 |
|
|
sdr_req_wr_n,
|
| 185 |
|
|
sdr_req_addr})
|
| 186 |
|
|
);
|
| 187 |
|
|
|
| 188 |
|
|
// synopsys translate_off
|
| 189 |
|
|
always @(posedge wb_clk_i) begin
|
| 190 |
|
|
if (cmdfifo_full == 1'b1 && cmdfifo_wr == 1'b1) begin
|
| 191 |
|
|
$display("ERROR:%m COMMAND FIFO WRITE OVERFLOW");
|
| 192 |
|
|
end
|
| 193 |
|
|
end
|
| 194 |
|
|
// synopsys translate_off
|
| 195 |
|
|
always @(posedge sdram_clk) begin
|
| 196 |
|
|
if (cmdfifo_empty == 1'b1 && cmdfifo_rd == 1'b1) begin
|
| 197 |
|
|
$display("ERROR:%m COMMAND FIFO READ OVERFLOW");
|
| 198 |
|
|
end
|
| 199 |
|
|
end
|
| 200 |
|
|
// synopsys translate_on
|
| 201 |
|
|
|
| 202 |
|
|
|
| 203 |
|
|
wire wrdatafifo_wr = wb_ack_o & wb_we_i ;
|
| 204 |
|
|
wire wrdatafifo_rd = sdr_wr_next;
|
| 205 |
|
|
|
| 206 |
|
|
|
| 207 |
|
|
// Write DATA + Data Mask FIFO
|
| 208 |
|
|
async_fifo #(.W(dw+(dw/8)), .DP(16)) u_wrdatafifo (
|
| 209 |
|
|
// Write Path , System clock domain
|
| 210 |
|
|
.wr_clk (wb_clk_i),
|
| 211 |
|
|
.wr_reset_n (!wb_rst_i),
|
| 212 |
|
|
.wr_en (wrdatafifo_wr),
|
| 213 |
|
|
.wr_data ({~wb_sel_i,
|
| 214 |
|
|
wb_dat_i}),
|
| 215 |
|
|
.afull (),
|
| 216 |
|
|
.full (wrdatafifo_full),
|
| 217 |
|
|
|
| 218 |
|
|
|
| 219 |
|
|
// Read Path , SDRAM clock domain
|
| 220 |
|
|
.rd_clk (sdram_clk),
|
| 221 |
|
|
.rd_reset_n (sdram_resetn),
|
| 222 |
|
|
.aempty (),
|
| 223 |
|
|
.empty (wrdatafifo_empty),
|
| 224 |
|
|
.rd_en (wrdatafifo_rd),
|
| 225 |
|
|
.rd_data ({sdr_wr_en_n,
|
| 226 |
|
|
sdr_wr_data})
|
| 227 |
|
|
);
|
| 228 |
|
|
// synopsys translate_off
|
| 229 |
|
|
always @(posedge wb_clk_i) begin
|
| 230 |
|
|
if (wrdatafifo_full == 1'b1 && wrdatafifo_wr == 1'b1) begin
|
| 231 |
|
|
$display("ERROR:%m WRITE DATA FIFO WRITE OVERFLOW");
|
| 232 |
|
|
end
|
| 233 |
|
|
end
|
| 234 |
|
|
|
| 235 |
|
|
always @(posedge sdram_clk) begin
|
| 236 |
|
|
if (wrdatafifo_empty == 1'b1 && wrdatafifo_rd == 1'b1) begin
|
| 237 |
|
|
$display("ERROR:%m WRITE DATA FIFO READ OVERFLOW");
|
| 238 |
|
|
end
|
| 239 |
|
|
end
|
| 240 |
|
|
// synopsys translate_on
|
| 241 |
|
|
|
| 242 |
|
|
// -------------------------------------------------------------------
|
| 243 |
|
|
// READ DATA FIFO
|
| 244 |
|
|
// ------------------------------------------------------------------
|
| 245 |
|
|
wire rd_eop; // last read indication
|
| 246 |
|
|
wire rddatafifo_wr = sdr_rd_valid;
|
| 247 |
|
|
wire rddatafifo_rd = wb_ack_o & !wb_we_i & (rddatafifo_empty == 0);
|
| 248 |
|
|
|
| 249 |
|
|
// READ DATA FIFO depth is kept small, assuming that Sys-CLock > SDRAM Clock
|
| 250 |
|
|
// READ DATA + EOP
|
| 251 |
|
|
async_fifo #(.W(dw+1), .DP(4)) u_rddatafifo (
|
| 252 |
|
|
// Write Path , SDRAM clock domain
|
| 253 |
|
|
.wr_clk (sdram_clk),
|
| 254 |
|
|
.wr_reset_n (sdram_resetn),
|
| 255 |
|
|
.wr_en (rddatafifo_wr),
|
| 256 |
|
|
.wr_data ({sdr_last_rd,
|
| 257 |
|
|
sdr_rd_data}),
|
| 258 |
|
|
.afull (),
|
| 259 |
|
|
.full (rddatafifo_full),
|
| 260 |
|
|
|
| 261 |
|
|
|
| 262 |
|
|
// Read Path , SYS clock domain
|
| 263 |
|
|
.rd_clk (wb_clk_i),
|
| 264 |
|
|
.rd_reset_n (!wb_rst_i),
|
| 265 |
|
|
.empty (rddatafifo_empty),
|
| 266 |
|
|
.aempty (),
|
| 267 |
|
|
.rd_en (rddatafifo_rd),
|
| 268 |
|
|
.rd_data ({rd_eop,
|
| 269 |
|
|
wb_dat_o})
|
| 270 |
|
|
);
|
| 271 |
|
|
|
| 272 |
|
|
// synopsys translate_off
|
| 273 |
|
|
always @(posedge sdram_clk) begin
|
| 274 |
|
|
if (rddatafifo_full == 1'b1 && rddatafifo_wr == 1'b1) begin
|
| 275 |
|
|
$display("ERROR:%m READ DATA FIFO WRITE OVERFLOW");
|
| 276 |
|
|
end
|
| 277 |
|
|
end
|
| 278 |
|
|
|
| 279 |
|
|
always @(posedge wb_clk_i) begin
|
| 280 |
|
|
if (rddatafifo_empty == 1'b1 && rddatafifo_rd == 1'b1) begin
|
| 281 |
|
|
$display("ERROR:%m READ DATA FIFO READ OVERFLOW");
|
| 282 |
|
|
end
|
| 283 |
|
|
end
|
| 284 |
|
|
// synopsys translate_on
|
| 285 |
|
|
|
| 286 |
|
|
|
| 287 |
|
|
endmodule
|