ledmatrix/sdram_driver_v2.v

149 lines
6.1 KiB
Verilog

module sdram_driver_v2 #
(
parameter COL_WIDTH = 8 ,//2^8 = 256 addresses in each colum
parameter ROW_WIDTH = 12 ,//2^12 = 4096 addresses in each bank
parameter BANK_WIDTH = 2 ,//2^2 = 4 banks in a single chip
parameter DQ_WIDTH = 8 ,//8 bit Data Bus for one chip
parameter [12:0] SDRAM_MR = 13'h0037 ,//Full Page Burst,Latency=3,Burst Read and Burst Write,Standard mode
parameter DDR_PRIMITIVE_TYPE = "VIRTEX5" //FPGA is Virtex-5 serirals
)
(
clk0 ,//The main clock of the control system
clk1 ,//have the same period of clk0, but the phase is shifted
rst_n ,//A low voltage may bring the control system to an oringinal state,and the data in SDRAM may be damaged
user_command_req ,//The user want to send a read/write command,active HIGH
user_command_gnt ,//The state machine have accept the user's read/write command
user_rd0_wr1 ,//HIGH voltage means read and a low means write,synchronous to "user_command_req"
user_burst_length,//Express the read/write lenghth of each command,synchronous to "user_command_req"
user_start_addr ,//the user's read/write address,synchronous to "user_command_req"
Tx_fifo_rd_en ,//used in the user's write command,this port is synchronous to "clk0"
Tx_fifo_rd_data ,//the user write data to the fifo,synchronous to "clk0"
sdram_data_valid,//tell the user that valid read data is coming,active HIGH
sdram_rd_data ,//synchronous to sdram_data_valid
sdram_clk ,//connected to the CLK port of SDRAM
sdram_cke ,//connected to the CKE port of SDRAM
sdram_cs_n ,//connected to the CS_n port of SDRAM
sdram_ras_n ,//connected to the RAS_n port of SDRAM
sdram_cas_n ,//connected to the CAS_n port of SDRAM
sdram_we_n ,//connected to the WE_n port of SDRAM
sdram_ba ,//connected to the BA port of SDRAM
sdram_addr ,//connected to the ADDR port of SDRAM
sdram_dqm ,//connected to the DQM port of SDRAM
sdram_dq //connected to the DQ port of SDRAM
);
input clk0;
input clk1;
input rst_n;
input user_command_req;
output user_command_gnt;
input user_rd0_wr1;
input [COL_WIDTH-1:0] user_burst_length;
input [BANK_WIDTH+ROW_WIDTH+COL_WIDTH-1 : 0] user_start_addr;
output Tx_fifo_rd_en;
input [DQ_WIDTH/8+DQ_WIDTH-1 :0 ] Tx_fifo_rd_data;
output sdram_data_valid;
output [DQ_WIDTH-1 : 0] sdram_rd_data;
output sdram_clk ;
output sdram_cke ;
output sdram_cs_n ;
output sdram_ras_n;
output sdram_cas_n;
output sdram_we_n ;
output [BANK_WIDTH-1 : 0] sdram_ba ;
output [ROW_WIDTH-1 : 0] sdram_addr ;
output [DQ_WIDTH/8-1: 0] sdram_dqm ;
inout [DQ_WIDTH-1 : 0] sdram_dq ;
wire c0_sdram_cke;
wire c0_sdram_cs_n;
wire c0_sdram_ras_n;
wire c0_sdram_cas_n;
wire c0_sdram_we_n;
wire [BANK_WIDTH-1 : 0] c0_sdram_ba;
wire [ROW_WIDTH-1 : 0] c0_sdram_addr;
wire c0_sdram_dq_out_en;
wire [DQ_WIDTH/8-1: 0] c0_sdram_dqm;
wire [DQ_WIDTH-1 : 0] c0_sdram_dq_out;
wire [DQ_WIDTH-1 : 0] c0_sdram_dq_in;
sdram_ctrl #
(
.COL_WIDTH (COL_WIDTH ),
.ROW_WIDTH (ROW_WIDTH ),
.BANK_WIDTH (BANK_WIDTH ),
.DQ_WIDTH (DQ_WIDTH ),
.SDRAM_MR (SDRAM_MR )
)
u_sdram_ctrl(
.clk (clk0 ),//The main clock of the control system
.rst_n(rst_n),//A low voltage may bring the control system to an oringinal state,but the data in SDRAM may be damaged
.user_command_req (user_command_req ),//The user want to send a read/write command,active HIGH
.user_command_gnt (user_command_gnt ),//The state machine have accept the user's read/write command
.user_rd0_wr1 (user_rd0_wr1 ),//HIGH voltage means read and a low means write,synchronous to "user_command_req"
.user_burst_length(user_burst_length),//Express the read/write lenghth of each command,synchronous to "user_command_req"
.user_start_addr (user_start_addr ),//the user's read/write address,synchronous to "user_command_req"
.Tx_fifo_rd_en (Tx_fifo_rd_en ),//used in the user's write command,this port is synchronous to "clk0"
.Tx_fifo_rd_data (Tx_fifo_rd_data ),//the user write data to the fifo,synchronous to "clk0"
.sdram_cke (c0_sdram_cke ),
.sdram_cs_n (c0_sdram_cs_n ),
.sdram_ras_n (c0_sdram_ras_n ),
.sdram_cas_n (c0_sdram_cas_n ),
.sdram_we_n (c0_sdram_we_n ),
.sdram_ba (c0_sdram_ba ),
.sdram_addr (c0_sdram_addr ),
.sdram_dq_out_en(c0_sdram_dq_out_en),
.sdram_dqm (c0_sdram_dqm ),
.sdram_dq_out (c0_sdram_dq_out ),
.sdram_dq_in (c0_sdram_dq_in ),
.sdram_data_valid(sdram_data_valid),//tell the user that valid read data is coming,active HIGH
.sdram_rd_data (sdram_rd_data ) //synchronous to sdram_data_valid
);
sdram_io #
(
.ROW_WIDTH (ROW_WIDTH ),
.BANK_WIDTH (BANK_WIDTH ),
.DQ_WIDTH (DQ_WIDTH ),
.DDR_PRIMITIVE_TYPE(DDR_PRIMITIVE_TYPE)
)
u_sdram_io
(
.clk0(clk0),
.clk1(clk1),
.c0_sdram_cke (c0_sdram_cke ),
.c0_sdram_cs_n (c0_sdram_cs_n ),
.c0_sdram_ras_n (c0_sdram_ras_n ),
.c0_sdram_cas_n (c0_sdram_cas_n ),
.c0_sdram_we_n (c0_sdram_we_n ),
.c0_sdram_ba (c0_sdram_ba ),
.c0_sdram_addr (c0_sdram_addr ),
.c0_sdram_dq_out_en(c0_sdram_dq_out_en),
.c0_sdram_dqm (c0_sdram_dqm ),
.c0_sdram_dq_out (c0_sdram_dq_out ),
.c0_sdram_dq_in (c0_sdram_dq_in ),
.c1_sdram_clk (sdram_clk ),
.c1_sdram_cke (sdram_cke ),
.c1_sdram_cs_n (sdram_cs_n ),
.c1_sdram_ras_n (sdram_ras_n),
.c1_sdram_cas_n (sdram_cas_n),
.c1_sdram_we_n (sdram_we_n ),
.c1_sdram_ba (sdram_ba ),
.c1_sdram_addr (sdram_addr ),
.c1_sdram_dqm (sdram_dqm ),
.c1_sdram_dq (sdram_dq )
);
endmodule