Instantiation of RAM in FPGAs using VHDL

懵懂的女人 提交于 2019-12-06 03:30:53

OK, having gone through the blog post I now understand why they're using shared variable instead of signals. Its because multiple processes are assigning to this variable, which is not possible in the case of a reg in Verilog or a signal in VHDL. In that case the synthesizer will produce an error complaining of multiple drivers for mem. But in order to use shared variable in this case, you'll have to declare it as protected. What you need to do is declare a protected data type, and then encapsulate your mem variable inside it, much like classes in object oriented languages. Here's an example of the protected data type:

type mem_envelope is protected        -- protected type declaration

variable mem : mem_type;

function GetVal( addr : integer ) return std_logic_vector(data - 1 downto 0);
function SetVal( addr : integer; val : std_logic_vector(data - 1 downto 0) ) return boolean; --may be used to indicate whether write was successfull or not

end protected mem_envelope;

Then declare a sharede variable of type mem_envelope and use GetVal and SetVal functions to read/write values to the memory inside your processes.

Another way of implementing a True-Dual-Port (TDP) RAM is to use one process with two clocks.

signal ram          : ram_t;
signal a1_reg       : unsigned(A_BITS-1 downto 0);
signal a2_reg       : unsigned(A_BITS-1 downto 0);

....

process (clk1, clk2)
begin   -- process
  if rising_edge(clk1) then
    if ce1 = '1' then
      if we1 = '1' then
        ram(to_integer(a1)) <= d1;
      end if;

      a1_reg <= a1;
    end if;
  end if;

  if rising_edge(clk2) then
    if ce2 = '1' then
      if we2 = '1' then
        ram(to_integer(a2)) <= d2;
      end if;

      a2_reg <= a2;
    end if;
  end if;
end process;

q1 <= ram(to_integer(a1_reg));      -- returns new data
q2 <= ram(to_integer(a2_reg));      -- returns new data

This is even synthezisable with Xilinx tools. Altera tools need the altsyncram macro for a proper TDP-RAM recognition.

Source: PoC.mem.ocram.tdp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!