2022年SDRAM程序代码 .pdf
《2022年SDRAM程序代码 .pdf》由会员分享,可在线阅读,更多相关《2022年SDRAM程序代码 .pdf(21页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、module sdram_input_efifo_module ( / inputs: clk, rd, reset_n, wr, wr_data, / outputs: almost_empty, almost_full, empty, full, rd_data ) ; output almost_empty; output almost_full; output empty; output full; output 43: 0 rd_data; input clk; input rd; input reset_n; input wr; input 43: 0 wr_data; wire
2、almost_empty; wire almost_full; wire empty; reg 1: 0 entries; reg 43: 0 entry_0; reg 43: 0 entry_1; wire full; reg rd_address; reg 43: 0 rd_data; wire 1: 0 rdwr; reg wr_address; assign rdwr = rd, wr; assign full = entries = 2; assign almost_full = entries = 1; assign empty = entries = 0; 名师资料总结 - -
3、-精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 21 页 - - - - - - - - - assign almost_empty = entries = 1; always (entry_0 or entry_1 or rd_address) begin case (rd_address) / synthesis parallel_case full_case 1d0: begin rd_data = entry_0; end / 1d0 1d1: begin rd_data = entr
4、y_1; end / 1d1 default: begin end / default endcase / rd_address end always (posedge clk or negedge reset_n) begin if (reset_n = 0) begin wr_address = 0; rd_address = 0; entries = 0; end else case (rdwr) / synthesis parallel_case full_case 2d1: begin / Write data if (!full) begin entries = entries +
5、 1; wr_address = (wr_address = 1) ? 0 : (wr_address + 1); end end / 2d1 2d2: begin / Read data if (!empty) begin entries = entries - 1; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 21 页 - - - - - - - - - rd_address = (rd_address = 1) ? 0 : (rd_address + 1); e
6、nd end / 2d2 2d3: begin wr_address = (wr_address = 1) ? 0 : (wr_address + 1); rd_address = (rd_address = 1) ? 0 : (rd_address + 1); end / 2d3 default: begin end / default endcase / rdwr end always (posedge clk) begin /Write data if (wr & !full) case (wr_address) / synthesis parallel_case full_case 1
7、d0: begin entry_0 = wr_data; end / 1d0 1d1: begin entry_1 = wr_data; end / 1d1 default: begin end / default endcase / wr_address end endmodule module sdram ( / inputs: az_addr, az_be_n, az_cs, az_data, az_rd_n, 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 21
8、页 - - - - - - - - - az_wr_n, clk, reset_n, / outputs: za_data, za_valid, za_waitrequest, zs_addr, zs_ba, zs_cas_n, zs_cke, zs_cs_n, zs_dq, zs_dqm, zs_ras_n, zs_we_n ) ; output 15: 0 za_data; output za_valid; output za_waitrequest; output 12: 0 zs_addr; output 1: 0 zs_ba; output zs_cas_n; output zs_c
9、ke; output 1: 0 zs_cs_n; inout 15: 0 zs_dq; output 1: 0 zs_dqm; output zs_ras_n; output zs_we_n; input 24: 0 az_addr; input 1: 0 az_be_n; input az_cs; input 15: 0 az_data; input az_rd_n; input az_wr_n; input clk; input reset_n; wire 23: 0 CODE; reg ack_refresh_request; reg 23: 0 active_addr; wire 1:
10、 0 active_bank; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 21 页 - - - - - - - - - reg active_cs_n; reg 15: 0 active_data; reg 1: 0 active_dqm; reg active_rnw; wire almost_empty; wire almost_full; wire bank_match; wire 8: 0 cas_addr; wire clk_en; wire 4: 0 c
11、md_all; wire 2: 0 cmd_code; wire cs_n; wire 1: 0 csn_decode; wire csn_match; wire 23: 0 f_addr; wire 1: 0 f_bank; wire f_cs_n; wire 15: 0 f_data; wire 1: 0 f_dqm; wire f_empty; reg f_pop; wire f_rnw; wire f_select; wire 43: 0 fifo_read_data; reg 12: 0 i_addr; reg 4: 0 i_cmd; reg 2: 0 i_count; reg 2:
12、 0 i_next; reg 2: 0 i_refs; reg 2: 0 i_state; reg init_done; reg 12: 0 m_addr; reg 1: 0 m_bank; reg 4: 0 m_cmd; reg 2: 0 m_count; reg 15: 0 m_data; reg 1: 0 m_dqm; reg 8: 0 m_next; reg 8: 0 m_state; reg oe; wire pending; wire rd_strobe; reg 2: 0 rd_valid; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - -
13、 - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 21 页 - - - - - - - - - reg 12: 0 refresh_counter; reg refresh_request; wire rnw_match; wire row_match; wire 23: 0 txt_code; reg za_cannotrefresh; reg 15: 0 za_data; reg za_valid; wire za_waitrequest; wire 12: 0 zs_addr; wire 1: 0 zs_ba; wire zs_cas_n; wire z
14、s_cke; wire 1: 0 zs_cs_n; wire 15: 0 zs_dq; wire 1: 0 zs_dqm; wire zs_ras_n; wire zs_we_n; assign clk_en = 1; /s1, which is an e_avalon_slave assign zs_cs_n, zs_ras_n, zs_cas_n, zs_we_n = m_cmd; assign zs_addr = m_addr; assign zs_cke = clk_en; assign zs_dq = oe?m_data:161bz; assign zs_dqm = m_dqm; a
15、ssign zs_ba = m_bank; assign f_select = f_pop & pending; assign f_rnw, f_cs_n, f_addr, f_dqm, f_data = fifo_read_data; assign cs_n = f_select ? f_cs_n : active_cs_n; assign csn_decode0 = cs_n != 1h0; assign csn_decode1 = cs_n != 1h1; sdram_input_efifo_module the_sdram_input_efifo_module ( .almost_em
16、pty (almost_empty), .almost_full (almost_full), .clk (clk), .empty (f_empty), .full (za_waitrequest), .rd (f_select), .rd_data (fifo_read_data), .reset_n (reset_n), .wr (az_wr_n | az_rd_n) & !za_waitrequest), .wr_data (az_wr_n, az_addr, az_wr_n ? 2b0 : az_be_n, az_data) 名师资料总结 - - -精品资料欢迎下载 - - - -
17、- - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 21 页 - - - - - - - - - ); assign f_bank = f_addr23,f_addr9; / Refresh/init counter. always (posedge clk or negedge reset_n) begin if (reset_n = 0) refresh_counter = 7500; else if (refresh_counter = 0) refresh_counter = 1171; else refresh_count
18、er = refresh_counter - 1b1; end / Refresh request signal. always (posedge clk or negedge reset_n) begin if (reset_n = 0) refresh_request = 0; else if (1) refresh_request = (refresh_counter = 0) | refresh_request) & ack_refresh_request & init_done; end / Generate an Interrupt if two ref_reqs occur be
19、fore one ack_refresh_request always (posedge clk or negedge reset_n) begin if (reset_n = 0) za_cannotrefresh = 0; else if (1) za_cannotrefresh = (refresh_counter = 0) & refresh_request; end / Initialization-done flag. always (posedge clk or negedge reset_n) begin if (reset_n = 0) init_done = 0; else
20、 if (1) init_done = init_done | (i_state = 3b101); end / * Init FSM * 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 21 页 - - - - - - - - - always (posedge clk or negedge reset_n) begin if (reset_n = 0) begin i_state = 3b000; i_next = 3b000; i_cmd = 5b11111; i_
21、addr = 131b1; i_count = 31b0; end else begin i_addr = 131b1; case (i_state) / synthesis parallel_case full_case 3b000: begin i_cmd = 5b11111; i_refs = 3b0; /Wait for refresh count-down after reset if (refresh_counter = 0) i_state = 3b001; end / 3b000 3b001: begin i_state = 3b011; i_cmd = 21b0,3h2; i
22、_count = 1; i_next = 3b010; end / 3b001 3b010: begin i_cmd = 21b0,3h1; i_refs = i_refs + 1b1; i_state = 3b011; i_count = 5; / Count up init_refresh_commands if (i_refs = 3h1) i_next = 3b111; else i_next = 3b010; end / 3b010 3b011: begin i_cmd 1) i_count = i_count - 1b1; else i_state = i_next; end /
23、3b011 3b101: begin i_state = 3b101; end / 3b101 3b111: begin i_state = 3b011; i_cmd = 21b0,3h0; i_addr = 31b0,1b0,2b00,3h3,4h0; i_count = 4; i_next = 3b101; end / 3b111 default: begin i_state = 3b000; end / default endcase / i_state endcase / i_state end end assign active_bank = active_addr23,active
24、_addr9; assign csn_match = active_cs_n = f_cs_n; assign rnw_match = active_rnw = f_rnw; assign bank_match = active_bank = f_bank; assign row_match = active_addr22 : 10 = f_addr22 : 10; assign pending = csn_match & rnw_match & bank_match & row_match & !f_empty; assign cas_addr = f_select ? 41b0,f_add
25、r8 : 0 : 41b0,active_addr8 : 0 ; / * Main FSM * always (posedge clk or negedge reset_n) begin if (reset_n = 0) begin m_state = 9b000000001; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 21 页 - - - - - - - - - m_next = 9b000000001; m_cmd = 5b11111; m_bank = 2b0
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年SDRAM程序代码 2022 SDRAM 程序代码
限制150内