VerilogHDL代码_AHB总线_master部分(9页).doc

上传人:1595****071 文档编号:35420333 上传时间:2022-08-21 格式:DOC 页数:9 大小:298.50KB
返回 下载 相关 举报
VerilogHDL代码_AHB总线_master部分(9页).doc_第1页
第1页 / 共9页
VerilogHDL代码_AHB总线_master部分(9页).doc_第2页
第2页 / 共9页
点击查看更多>>
资源描述

《VerilogHDL代码_AHB总线_master部分(9页).doc》由会员分享,可在线阅读,更多相关《VerilogHDL代码_AHB总线_master部分(9页).doc(9页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、-VerilogHDL代码_AHB总线_master部分-第 9 页module ahb_master (HBUSREQ,HLOCK,HTRANS,HADDR,HWRITE,HSIZE,HBURST,HWDATA,HSEL,hcount,HRESETn,HCLK,HGRANT,HREADY,HRESP,HRDATA,BUSREQ,ADDREQ,WRITE,ADDR,SIZE,BURST,SEL,TRANS,WDATA);output HBUSREQ,HLOCK,HWRITE;output 1:0HTRANS,HSEL;output 31:0HADDR,HWDATA;output 2:0HSIZ

2、E,HBURST;input HGRANT,HREADY,HCLK,HRESETn,BUSREQ,ADDREQ,WRITE;input 31:0ADDE,WDATA;input 2:0SIZE,BURST;input 1:0HRESP,SEL,TRANS;input 31:0HRDATA;reg HBUSRREQ,HLOCK,HWRITE,hcount;reg 1:0HTRANS,HSEL;reg 31:0HADDR,HWDATA;reg 2:0HSIZE,HBURST;wire HGRANT,HREADY,HCLK,HRESETn,WRITE;wire 31:0ADDR,WDATA;wire

3、 2:0SIZE,BURST;wire 1:0HRESP,SEL,TRANS;wire 31:0HRDATA;reg bus_reg,adde_reg,new_hready,old_hready;reg 31:0RDATA;reg 31:0h_addr;parameter OKAY=2b00 ERROR=2b01 RETRY=2b10 SPLIT=2b11;always (posedge HCLK)begin if(!HRESETn) begin HBUSREQ=0; HLOCK=0; HWRITE=0; HTRANS=2b00; HSEL=2b00; HADDR=32h000000000;

4、HWDATA=32h000000000; HSIZE=2b00; HBURST=2b00; bus_reg=0; addr_reg=0; new_hready=0; old_hready=0; hcount=0; endend always (posedge HCLK)begin if(HRESETn) begin if(!addr_reg) begin if(ADDREQ) begin HADDR=ADDR; h_addr=ADDR; HWRITE=WRITE; HSIZE=SIZE; HBURST=BURST; HSEL=SEL; HTRANS=TRANS; addr_reg=1b1; H

5、WDATA=32h000000000; end end else if(addr_reg) begin HADDR=32h000000000; HWRITE=1b0; HSIZE=3b000; HBURST=3b000; HTRANS=2b00; addr_reg=1b0; end if(!ADDREQ) begin if(WRITE) begin hcount=0; case(TRANS) 2b00:begin HWDATA=WDATA; if(HREADY & !new_hready & HRESP=ERROR) new_hready=1; else if(new_hready!=old_

6、hready) HWDATA=32h00000000; end 2b01:begin hcount=hcount+1; new_hready=0; HWDATA=WDATA; if(HREADY &!new_hready & HRESP) new_hready=1; else if(new_hready!=old hready) hWDATA=32h00000000; end 2b10:begin HWDATA=32h00000000; end 2b11:begin hcount=hcount+1; HWDATA=WDATA; if(HREADY & HRESP=OKAY) begin if(

7、!new_hready) new_hready=1; end else if(new_hready!=old_hready) begin HWDATA=WDATA; new_hready=0; end else if(HREADY & HRESP=ERROR) begin HWDATA=32h00000000; end end endcaseend else if(!WRITE) begin case(TRANS) 2b00:begin if(!HREADY) RDATA=HRDATA; else if(HREADY) RDATA=32h00000000; end 2b01:begin if(

8、!HREADY) begin RDATA=HRDATA; if(HBURST=000) h_addr=h_addr+1; else h_addr=h_addr-1; end else if(HREADY) RDATA=32h00000000; end 2b10:begin RDATA=32h00000000; end 2b11:begin if(!HREADY) begin RDATA=HRDATA; if(HBURST=000) h_addr=h_addr+1; else h_addr=h_addr-1; end endcase endendendendmodulemodule ram_to

9、p( HCLK , HRESETn , HSEL_s , HADDR_s , HBURST_s , HTRANS_s , HRDATA_s , HWDATA_s , HWRITE_s , HREADY_s , HRESP_sinput HCLK ;input HRESETn ;input HSEL_s ;input 19:0 HADDR_s ;input 2:0 HBURST_s ;input 1:0 HTRANS_s ;input 31:0 HWDATA_s ;input HWRITE_s ;output 1:0 HRESP_s ;output 31:0 HRDATA_s ;output H

10、READY_s ;wire 31:0 ram_RDATA ;wire 17:0 ram_ADDR ;wire 31:0 ram_WDATA ;wire ram_WRITE ;ram_ahbif U_ram_ahbif (.HCLK (HCLK ),.HRESETn (HRESETn ),.HSEL_s (HSEL_s ),.HADDR_s (HADDR_s ),.HBURST_s (HBURST_s ),.HTRANS_s (HTRANS_s ),.HRDATA_s (HRDATA_s ),.HWDATA_s (HWDATA_s ),.HWRITE_s (HWRITE_s ),.HREADY_

11、s (HREADY_s ),.HRESP_s (HRESP_s ),.ram_RDATA (ram_RDATA ),.ram_ADDR (ram_ADDR ),.ram_WDATA (ram_WDATA ),.ram_WRITE (ram_WRITE )ram_infer U_ram_infer(.q (ram_RDATA ),.a (ram_ADDR ),.d (ram_WDATA ),.we (ram_WRITE ),.clk (HCLK )endmodulemodule ram_infer(q ,a ,d ,we ,clkoutput 31:0 q ;input 31:0 d ;inpu

12、t 17:0 a ;input we ;input clk ;reg 31:0 mem 262143:0 ;always (posedge clk) beginif (we) beginmema = d;endendassign q = mema;endmodulemodule ram_ahbif(HCLK ,HRESETn ,HSEL_s ,HADDR_s ,HBURST_s ,HTRANS_s ,HRDATA_s ,HWDATA_s ,HWRITE_s ,HREADY_s ,HRESP_s ,ram_RDATA ,ram_ADDR ,ram_WDATA ,ram_WRITE/declara

13、tion of input & outputinput HCLK ;input HRESETn ;input HSEL_s ;input 19:0 HADDR_s ;input 2:0 HBURST_s ;input 1:0 HTRANS_s ;input 31:0 HWDATA_s ;input HWRITE_s ;output 1:0 HRESP_s ;output 31:0 HRDATA_s ;output HREADY_s ;input 31:0 ram_RDATA ;output 17:0 ram_ADDR ;output 31:0 ram_WDATA ;output ram_WRI

14、TE ;/declaration of registers & wires/wire 1:0 HRESP_s ;wire 31:0 HRDATA_s ;reg HREADY_s ;wire 31:0 ram_WDATA ;reg 17:0 ram_ADDR ;reg ram_WRITE ;wire wr_en ;wire rd_en ;wire ready_en ;/program & functionassign HRESP_s = 2b00;always(posedge HCLK or negedge HRESETn)begin /HSIZE = 3b010-32bitsif(!HRESE

15、Tn) beginram_ADDR = 18b000000000000000000;end else if (HSEL_s = 1b1) beginram_ADDR = HADDR_s19:2;endendassign wr_en = HSEL_s & HTRANS_s1 & HWRITE_s;always(posedge HCLK or negedge HRESETn)beginif(!HRESETn) beginram_WRITE = 1b0;end else if(wr_en) beginram_WRITE = 1b1;end else beginram_WRITE = 1b0;endendassign ram_WDATA= HWDATA_s;assign HRDATA_s = ram_RDATA;assign ready_en = HSEL_s & HTRANS_s1;always(posedge HCLK or negedge HRESETn)beginif(!HRESETn) beginHREADY_s = 1b0;end else if(ready_en) beginHREADY_s = 1b1;end else beginHREADY_s = 1b0;endendendmodule

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 单元课程

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁