LIBRARY ieee;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_unsigned.all;
USE ieee.std_logic_1164.all;
ENTITY controlsys IS
GENERIC (
FIFOLENTH : integer := 1024; --FIFO长度2048
FIFOWITH : integer := 16; --FIFO宽度------------8----16---
PACKAGENUM : integer := 128 --FIFO单个数据包长度--512--256--
);
PORT
(
IFCLK : IN STD_LOGIC ;
CLKOUT : OUT STD_LOGIC ;
DATAOUT : INOUT STD_LOGIC_VECTOR (15 DOWNTO 0) ;
SRAMFD : INOUT STD_LOGIC_VECTOR (15 DOWNTO 0) ;
SRAMADR : OUT STD_LOGIC_VECTOR (17 DOWNTO 0) ;
SRAMWE : OUT STD_LOGIC ;
SRAMCE : OUT STD_LOGIC ;
SRAMOE : OUT STD_LOGIC ;
SRAMUB : OUT STD_LOGIC ;
SRAMLB : OUT STD_LOGIC ;
KEY1 : IN STD_LOGIC;
KEY2 : IN STD_LOGIC;
KEY3 : IN STD_LOGIC;
LED1 : OUT STD_LOGIC;
LED2 : OUT STD_LOGIC;
LED3 : OUT STD_LOGIC;
LED4 : OUT STD_LOGIC
);
END controlsys;
ARCHITECTURE ARC_controlsys OF controlsys IS
TYPE fifo_arry IS ARRAY(0 to 31) OF bit_vector((FIFOWITH-1) DOWNTO 0);
SIGNAL fifomemory:fifo_arry;
TYPE wr_state IS (prepare,trswraddr,wrdata,idel);
TYPE rd_state IS (prepare,trsrdaddr,rddata,rdend,idel);
SIGNAL curwrstate:wr_state;
SIGNAL currdstate:rd_state;
SIGNAL addwrbuf: NATURAL RANGE 0 TO (2**9-1) ;
SIGNAL addrdbuf: NATURAL RANGE 0 TO (2**9-1) ;
SIGNAL sramdatabuf: STD_LOGIC_VECTOR((FIFOWITH-1) DOWNTO 0) ;
SIGNAL sramaddbuf : STD_LOGIC_VECTOR(17 DOWNTO 0) ;
SIGNAL data : STD_LOGIC_VECTOR((FIFOWITH-1) DOWNTO 0) :="1111111111111111";
SIGNAL sramoebuf,sramcebuf,sramwebuf,sramubbuf,sramlbbuf : STD_LOGIC ;
SIGNAL led1buf,led2buf,led3buf,led4buf,clkbuf : STD_LOGIC ;
BEGIN
DATAOUT <= sramdatabuf;
SRAMFD <= sramdatabuf;
SRAMADR <= sramaddbuf;
SRAMADR <= sramaddbuf;
SRAMWE <= sramwebuf;
SRAMCE <= sramcebuf;
SRAMOE <= sramoebuf;
SRAMUB <= sramubbuf;
SRAMLB <= sramlbbuf;
LED1 <= led1buf;
LED2 <= led2buf;
LED3 <= led3buf;
LED4 <= led4buf;
CLKOUT <= clkbuf;
P_WR:PROCESS(IFCLK)
VARIABLE count,count1:INTEGER RANGE 0 to 100;
BEGIN
clkbuf <= IFCLK;
IF(IFCLK'event AND IFCLK='1') THEN
IF(KEY3 = '0') THEN
led3buf <= '1';
CASE curwrstate IS
WHEN prepare => count1:=count1+1;sramcebuf <= '0';sramoebuf <= '0';
sramwebuf <= 'Z';sramlbbuf <= 'Z';sramubbuf <= 'Z';
IF(count1=1) THEN
curwrstate<=trswraddr;count1:=0;
ELSE
curwrstate<=prepare;
END IF;
WHEN trswraddr=>count1:=count1+1;
sramaddbuf<=conv_std_logic_vector(addwrbuf,18);
IF(count1=1) THEN
addwrbuf <= addwrbuf+1;
curwrstate<=wrdata;count1:=0;
ELSE
curwrstate<=trswraddr;
END IF;
WHEN wrdata =>count1:=count1+1;
IF(count1<2) THEN
sramwebuf <= '1';sramlbbuf <= '1';sramubbuf <= '1';
ELSIF(count1>2 AND count1<4) THEN
sramwebuf<='0';sramlbbuf<='0';sramubbuf<='0';
sramdatabuf<=data;
ELSIF(count1=5) THEN
sramwebuf<='1';sramlbbuf<='1';sramubbuf<='1';
sramdatabuf<="ZZZZZZZZZZZZZZZZ";
count1:=0;
count := count + 1;
IF(count<512) THEN
curwrstate<=prepare;
ELSE
curwrstate<=idel;
END IF;
END IF;
WHEN idel =>NULL;
WHEN others=>NULL;
END CASE;
ELSIF(KEY2 = '0') THEN
led2buf <= '1';
CASE currdstate IS
WHEN prepare => count1:=count1+1;sramcebuf <= '0';sramoebuf <= '0';
sramwebuf <= 'Z';sramlbbuf <= 'Z';sramubbuf <= 'Z';
IF(count1=1) THEN
currdstate<=trsrdaddr;count1:=0;
ELSE
currdstate<=prepare;
END IF;
WHEN trsrdaddr=>count1:=count1+1;
sramaddbuf<=conv_std_logic_vector(addrdbuf,18);
IF(count1=1) THEN
addrdbuf <= addrdbuf+1;
currdstate<=rddata;count1:=0;
ELSE
currdstate<=trsrdaddr;
END IF;
WHEN rddata =>count1:=count1+1;
IF(count1<2) THEN
sramwebuf <= '0';sramlbbuf <= '1';sramubbuf <= '1';
ELSIF(count1>2 AND count1<4) THEN
sramwebuf<='1';sramlbbuf<='0';sramubbuf<='0';
fifomemory(addrdbuf) <= to_bitvector(sramdatabuf);
ELSIF(count1 = 5) THEN
sramwebuf<='0';sramlbbuf<='0';sramubbuf<='0';
sramdatabuf<="ZZZZZZZZZZZZZZZZ";
count1:=0;
count := count + 1;
IF(count<512) THEN
currdstate<=prepare;
ELSE
currdstate<=idel;
END IF;
currdstate<=rdend;
END IF;
WHEN rdend => sramwebuf <= 'Z';sramlbbuf <= 'Z';sramubbuf <= 'Z';
count1:=0;
count := count + 1;
IF(count<512) THEN
currdstate<=prepare;
ELSE
currdstate<=idel;
END IF;
WHEN idel =>NULL;
WHEN others=>NULL;
END CASE;
ELSIF(KEY1 = '0') THEN
count1:=0;
addwrbuf <= 0;
addrdbuf <= 0;
sramaddbuf <= "000000000000000000";
led1buf <= '1';
led2buf <= '1';
led3buf <= '1';
led4buf <= '1';
ELSE
led1buf <= '1';
led2buf <= '0';
led3buf <= '0';
led4buf <= '0';
END IF;
ELSE
END IF;
END PROCESS;
END ARC_controlsys;
- 1
- 2
- 3
- 4
前往页