|
|
楼主 |
发表于 2003-8-30 11:58:25
|
显示全部楼层
能不能解释下面的warning!!
我是用三态来做的啊!!
程序贴给你们看不过风格不好哦!!请指教
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity monitor is
port( RESET :in std_logic;
CLK16x :in std_logic;
SCL :in std_logic;
SDA :inout std_logic;
IOWB ut std_logic;
IORB ut std_logic;
INT0 ut std_logic; --interrupt padtest port
SA :out std_logic_vector(7 downto 0);
DATA :out std_logic_vector(7 downto 0);---test port
SD :inout std_logic_vector(7 downto 0));
end monitor;
architecture rtl of monitor is
type state is (start_r,shift_r,ack_r);
signal rx_states : state;
type states is (S0,S1,S2,S3);
signal next_state :states;
signal REG :std_logic_vector(7 downto 0);
signal DATAR :std_logic_vector(7 downto 0);
signal ADDR :std_logic_vector(7 downto 0);
signal SDA1 :std_logic;
signal SCL1 :std_logic;
signal startb :std_logic;
signal stopb :std_logic;
signal datab :std_logic; ---receive continous data signal
signal start :std_logic;
signal COUNT :std_logic_vector(3 downto 0);
signal cnt :std_logic_vector(1 downto 0);
signal RIDE :std_logic;
signal FIDE :std_logic;
signal DRIDE :std_logic;
signal DFIDE :std_logic;
signal WCTR :std_logic;
signal RCTR :std_logic;
signal DEN :std_logic;
signal cnt2 :std_logic_vector(4 downto 0);
signal ACK :std_logic;
signal WEN :std_logic;
signal REN :std_logic;
signal databr :std_logic;
signal IORB0 :std_logic;
signal IOWB0 :std_logic;
signal cnt3 :std_logic_vector(2 downto 0);
signal AEN :std_logic;
-- signal doutr :std_logic_vector(7 downto 0);
begin
process(CLK16x,RESET,cnt)
begin
if RESET='0' then
startb<='0';
datab<='0';
start<='0';
cnt<="00";
stopb<='0';
REN<='0';
WEN<='0';
databr<='0';
elsif CLK16x'event and CLK16x='1' then
if SCL1='1' and FIDE='1' then --monitor start bit
startb<='1';
stopb<='0';
datab<='0';
databr<='0';
elsif SCL1='1' and RIDE='1' then --monitor stop bit
startb<='0';
stopb<='1';
databr<='0';
elsif COUNT="1000" and REG="10110000"
and startb='1' then -- device address B0
datab<='1';
databr<='1';
startb<='0';
end if;
--// after writing B0 and judge the read or write signal
if datab='1' and REG="10100001"
and start='1' then --the condition of read strobe signal (A1)
REN<='1';
WEN<='0';
datab<='0';
elsif datab='1' and REG="10100000"
and start='1' then-- the condition of write strobe signal (A0)
WEN<='1';
REN<='0';
datab<='0';
elsif stopb='1' or startb='1' then
WEN<='0';
REN<='0';
end if;
if databr='1' and COUNT="1001" and DRIDE='1' then
-- the condition of receive the data from I2C
start<='1';
else
start<='0';
end if;
if WEN='1' and COUNT="1001" and DRIDE='1' then
cnt<=cnt+1;
end if;
end if;
end process;
process(CLK16x,RESET,rx_states) --- receive the data
begin
if RESET='0' then
rx_states<=start_r;
COUNT<="0010";
REG<=(others=>'0');
elsif CLK16x'event and CLK16x='1' then
if stopb='1' then
rx_states<=start_r;
end if;
case rx_states is
when start_r=>
if (startb='1' and DRIDE='1' ) or start='1' then
COUNT<="0000";
rx_states<=shift_r;
else rx_states<=start_r;
end if;
when shift_r=>
if DFIDE='1' then --SCL1='1' and
COUNT<=COUNT+1; if COUNT<"1000" then
rx_states<=shift_r;
REG<=REG(6 downto 0)&SDA; ---first MSB else
rx_states<=ack_r;
end if;
end if;
when ack_r=>
if (COUNT="1001" and DRIDE='1') then
rx_states<=start_r;
end if;
end case;
end if;
end process;
process(CLK16x,RESET,SDA,SCL)
begin
if RESET='0' then
SDA1<='1';
SCL1<='1';
RIDE<='0';
FIDE<='0';
DRIDE<='0';
DFIDE<='0';
ACK<='0';
elsif CLK16x'event and CLK16x='1' then
SCL1<=SCL;
SDA1<=SDA;
if COUNT="1000" then--and DRIDE='1' then
ACK<='1';
else--if COUNT="1000" and DFIDE='1' then --question
ACK<='0';
end if;
if (SDA1='1' and SDA='0') then ---the falling of the SDA
FIDE<='1';
RIDE<='0';
elsif (SDA1='0' and SDA='1') then ---the rising of the SDA
RIDE<='1';
FIDE<='0';
else
RIDE<='0';
FIDE<='0';
end if;
if SCL1='0' and SCL='1' then --- the rising of the SCL
DRIDE<='1';
DFIDE<='0';
elsif SCL1='1' and SCL='0' then --- the falling of the SCL
DRIDE<='0';
DFIDE<='1';
else
DRIDE<='0';
DFIDE<='0';
end if;
end if;
end process;
process(RESET,CLK16x,WEN,REN,DFIDE,COUNT,cnt,REG,WCTR,RCTR,next_state,cnt2)
begin
if RESET='0' then
next_state<=S0;
IOWB0<='1';
IORB0<='1';
RCTR<='0';
WCTR<='0';
DATAR<=(others=>'0');
ADDR<=(others=>'0');
DATA<=(others=>'0');
-- SA<=(others=>'0');
INT0<='1';
cnt2<="00000";
DEN<='0';
AEN<='0';
cnt3<=(others=>'0');
elsif CLK16x'event and CLK16x='1' then
---generate enable signal to write or read
if WEN='1' and DFIDE='1' and COUNT="1000" and cnt(0)='0' then
ADDR<=REG;
DATAR<=(others=>'Z');
WCTR<='0';
RCTR<='0';
elsif WEN='1' and DFIDE='1' and COUNT="1000" and cnt(0)='1' then
DATAR<=REG;
WCTR<='1';
RCTR<='0';
elsif REN='1' and DFIDE='1' and COUNT="1000" then
ADDR<=REG;
DATAR<=(others=>'Z');
RCTR<='1';
WCTR<='0';
elsif stopb='1' then
DATAR<=(others=>'0');
end if;
if REN='1' and cnt2="00011" then--cnt2="01100" then
DATA<=SD; ----问题在这里
--elsif stopb='1' then
-- DATA<=(others=>'0');
end if;
--DATA<=doutr;
--- the machine is generated to write or read of ISA
case next_state is
when S0=> --SA<=(others=>'Z');
-- SA<=ADDR;
DEN<='0';
if WCTR='1' or RCTR='1' then next_state<=S1; cnt2<=(others=>'0');
cnt3<=(others=>'0');
else
AEN<='0';
next_state<=S0;
end if;
when S1=>
cnt3<=cnt3+1;
if cnt3="111" then
next_state<=S2;
else
WCTR<='0';
RCTR<='0';
AEN<='1';
next_state<=S1;
end if;
when S2=>
next_state<=S3;
if REN='1' then
IORB0<='0';
DEN<='0';
elsif WEN='1' then
IOWB0<='0';
DEN<='1'; end if;
when S3=>
cnt2<=cnt2+1;
if REN='1' and cnt2="01100" then
INT0<='0';
elsif cnt2="11111" then INT0<='1';
IORB0<='1';
IOWB0<='1';
next_state<=S0;
else
next_state<=S3;
end if;
end case;
end if;
end process;
SD<=DATAR when (DEN='1' ) else "ZZZZZZZZ";
SDA <='0' when (ACK = '1') else 'Z';
IORB<='0' when (IORB0='0') else 'Z';
IOWB<='0' when (IOWB0='0') else 'Z';
SA<=ADDR when (AEN='1') else "ZZZZZZZZ";
end rtl; |
|