Kosyas41
Member level 3
- Joined
- Apr 12, 2016
- Messages
- 62
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 502
library ieee;
use ieee.std_logic_1164.all;
entity true_dual_port_ram_single_clock is
generic (
DATA_WIDTH : natural := 8;
ADDR_WIDTH : natural := 6
);
port (
clk : in std_logic;
addr_a : in natural range 0 to 2**ADDR_WIDTH - 1;
addr_b : in natural range 0 to 2**ADDR_WIDTH - 1;
data_a : in std_logic_vector((DATA_WIDTH-1) downto 0);
data_b : in std_logic_vector((DATA_WIDTH-1) downto 0);
we_a : in std_logic := '1';
we_b : in std_logic := '1';
q_a : out std_logic_vector((DATA_WIDTH -1) downto 0);
q_b : out std_logic_vector((DATA_WIDTH -1) downto 0)
);
end true_dual_port_ram_single_clock;
architecture rtl of true_dual_port_ram_single_clock is
-- Build a 2-D array type for the RAM
subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0);
type memory_t is array((2**ADDR_WIDTH - 1) downto 0) of word_t;
-- Declare the RAM signal.
shared variable ram : memory_t;
begin
process(clk)
begin
if(rising_edge(clk)) then -- Port A
if(we_a = '1') then
ram(addr_a) <= data_a;
-- Read-during-write on the same port returns NEW data
q_a <= data_a;
else
-- Read-during-write on the mixed port returns OLD data
q_a <= ram(addr_a);
end if;
end if;
end process;
process(clk)
begin
if(rising_edge(clk)) then -- Port B
if(we_b = '1') then
ram(addr_b) := data_b;
-- Read-during-write on the same port returns NEW data
q_b <= data_b;
else
-- Read-during-write on the mixed port returns OLD data
q_b <= ram(addr_b);
end if;
end if;
end process;
end rtl;
but the question.how can I write data to this Ram?
library ieee;
use ieee.std_logic_1164.all;
entity true_dual_port_ram_single_clock is
generic (
DATA_WIDTH : natural := 8;
ADDR_WIDTH : natural := 6
);
port (
clk : in std_logic;
addr_a : in natural range 0 to 2**ADDR_WIDTH - 1;
addr_b : in natural range 0 to 2**ADDR_WIDTH - 1;
data_a : in std_logic_vector((DATA_WIDTH-1) downto 0);
data_b : in std_logic_vector((DATA_WIDTH-1) downto 0);
we_a : in std_logic := '1';
we_b : in std_logic := '1';
q_a : out std_logic_vector((DATA_WIDTH -1) downto 0);
q_b : out std_logic_vector((DATA_WIDTH -1) downto 0)
);
end true_dual_port_ram_single_clock;
architecture rtl of true_dual_port_ram_single_clock is
-- Build a 2-D array type for the RAM
subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0);
type memory_t is array((2**ADDR_WIDTH - 1) downto 0) of word_t;
-- Declare the RAM signal.
shared variable ram : memory_t;
begin
process(clk)
begin
if(rising_edge(clk)) then -- Port A
if(we_a = '1') then
case addr_a is
when 0 =>
data_a <= 128;
when 16 =>
data_a <= 128;
when others =>
data_a <=0;
end case;
ram(addr_a) <= data_a;
-- Read-during-write on the same port returns NEW data
q_a <= data_a;
else
-- Read-during-write on the mixed port returns OLD data
q_a <= ram(addr_a);
end if;
end if;
end process;
process(clk)
begin
if(rising_edge(clk)) then -- Port B
if(we_b = '1') then
ram(addr_b) := data_b;
-- Read-during-write on the same port returns NEW data
q_b <= data_b;
else
-- Read-during-write on the mixed port returns OLD data
q_b <= ram(addr_b);
end if;
end if;
end process;
end rtl;
but the question.how can I
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 process(clk) begin if(rising_edge(clk)) then -- Port A if(we_a = '1') then case addr_a is when 0 => data_a <= 128; when 16 => data_a <= 128; when others => data_a <=0; end case; ram(addr_a) <= data_a; -- Read-during-write on the same port returns NEW data q_a <= data_a; else -- Read-during-write on the mixed port returns OLD data q_a <= ram(addr_a); end if;
entity rx_buffer is
generic (WIDTH : integer := 2);
port ( clock : in std_logic;
n_reset : in std_logic;
rxbuff_en : in std_logic;
rxbuff_wr_en : in std_logic;
rxbuff_addr : in std_logic_vector(WIDTH-1 downto 0);
rxbuff_in : in std_logic_vector(7 downto 0);
rxbuff_out : out std_logic_vector(7 downto 0)
);
end rx_buffer;
architecture rx_buffer_arc of rx_buffer is
type mem_arr is array (natural range<>) of std_logic_vector(7 downto 0);
signal DATA_ARR_q, DATA_ARR_in : mem_arr(0 to WIDTH+1);
begin
process (rxbuff_en, rxbuff_wr_en, rxbuff_addr, DATA_ARR_q, rxbuff_in)
begin
DATA_ARR_in <= DATA_ARR_q;
rxbuff_out <= (others => '0');
if (rxbuff_en = '1') then
if (rxbuff_wr_en = '1') then
if (rxbuff_addr = "00") then
DATA_ARR_in(0) <= rxbuff_in;
elsif (rxbuff_addr = "01") then
DATA_ARR_in(1) <= rxbuff_in;
elsif (rxbuff_addr = "10") then
DATA_ARR_in(2) <= rxbuff_in;
else
DATA_ARR_in(3) <= rxbuff_in;
end if;
else
if (rxbuff_addr = "00") then
rxbuff_out <= DATA_ARR_q(0);
elsif (rxbuff_addr = "01") then
rxbuff_out <= DATA_ARR_q(1);
elsif (rxbuff_addr = "10") then
rxbuff_out <= DATA_ARR_q(2);
else
rxbuff_out <= DATA_ARR_q(3);
end if;
end if;
end if;
end process;
process (clock, n_reset)
begin
if (n_reset = '0') then
DATA_ARR_q <= (others => (others => '0'));
else
if (clock='1' and clock'event) then
DATA_ARR_q <= DATA_ARR_in;
end if;
end if;
end process;
end rx_buffer_arc;
entity tx_buffer is
generic (WIDTH : integer := 2);
port ( clock : in std_logic;
n_reset : in std_logic;
txbuff_en : in std_logic;
txbuff_wr_en : in std_logic;
txbuff_addr : in std_logic_vector(WIDTH-1 downto 0);
txbuff_in : in std_logic_vector(7 downto 0);
txbuff_out : out std_logic_vector(7 downto 0)
);
end tx_buffer;
architecture tx_buffer_arc of tx_buffer is
type mem_arr is array (natural range<>) of std_logic_vector(7 downto 0);
signal DATA_ARR_q, DATA_ARR_in : mem_arr(0 to WIDTH+1);
begin
process (txbuff_en, txbuff_wr_en, txbuff_addr, DATA_ARR_q, txbuff_in)
begin
-- next-state assignments
DATA_ARR_in <= DATA_ARR_q;
txbuff_out <= (others => '0');
if (txbuff_en = '1') then
if (txbuff_wr_en = '1') then
if (txbuff_addr = "00") then
DATA_ARR_in(0) <= txbuff_in;
elsif (txbuff_addr = "01") then
DATA_ARR_in(1) <= txbuff_in;
elsif (txbuff_addr = "10") then
DATA_ARR_in(2) <= txbuff_in;
else
DATA_ARR_in(3) <= txbuff_in;
end if;
else
if (txbuff_addr = "00") then
txbuff_out <= DATA_ARR_q(0);
elsif (txbuff_addr = "01") then
txbuff_out <= DATA_ARR_q(1);
elsif (txbuff_addr = "10") then
txbuff_out <= DATA_ARR_q(2);
else
txbuff_out <= DATA_ARR_q(3);
end if;
end if;
end if;
end process;
process (clock, n_reset)
begin
if (n_reset = '0') then
DATA_ARR_q <= (others => (others => '0'));
else
if (clock='1' and clock'event) then
DATA_ARR_q <= DATA_ARR_in;
end if;
end if;
end process;
end tx_buffer_arc;
THe following might help you. The READ and WRITE codes are different, but you can easily combine them.
Code:entity rx_buffer is generic (WIDTH : integer := 2); port ( clock : in std_logic; n_reset : in std_logic; rxbuff_en : in std_logic; rxbuff_wr_en : in std_logic; rxbuff_addr : in std_logic_vector(WIDTH-1 downto 0); rxbuff_in : in std_logic_vector(7 downto 0); rxbuff_out : out std_logic_vector(7 downto 0) ); end rx_buffer; architecture rx_buffer_arc of rx_buffer is type mem_arr is array (natural range<>) of std_logic_vector(7 downto 0); signal DATA_ARR_q, DATA_ARR_in : mem_arr(0 to WIDTH+1); begin process (rxbuff_en, rxbuff_wr_en, rxbuff_addr, DATA_ARR_q, rxbuff_in) begin DATA_ARR_in <= DATA_ARR_q; rxbuff_out <= (others => '0'); if (rxbuff_en = '1') then if (rxbuff_wr_en = '1') then if (rxbuff_addr = "00") then DATA_ARR_in(0) <= rxbuff_in; elsif (rxbuff_addr = "01") then DATA_ARR_in(1) <= rxbuff_in; elsif (rxbuff_addr = "10") then DATA_ARR_in(2) <= rxbuff_in; else DATA_ARR_in(3) <= rxbuff_in; end if; else if (rxbuff_addr = "00") then rxbuff_out <= DATA_ARR_q(0); elsif (rxbuff_addr = "01") then rxbuff_out <= DATA_ARR_q(1); elsif (rxbuff_addr = "10") then rxbuff_out <= DATA_ARR_q(2); else rxbuff_out <= DATA_ARR_q(3); end if; end if; end if; end process; process (clock, n_reset) begin if (n_reset = '0') then DATA_ARR_q <= (others => (others => '0')); else if (clock='1' and clock'event) then DATA_ARR_q <= DATA_ARR_in; end if; end if; end process; end rx_buffer_arc;
Code:entity tx_buffer is generic (WIDTH : integer := 2); port ( clock : in std_logic; n_reset : in std_logic; txbuff_en : in std_logic; txbuff_wr_en : in std_logic; txbuff_addr : in std_logic_vector(WIDTH-1 downto 0); txbuff_in : in std_logic_vector(7 downto 0); txbuff_out : out std_logic_vector(7 downto 0) ); end tx_buffer; architecture tx_buffer_arc of tx_buffer is type mem_arr is array (natural range<>) of std_logic_vector(7 downto 0); signal DATA_ARR_q, DATA_ARR_in : mem_arr(0 to WIDTH+1); begin process (txbuff_en, txbuff_wr_en, txbuff_addr, DATA_ARR_q, txbuff_in) begin -- next-state assignments DATA_ARR_in <= DATA_ARR_q; txbuff_out <= (others => '0'); if (txbuff_en = '1') then if (txbuff_wr_en = '1') then if (txbuff_addr = "00") then DATA_ARR_in(0) <= txbuff_in; elsif (txbuff_addr = "01") then DATA_ARR_in(1) <= txbuff_in; elsif (txbuff_addr = "10") then DATA_ARR_in(2) <= txbuff_in; else DATA_ARR_in(3) <= txbuff_in; end if; else if (txbuff_addr = "00") then txbuff_out <= DATA_ARR_q(0); elsif (txbuff_addr = "01") then txbuff_out <= DATA_ARR_q(1); elsif (txbuff_addr = "10") then txbuff_out <= DATA_ARR_q(2); else txbuff_out <= DATA_ARR_q(3); end if; end if; end if; end process; process (clock, n_reset) begin if (n_reset = '0') then DATA_ARR_q <= (others => (others => '0')); else if (clock='1' and clock'event) then DATA_ARR_q <= DATA_ARR_in; end if; end if; end process; end tx_buffer_arc;
library ieee;
use ieee.std_logic_1164.all;
entity tx_buffer is
generic (WIDTH : integer := 2);
port ( clock : in std_logic;
n_reset : in std_logic;
txbuff_en : in std_logic;
txbuff_wr_en : in std_logic;
txbuff_addr : in std_logic_vector(WIDTH-1 downto 0);
txbuff_in : in std_logic_vector(7 downto 0);
txbuff_out : out std_logic_vector(7 downto 0);
rxbuff_en : in std_logic;
rxbuff_wr_en : in std_logic;
rxbuff_addr : in std_logic_vector(WIDTH-1 downto 0);
rxbuff_in : in std_logic_vector(7 downto 0);
rxbuff_out : out std_logic_vector(7 downto 0)
);
end tx_buffer;
architecture tx_buffer_arc of tx_buffer is
type mem_arr is array (natural range<>) of std_logic_vector(7 downto 0);
signal DATA_ARR_q, DATA_ARR_in : mem_arr(0 to WIDTH+1);
begin
process (txbuff_en, txbuff_wr_en, rxbuff_en,rxbuff_wr_en, rxbuff_addr, txbuff_addr, DATA_ARR_q, txbuff_in,rxbuff_in)
begin
-- next-state assignments
DATA_ARR_in <= DATA_ARR_q;
txbuff_out <= (others => '0');
if (txbuff_en = '1') then
if (txbuff_wr_en = '1') then
if (txbuff_addr = "00") then
DATA_ARR_in(0) <= txbuff_in;
elsif (txbuff_addr = "01") then
DATA_ARR_in(1) <= txbuff_in;
elsif (txbuff_addr = "10") then
DATA_ARR_in(2) <= txbuff_in;
else
DATA_ARR_in(3) <= txbuff_in;
end if;
else
if (txbuff_addr = "00") then
txbuff_out <= DATA_ARR_q(0);
elsif (txbuff_addr = "01") then
txbuff_out <= DATA_ARR_q(1);
elsif (txbuff_addr = "10") then
txbuff_out <= DATA_ARR_q(2);
else
txbuff_out <= DATA_ARR_q(3);
end if;
end if;
end if;
rxbuff_out <= (others => '0');
if (rxbuff_en = '1') then
if (rxbuff_wr_en = '1') then
if (rxbuff_addr = "00") then
DATA_ARR_in(0) <= rxbuff_in;
elsif (rxbuff_addr = "01") then
DATA_ARR_in(1) <= rxbuff_in;
elsif (rxbuff_addr = "10") then
DATA_ARR_in(2) <= rxbuff_in;
else
DATA_ARR_in(3) <= rxbuff_in;
end if;
else
if (rxbuff_addr = "00") then
rxbuff_out <= DATA_ARR_q(0);
elsif (rxbuff_addr = "01") then
rxbuff_out <= DATA_ARR_q(1);
elsif (rxbuff_addr = "10") then
rxbuff_out <= DATA_ARR_q(2);
else
rxbuff_out <= DATA_ARR_q(3);
end if;
end if;
end if;
end process;
process (clock, n_reset)
begin
if (n_reset = '0') then
DATA_ARR_q <= (others => (others => '0'));
else
if (clock='1' and clock'event) then
DATA_ARR_q <= DATA_ARR_in;
end if;
end if;
end process;
end tx_buffer_arc;
library ieee;
use ieee.std_logic_1164.all;
entity true_dual_port_ram_single_clock is
generic (
DATA_WIDTH : integer := 8;
ADDR_WIDTH : integer := 6;
WIDTH : integer :=2
);
port (
clk : in std_logic;
n_reset : in std_logic;
addr_a : in natural range 0 to 2**ADDR_WIDTH - 1;
addr_b : in natural range 0 to 2**ADDR_WIDTH - 1;
data_a : in std_logic_vector((DATA_WIDTH-1) downto 0);
data_b : in std_logic_vector((DATA_WIDTH-1) downto 0);
we_a : in std_logic := '1';
we_b : in std_logic := '1';
q_a : out std_logic_vector((DATA_WIDTH -1) downto 0);
q_b : out std_logic_vector((DATA_WIDTH -1) downto 0);
txbuff_en : in std_logic;
txbuff_wr_en : in std_logic;
txbuff_addr : in std_logic_vector(WIDTH-1 downto 0);
txbuff_in : in std_logic_vector(7 downto 0);
txbuff_out : out std_logic_vector(7 downto 0);
rxbuff_en : in std_logic;
rxbuff_wr_en : in std_logic;
rxbuff_addr : in std_logic_vector(WIDTH-1 downto 0);
rxbuff_in : in std_logic_vector(7 downto 0);
rxbuff_out : out std_logic_vector(7 downto 0)
);
end true_dual_port_ram_single_clock;
architecture rtl of true_dual_port_ram_single_clock is
-- Build a 2-D array type for the RAM
subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0);
type memory_t is array((2**ADDR_WIDTH - 1) downto 0) of word_t;
-- Declare the RAM signal.
type mem_arr is array (natural range<>) of std_logic_vector(7 downto 0);
signal DATA_ARR_q, DATA_ARR_in : mem_arr(0 to WIDTH+1);
shared variable ram : memory_t;
begin
process(clk)
begin
if(rising_edge(clk)) then -- Port A
if(we_a = '1') then
ram(addr_a) := data_a;
-- Read-during-write on the same port returns NEW data
q_a <= data_a;
else
-- Read-during-write on the mixed port returns OLD data
q_a <= ram(addr_a);
end if;
end if;
end process;
process(clk,txbuff_en, txbuff_wr_en, rxbuff_en,rxbuff_wr_en, rxbuff_addr, txbuff_addr, DATA_ARR_q, txbuff_in,rxbuff_in)
begin
DATA_ARR_in <= DATA_ARR_q;
txbuff_out <= (others => '0');
if (txbuff_en = '1') then
if (txbuff_wr_en = '1') then
if (txbuff_addr = "00") then
DATA_ARR_in(0) <= txbuff_in;
elsif (txbuff_addr = "01") then
DATA_ARR_in(1) <= txbuff_in;
elsif (txbuff_addr = "10") then
DATA_ARR_in(2) <= txbuff_in;
else
DATA_ARR_in(3) <= txbuff_in;
end if;
else
if (txbuff_addr = "00") then
txbuff_out <= DATA_ARR_q(0);
elsif (txbuff_addr = "01") then
txbuff_out <= DATA_ARR_q(1);
elsif (txbuff_addr = "10") then
txbuff_out <= DATA_ARR_q(2);
else
txbuff_out <= DATA_ARR_q(3);
end if;
end if;
end if;
rxbuff_out <= (others => '0');
if (rxbuff_en = '1') then
if (rxbuff_wr_en = '1') then
if (rxbuff_addr = "00") then
DATA_ARR_in(0) <= rxbuff_in;
elsif (rxbuff_addr = "01") then
DATA_ARR_in(1) <= rxbuff_in;
elsif (rxbuff_addr = "10") then
DATA_ARR_in(2) <= rxbuff_in;
else
DATA_ARR_in(3) <= rxbuff_in;
end if;
else
if (rxbuff_addr = "00") then
rxbuff_out <= DATA_ARR_q(0);
elsif (rxbuff_addr = "01") then
rxbuff_out <= DATA_ARR_q(1);
elsif (rxbuff_addr = "10") then
rxbuff_out <= DATA_ARR_q(2);
else
rxbuff_out <= DATA_ARR_q(3);
end if;
end if;
end if;
end process;
process (clk, n_reset)
begin
if (n_reset = '0') then
DATA_ARR_q <= (others => (others => '0'));
else
if (clk='1' and clk'event) then
DATA_ARR_q <= DATA_ARR_in;
end if;
end if;
if(rising_edge(clk)) then -- Port B
if(we_b = '1') then
ram(addr_b) := data_b;
-- Read-during-write on the same port returns NEW data
q_b <= data_b;
else
-- Read-during-write on the mixed port returns OLD data
q_b <= ram(addr_b);
end if;
end if;
end process;
end rtl;
Sorry about the above comment in #8.The READ and WRITE codes are different, but you can easily combine them.
Due to your above comment in #7, I gave you an example.ok/but how I can write a right code?Could you pls help me?
library ieee;
use ieee.std_logic_1164.all;
entity true_dual_port_ram_single_clock is
generic (
DATA_WIDTH : integer := 8;
ADDR_WIDTH : integer := 6;
WIDTH : integer :=2
);
port (
clk : in std_logic;
n_reset : in std_logic;
addr_a : in natural range 0 to 2**ADDR_WIDTH - 1;
addr_b : in natural range 0 to 2**ADDR_WIDTH - 1;
data_a : in std_logic_vector((DATA_WIDTH-1) downto 0);
data_b : in std_logic_vector((DATA_WIDTH-1) downto 0);
we_a : in std_logic := '1';
we_b : in std_logic := '1';
q_a : out std_logic_vector((DATA_WIDTH -1) downto 0);
q_b : out std_logic_vector((DATA_WIDTH -1) downto 0);
txbuff_en : in std_logic;
txbuff_wr_en : in std_logic;
txbuff_addr : in std_logic_vector(WIDTH-1 downto 0);
txbuff_in : in std_logic_vector(7 downto 0);
txbuff_out : out std_logic_vector(7 downto 0)
);
end true_dual_port_ram_single_clock;
architecture rtl of true_dual_port_ram_single_clock is
-- Build a 2-D array type for the RAM
subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0);
type memory_t is array((2**ADDR_WIDTH - 1) downto 0) of word_t;
-- Declare the RAM signal.
type mem_arr is array (natural range<>) of std_logic_vector(7 downto 0);
signal DATA_ARR_q, DATA_ARR_in : mem_arr(0 to WIDTH+1);
shared variable ram : memory_t;
begin
process(clk)
begin
if(rising_edge(clk)) then -- Port A
if(we_a = '1') then
ram(addr_a) := data_a;
-- Read-during-write on the same port returns NEW data
q_a <= data_a;
else
-- Read-during-write on the mixed port returns OLD data
q_a <= ram(addr_a);
end if;
end if;
end process;
process(clk,txbuff_en, txbuff_wr_en, txbuff_addr, DATA_ARR_q, txbuff_in)
begin
DATA_ARR_in <= DATA_ARR_q;
txbuff_out <= (others => '0');
if (txbuff_en = '1') then
if (txbuff_wr_en = '1') then
if (txbuff_addr = "00") then
DATA_ARR_in(0) <= txbuff_in;
elsif (txbuff_addr = "01") then
DATA_ARR_in(1) <= txbuff_in;
elsif (txbuff_addr = "10") then
DATA_ARR_in(2) <= txbuff_in;
else
DATA_ARR_in(3) <= txbuff_in;
end if;
else
if (txbuff_addr = "00") then
txbuff_out <= DATA_ARR_q(0);
elsif (txbuff_addr = "01") then
txbuff_out <= DATA_ARR_q(1);
elsif (txbuff_addr = "10") then
txbuff_out <= DATA_ARR_q(2);
else
txbuff_out <= DATA_ARR_q(3);
end if;
end if;
end if;
end process;
process (clk, n_reset)
begin
if (n_reset = '0') then
DATA_ARR_q <= (others => (others => '0'));
else
if (clk='1' and clk'event) then
DATA_ARR_q <= DATA_ARR_in;
end if;
end if;
if(rising_edge(clk)) then -- Port B
if(we_b = '1') then
ram(addr_b) := data_b;
-- Read-during-write on the same port returns NEW data
q_b <= data_b;
else
-- Read-during-write on the mixed port returns OLD data
q_b <= ram(addr_b);
end if;
end if;
end process;
end rtl;
.So Its mean that I can use your code and it will write data in dp RAM?
Sorry, I can't work as a compiler for you.for example like this?
FYI, the OP want's you to write an entire example for them. It's not about common sense or knowledge, it's a fundamental problem of not having a engineer's thought process.You have to understand both the codes and then use your knowledge and common sense.
I never do that.FYI, the OP want's you to write an entire example for them.
I wanted to say technical common sense.It's not about common sense or knowledge,.....
:-DI never do that.
Does such a thing even exist!? I must have read too many questions on edaboard, based on what I've seen around here, such a thing is not at all common. In fact it seems to be an endangered species on the brink of extinction. Or maybe it's the engineering equivalent of the dodo bird. ;-)I wanted to say technical common sense.
Very nicely put, but next you'll be asked to write the testbench or give them an example testbench. :roll:To the OP: Please go through my codes and first understand how a simple write and read takes place. Do write a test-bench for it and study the signal transitions via the waveforms after simulation. After that you can go for the modelling a true dual port RAM. I say that because I have an impression that you lack some basic understanding.
Interesting. I'm going to say the wolverine eats the cat. The dog can outrun the crocodile, even if the dog is small due to the four-leg advantage. But without knowing how large the dog is, it is impossible to know if the wolverine would also eat it.You have one dog, one wolverine, a three legged crocodile, and one cat. How many domesticated animals do you own?
library ieee;
use ieee.std_logic_1164.all;
entity true_dual_port_ram_single_clock is
generic (
DATA_WIDTH : natural := 8;
ADDR_WIDTH : natural := 6
);
port (
clk : in std_logic;
addr_a : in natural range 0 to 2**ADDR_WIDTH - 1;
addr_b : in natural range 0 to 2**ADDR_WIDTH - 1;
data_a : in std_logic_vector((DATA_WIDTH-1) downto 0);
data_b : in std_logic_vector((DATA_WIDTH-1) downto 0);
we_a : in std_logic := '1';
we_b : in std_logic := '1';
q_a : out std_logic_vector((DATA_WIDTH -1) downto 0);
q_b : out std_logic_vector((DATA_WIDTH -1) downto 0)
);
end true_dual_port_ram_single_clock;
architecture rtl of true_dual_port_ram_single_clock is
-- Build a 2-D array type for the RAM
subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0);
type memory_t is array((2**ADDR_WIDTH - 1) downto 0) of word_t;
-- Declare the RAM signal.
shared variable ram : memory_t;
begin
process(clk)
begin
if(rising_edge(clk)) then -- Port A
if(we_a = '1') then
case addr_a is
when 0 =>
q_a <= "10000000";
when 16 =>
q_a <= "10000000";
when others =>
q_a <="00000000";
end case;
ram(addr_a) := data_a;
-- Read-during-write on the same port returns NEW data
q_a <= data_a;
else
-- Read-during-write on the mixed port returns OLD data
case addr_a is
when 0 =>
q_a <= "10000000";
when 16 =>
q_a <= "10000000";
when others =>
q_a <="00000000";
end case;
q_a <= ram(addr_a);
end if;
end if;
end process;
process(clk)
begin
if(rising_edge(clk)) then -- Port B
if(we_b = '1') then
case addr_b is
when 0 =>
q_b <= "10000000";
when 16 =>
q_b <= "10000000";
when others =>
q_b <="00000000";
end case;
ram(addr_b) := data_b;
-- Read-during-write on the same port returns NEW data
q_b <= data_b;
else
-- Read-during-write on the mixed port returns OLD data
if(we_b = '1') then
case addr_b is
when 0 =>
q_b <= "10000000";
when 16 =>
q_b <= "10000000";
when others =>
q_b <="00000000";
end case;
q_b <= ram(addr_b);
end if;
end if;
end if;
end process;
end rtl;
ram(addr_b) := data_b;
-- Read-during-write on the same port returns NEW data
q_b <= data_b;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?