vivado RAM Inference

以下示例显示了使用结构和记录对RAM的推断。

RAM Inference Single Port Structure (Verilog)
Filename: rams_sp_struct.sv
// RAM Inference using Struct in SV(Simple Dual port)
// File:rams_sdp_struct.sv
typedef struct packed {
logic [3:0] addr;
logic [27:0] data;
} Packet;
module rams_sdp_struct #(
parameter A_WID = 10,
D_WID = 32
)
(
input clk,
input we,
input ena,
input [A_WID-1:0] raddr, waddr,
input Packet din,
output Packet dout
);
Packet mem [2**A_WID-1:0];
always @ (posedge clk)
begin
if (ena) begin
if(we)
mem[waddr] <= din;
end
end
always @ (posedge clk)
begin
if (ena) begin
dout <= mem[raddr];
end
end
endmodule
RAM Inference Single Port Structure (VHDL)
Filename: rams_sp_record.vhd
-- Ram Inference Example using Records (Single port)
-- File:rams_sp_record.vhd
library ieee;
use ieee.std_logic_1164.all;
package mypack is
type Packet is record
addr : std_logic_vector(3 downto 0);
data : std_logic_vector(27 downto 0);
end record Packet;
type mem_t is array(integer range<>) of Packet;
end package;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.mypack.all;
entity rams_sp_record is generic (
A_WID : integer := 10;
D_WID : integer := 32
);
port (
clk : in std_logic;
we : in std_logic;
ena : in std_logic;
addr : in std_logic_vector(A_WID-1 downto 0);
din : in Packet;
dout : out Packet
);
end rams_sp_record;
architecture arch of rams_sp_record is
signal mem : mem_t(2**A_WID-1 downto 0);
begin
process(clk)
begin
if(clk'event and clk='1') then
if(ena = '1') then
if(we = '1') then
mem(to_integer(unsigned(addr))) <= din;
end if;
dout <= mem(to_integer(unsigned(addr)));
end if;
end if;
end process;
end arch;
RAM Inference - Simple Dual Port Structure (SystemVerilog)
Filename: rams_sdp_struct.sv
// RAM Inference using Struct in SV(Simple Dual port)
// File:rams_sdp_struct.sv
typedef struct packed {
logic [3:0] addr;
logic [27:0] data;
} Packet;
module rams_sdp_struct #(
parameter A_WID = 10,
D_WID = 32
)
(
input clk,
input we,
input ena,
input [A_WID-1:0] raddr, waddr,
input Packet din,
output Packet dout
);
Packet mem [2**A_WID-1:0];
always @ (posedge clk)
begin
if (ena) begin
if(we)
mem[waddr] <= din;
end
end
always @ (posedge clk)
begin
if (ena) begin
dout <= mem[raddr];
end
end
endmodule
RAM Inference - Simple Dual Port Record (VHDL)
Filename: rams_sdp_record.vhd
-- Ram Inference Example using Records (Simple Dual port)
-- File:rams_sdp_record.vhd
library ieee;
use ieee.std_logic_1164.all;
package mypack is
type Packet is record
addr : std_logic_vector(3 downto 0);
data : std_logic_vector(27 downto 0);
end record Packet;
type mem_t is array(integer range<>) of Packet;
end package;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.mypack.all;
entity rams_sdp_record is generic (
A_WID : integer := 10;
D_WID : integer := 32
);
port (
clk : in std_logic;
we : in std_logic;
ena : in std_logic;
raddr : in std_logic_vector(A_WID-1 downto 0);
waddr : in std_logic_vector(A_WID-1 downto 0);
din : in Packet;
dout : out Packet
);
end rams_sdp_record;
architecture arch of rams_sdp_record is
signal mem : mem_t(2**A_WID-1 downto 0);
begin
process(clk)
begin
if(clk'event and clk='1') then
if(ena = '1') then
if(we = '1') then
mem(to_integer(unsigned(waddr))) <= din;
end if;
end if;
end if;
end process;
process(clk)
begin
if(clk'event and clk='1') then
if(ena = '1') then
dout <= mem(to_integer(unsigned(raddr)));
end if;
end if;
end process;
end arch;
RAM Inference True Dual Port Structure (SystemVerilog)
Filename: rams_tdp_struct.sv
// RAM Inference using Struct in SV(True Dual port)
// File:rams_tdp_struct.sv
typedef struct packed {
logic [3:0] addr;
logic [27:0] data;
} Packet;
module rams_tdp_struct #(
parameter A_WID = 10,
D_WID = 32
)
(
input clka,
input clkb,
input wea,
input web,
input ena,
input enb,
input [A_WID-1:0] addra,
input [A_WID-1:0] addrb,
input Packet dina, dinb,
output Packet douta, doutb
);
Packet mem [2**A_WID-1:0];
always @ (posedge clka)
begin
if (ena)
begin
douta <= mem[addra];
if(wea)
mem[addra] <= dina;
end
end
always @ (posedge clkb)
begin
if (enb)
begin
doutb <= mem[addrb];
if(web)
mem[addrb] <= dinb;
end
end
endmodule
RAM Inference True Dual Port Record (VHDL)
Filename: rams_tdp_record.vhd
-- Ram Inference Example using Records (True Dual port)
-- File:rams_tdp_record.vhd
library ieee;
use ieee.std_logic_1164.all;
package mypack is
type Packet is record
addr : std_logic_vector(3 downto 0);
data : std_logic_vector(27 downto 0);
end record Packet;
type mem_t is array(integer range<>) of Packet;
end package;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.mypack.all;
entity rams_tdp_record is generic (
A_WID : integer := 10;
D_WID : integer := 32
);
port (
clka : in std_logic;
clkb : in std_logic;
wea : in std_logic;
web : in std_logic;
ena : in std_logic;
enb : in std_logic;
addra : in std_logic_vector(A_WID-1 downto 0);
addrb : in std_logic_vector(A_WID-1 downto 0);
dina : in Packet;
dinb : in Packet;
douta : out Packet;
doutb : out Packet
);
end rams_tdp_record;
architecture arch of rams_tdp_record is
signal mem : mem_t(2**A_WID-1 downto 0);
begin
process(clka)
begin
if(clka'event and clka='1') then
if(ena = '1') then
douta <= mem(to_integer(unsigned(addra)));
if(wea = '1') then
mem(to_integer(unsigned(addra))) <= dina;
end if;
end if;
end if;
end process;
process(clkb)
begin
if(clkb'event and clkb='1') then
if(enb = '1') then
doutb <= mem(to_integer(unsigned(addrb)));
if(web = '1') then
mem(to_integer(unsigned(addrb))) <= dinb;
end if;
end if;
end if;
end process;
end arch;

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-02-23 08:10:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-23 08:10:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-23 08:10:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-23 08:10:02       20 阅读

热门阅读

  1. nifi连接Sql server数据库报错TLS问题

    2024-02-23 08:10:02       37 阅读
  2. C++程序设计学习笔记(二)

    2024-02-23 08:10:02       28 阅读
  3. Go 语言一些常用语法编写和优化指南

    2024-02-23 08:10:02       30 阅读
  4. 力扣(leetcode)第455题分发饼干(Python)

    2024-02-23 08:10:02       31 阅读
  5. 嵌入式系统发展前景?

    2024-02-23 08:10:02       28 阅读
  6. mxonline安装总结

    2024-02-23 08:10:02       29 阅读
  7. Vue3学习——hooks

    2024-02-23 08:10:02       31 阅读
  8. C语言大小写转换

    2024-02-23 08:10:02       24 阅读
  9. 预防.locked.locked1勒索病毒攻击:保护数据安全

    2024-02-23 08:10:02       29 阅读
  10. 【Swift】NSSearchField用法和示例

    2024-02-23 08:10:02       27 阅读