|
发表于 2013-8-8 18:00:24
|
显示全部楼层
或者换个思路,为啥一定要定义这么复杂的数组呢,直接例化小块的SRAM也可以啊,使用generate生成,代码风格也很简洁。
我发段代码,也是双口RAM的。
-
- ram_2p_inst u_ram_2p_inst0
- (
- .clka (aclk ),
- .clkb (aclk ),
- .addra (ram_waddr ),
- .addrb (ram_raddr ),
- .dina (ram_wdata[31:0] ),
- .doutb (ram_rdata[31:0] ),
- .ena (1'b1 ),
- .enb (1'b1 ),
- .wea (|ram_we[3:0] )
- );
- ram_2p_inst u_ram_2p_inst1
- (
- .clka (aclk ),
- .clkb (aclk ),
- .addra (ram_waddr ),
- .addrb (ram_raddr ),
- .dina (ram_wdata[63:32] ),
- .doutb (ram_rdata[63:32] ),
- .ena (1'b1 ),
- .enb (1'b1 ),
- .wea (|ram_we[7:4] )
- );
- ram_2p_inst u_ram_2p_inst2
- (
- .clka (aclk ),
- .clkb (aclk ),
- .addra (ram_waddr ),
- .addrb (ram_raddr ),
- .dina (ram_wdata[95:64] ),
- .doutb (ram_rdata[95:64] ),
- .ena (1'b1 ),
- .enb (1'b1 ),
- .wea (|ram_we[11:8] )
- );
- ram_2p_inst u_ram_2p_inst3
- (
- .clka (aclk ),
- .clkb (aclk ),
- .addra (ram_waddr ),
- .addrb (ram_raddr ),
- .dina (ram_wdata[127:96] ),
- .doutb (ram_rdata[127:96] ),
- .ena (1'b1 ),
- .enb (1'b1 ),
- .wea (|ram_we[15:12] )
- );
- module ram_2p_inst
- #(
- parameter WD = 32, // Width of ram
- parameter PW = 12, // Pointer Width: This RAM is indexed by sequence number (12 bits)
- parameter DP = (1 << PW) // Depth: max of 4K sequence numbers
- )
- (
- clka,
- clkb,
- addra,
- addrb,
- dina,
- doutb,
- ena,
- enb,
- wea
- );
- // -----------------------------------------------------------------------------
- // IO Declarations
- // -----------------------------------------------------------------------------
- input clka;
- input clkb;
- input [PW-1:0] addra;
- input [PW-1:0] addrb;
- input [WD-1:0] dina;
- input ena;
- input enb;
- input wea;
- output [WD-1:0] doutb;
- reg [WD-1:0] mem [0:DP-1];
- reg [WD-1:0] doutb;
- integer i;
- // Writes
- always @(posedge clka)
- begin
- if (wea)
- mem[addra] <= #(`TP) dina;
- // synopsys translate_off
- if ((addra >= DP) & (DP > 0))
- $display("%t: Memory (%m) write address error. Address is %x, Max is %x, DP = 0x%x, PW = 0x%x", $time, addra, DP-1,DP,PW);
- // synopsys translate_on
- end
- // Reads
- always @(posedge clkb)
- begin
- doutb <= #(`TP) mem[addrb];
- // synopsys translate_off
- if ((addrb >= DP) & (DP > 0))
- $display("%t: Memory (%m) read address error. Address is %x, Max is %x, DP = 0x%x, PW = 0x%x", $time, addrb, DP-1,DP,PW);
- // synopsys translate_on
- end
复制代码 |
|