library IEEE;<br>
use IEEE.STD_LOGIC_1164.ALL;<br>
use IEEE.STD_LOGIC_ARITH.ALL;<br>
use IEEE.STD_LOGIC_UNSIGNED.ALL;<br>
<br>
entity test is<br>
port ( <br>
nCPU_RDY: in std_logic; <br>
NP_SP_CLK : in std_logic; <br>
nIF_SP_RESET : in std_logic; <br>
nCPU_CS : out std_logic; <br>
CPU_D : inout std_logic_vector(31 downto 0); <br>
CPU_A : out std_logic_vector(10 downto 0); <br>
nCPU_RD : out std_logic; <br>
nCPU_WR : out std_logic; <br>
nCPU_WIDTH : out std_logic_vector(1 downto 0); <br>
nCPU_BADD : out std_logic_vector(1 downto 0); <br>
RJ_LED_Y : out std_logic_vector(3 downto 0); <br>
RJ_LED_G : out std_logic_vector(3 downto 0); <br>
RJ_LEDA_G : out std_logic_vector(3 downto 0); <br>
RJ_LED_EN : out std_logic <br>
);<br>
end test;<br>
<br>
architecture rtl of test is<br>
type state_type is (idle,wr_add,wr_cs_assert,wr_wr_assert,wr_data,wr_wr_deassert,judge_wr_rdy,wr_cs_deassert,wr_data_deassert,rd_cs_assert,rd_rd_assert,rd_fetch_data,judge_rd_rdy,rd_wait_deassert,rd_rd_deassert,rd_cs_deassert);<br>
<br>
signal present_state,next_state : state_type;<br>
signal read_data_reg : std_logic_vector(31 downto 0);<br>
<br>
signal ready : std_logic; --ready for write and read<br>
<br>
<br>
begin<br>
<br>
nCPU_WR<='1';<br>
nCPU_RD<='1';<br>
nCPU_CS<='1';<br>
CPU_A<="11111111111";<br>
CPU_D<="00000000000000000000000000000000";<br>
<br>
nCPU_WIDTH<="11"; --32-bit mode<br>
nCPU_BADD<="00"; --little endian [31:0]<br>
ready<='1';<br>
-----------------write and read--------------------<br>
process(present_state,ready,CPU_D,nCPU_RDY, nIF_SP_RESET) <br>
begin<br>
--need initial state <br>
if nIF_SP_RESET = '0' then<br>
next_state<=idle;<br>
else<br>
<br>
case present_state is<br>
when idle =><br>
if ready='1' then<br>
next_state<=wr_add;<br>
else <br>
next_state<=idle;<br>
end if;<br>
when wr_add =><br>
CPU_A<="10100000001"; <br>
next_state<=wr_cs_assert;<br>
when wr_cs_assert =><br>
nCPU_CS<='0';<br>
next_state<=wr_wr_assert;<br>
when wr_wr_assert =><br>
nCPU_WR<='0';<br>
next_state<=wr_data;<br>
when wr_data => <br>
CPU_D<="00000000000000000000000000001111"; <br>
next_state<=wr_wr_deassert;<br>
when wr_wr_deassert =><br>
nCPU_WR<='1';<br>
next_state<=judge_wr_rdy;<br>
when judge_wr_rdy =><br>
if nCPU_RDY='0' then<br>
next_state<=wr_cs_deassert;<br>
else <br>
next_state<=judge_wr_rdy;<br>
end if;<br>
when wr_cs_deassert =><br>
nCPU_CS<='1';<br>
next_state<=wr_data_deassert;<br>
when wr_data_deassert =><br>
CPU_D<="00000000000000000000000000000000";<br>
when rd_cs_assert =><br>
nCPU_CS<='0';<br>
next_state<=rd_rd_assert;<br>
when rd_rd_assert =><br>
nCPU_RD<='0';<br>
next_state<=rd_fetch_data;<br>
when rd_fetch_data =><br>
read_data_reg<=CPU_D;<br>
next_state<=judge_rd_rdy;<br>
when judge_rd_rdy =><br>
if nCPU_RDY='0' then<br>
next_state<=rd_wait_deassert;<br>
else <br>
next_state<=judge_rd_rdy;<br>
end if;<br>
when rd_wait_deassert =><br>
next_state<=rd_rd_deassert;<br>
when rd_rd_deassert =><br>
nCPU_RD<='1';<br>
next_state<=rd_cs_deassert;<br>
when rd_cs_deassert =><br>
nCPU_CS<='1';<br>
ready<='0';<br>
next_state<=idle;<br>
when others =><br>
next_state<=idle;<br>
end case;<br>
end if;<br>
end process;<br>
<br>
process(NP_SP_CLK,nCPU_RDY)<br>
begin<br>
if rising_edge(NP_SP_CLK) or falling_edge(nCPU_RDY) then <br>
present_state<=next_state;<br>
end if;<br>
end process;<br>
<br>
-----------------------------------------------decode----------------------------------<br>
RJ_LED_EN<='0';<br>
RJ_LED_Y<=read_data_reg(1 DOWNTO 0) &read_data_reg(7 DOWNTO 6) ;<br>
RJ_LED_G<=read_data_reg(5 DOWNTO 4) &read_data_reg(3 DOWNTO 2);<br>
RJ_LEDA_G<="1111";<br>
<br>
<br>
<br>
end rtl; |