-1

我想对一个长度为 16 的数组进行排序,该数组有 8 个位数。我已经使用了bubblesort,它工作正常。现在我想从 BRAM 读取输入数组并将排序后的输出写入 BRAM。我已将单端口 RAM 用于测试平台,这就是它的外观。

library IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;

entity testbench is   
end testbench;

architecture Behavioral of testbench is

--temporary signal declarations.
signal ena : std_logic := '0';
signal wea : std_logic_VECTOR(0 downto 0):="0";
signal addra,dina,douta : std_logic_VECTOR(7 downto 0) := (others => '0');
signal clk : std_logic := '0';

begin
--Instantiating BRAM.
BRAM : entity work.BRAM_test 
port map(
clka => clk,  --clock for writing data to RAM.
ena => ena,   --Enable signal.
wea => wea,   --Write enable signal for Port A.
addra => addra, --8 bit address for the RAM.
dina => dina,   --8 bit data input to the RAM.
douta => douta);  --8 bit data output from the RAM. 

--Simulation process.
process(clk)
begin
addra <= X"00";  --reset the address value for reading from memory location "0"


end process;    

--Clock generation - Generates 500 MHz clock with 50% duty cycle.
process
begin
clk <= '1';
wait for 1 ns;  --"ON" time.
clk <= '0';
wait for 1 ns;  --"OFF" time.
end process;    

end Behavioral;

我无法做到这一点。请帮我。

4

1 回答 1

1

您可以执行以下附加代码之类的操作。这是一个通过状态读取 BRAM 内容、对数据进行排序(您可以添加排序逻辑)并将结果写回的过程。

gen_reset: process
begin
    reset<='1';
    wait for 50 ns;
    reset<='0';
    wait;
end process gen_reset;

gen_bram_access: process(clk, reset)
    type state_t is (read_bram, sort, write_bram, end_state);
    type buf_t is array(255 downto 0) of std_logic_vector(7 downto 0);
    variable buf: buf_t;
    variable state: state_t;

begin
    if reset='1' then
        addra<=X"00";
        buf:=(others=>(others => '0'));
        ena<='1';
        wea<="0";
        state:=read_bram;
    elsif rising_Edge(clk) then
        -- defaults
        ena<='1';
        wea<="0"; 

        case state is
    -- readout
        when read_bram =>
            if addra<X"FF" then --expected that X"FF" is last address
                buf(to_integer(unsigned(addra))):=dina;
                state:=read_bram;
                addra<=std_logic_vector(unsigned(addra) + 1);
            else
                addra<=X"00";
                state:=sort;
            end if;

    -- sort with whatever algo
        when sort =>
            -- add algo here! when finished, write results!
            state:=write_bram;

    -- write sorted to bram 
        when write_bram =>  
            if addra<X"FF" then --expected that X"FF" is last address
                douta<=buf(to_integer(unsigned(addra)));
                wea<="1";
                state:=write_bram;
                addra<=std_logic_vector(unsigned(addra) + 1);
            else
                addra<=X"00";
                state:=end_state;
            end if;         
        when others => -- (end_state)   
            state:=end_state;
        end case;
    end if;
end process gen_bram_access;
于 2013-03-11T09:06:47.670 回答