|
--------------------------------------------------------------------------------
|
|
--This file is part of fpga_gpib_controller.
|
|
--
|
|
-- Fpga_gpib_controller is free software: you can redistribute it and/or modify
|
|
-- it under the terms of the GNU General Public License as published by
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
|
-- (at your option) any later version.
|
|
--
|
|
-- Fpga_gpib_controller is distributed in the hope that it will be useful,
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
-- GNU General Public License for more details.
|
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
-- along with Fpga_gpib_controller. If not, see <http://www.gnu.org/licenses/>.
|
----------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------
|
-- Company:
|
-- Author: Andrzej Paluch
|
-- Engineer:
|
|
--
|
--
|
-- Create Date: 01:04:57 10/01/2011
|
-- Create Date: 01:04:57 10/01/2011
|
-- Design Name:
|
-- Design Name:
|
-- Module Name: if_func_AH - Behavioral
|
-- Module Name: if_func_AH - Behavioral
|
-- Project Name:
|
-- Project Name:
|
-- Target Devices:
|
-- Target Devices:
|
-- Tool versions:
|
-- Tool versions:
|
-- Description:
|
-- Description:
|
--
|
--
|
-- Dependencies:
|
-- Dependencies:
|
--
|
--
|
-- Revision:
|
-- Revision:
|
-- Revision 0.01 - File Created
|
-- Revision 0.01 - File Created
|
-- Additional Comments:
|
-- Additional Comments:
|
--
|
--
|
----------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------
|
library IEEE;
|
library IEEE;
|
use IEEE.STD_LOGIC_1164.ALL;
|
use IEEE.STD_LOGIC_1164.ALL;
|
|
|
use work.utilPkg.all;
|
use work.utilPkg.all;
|
|
|
|
|
entity if_func_AH is
|
entity if_func_AH is
|
port(
|
port(
|
-- device inputs
|
-- device inputs
|
clk : in std_logic; -- clock
|
clk : in std_logic; -- clock
|
pon : in std_logic; -- power on
|
pon : in std_logic; -- power on
|
rdy : in std_logic; -- ready for next message
|
rdy : in std_logic; -- ready for next message
|
tcs : in std_logic; -- take control synchronously
|
tcs : in std_logic; -- take control synchronously
|
-- state inputs
|
-- state inputs
|
LACS : in std_logic; -- listener active state
|
LACS : in std_logic; -- listener active state
|
LADS : in std_logic; -- listener addressed state
|
LADS : in std_logic; -- listener addressed state
|
-- interface inputs
|
-- interface inputs
|
ATN : in std_logic; -- attention
|
ATN : in std_logic; -- attention
|
DAV : in std_logic; -- data accepted
|
DAV : in std_logic; -- data accepted
|
-- interface outputs
|
-- interface outputs
|
RFD : out std_logic; -- ready for data
|
RFD : out std_logic; -- ready for data
|
DAC : out std_logic; -- data accepted
|
DAC : out std_logic; -- data accepted
|
-- reported state
|
-- reported state
|
ANRS : out std_logic; -- acceptor not ready state
|
ANRS : out std_logic; -- acceptor not ready state
|
ACDS : out std_logic -- accept data state
|
ACDS : out std_logic -- accept data state
|
);
|
);
|
end if_func_AH;
|
end if_func_AH;
|
|
|
architecture Behavioral of if_func_AH is
|
architecture Behavioral of if_func_AH is
|
|
|
-- states
|
-- states
|
type AH_STATE is (
|
type AH_STATE is (
|
-- acceptor idle state
|
-- acceptor idle state
|
ST_AIDS,
|
ST_AIDS,
|
-- acceptor not ready state
|
-- acceptor not ready state
|
ST_ANRS,
|
ST_ANRS,
|
-- acceptor ready state
|
-- acceptor ready state
|
ST_ACRS,
|
ST_ACRS,
|
-- acceptor wait for new cycle state
|
-- acceptor wait for new cycle state
|
ST_AWNS,
|
ST_AWNS,
|
-- accept data state
|
-- accept data state
|
ST_ACDS
|
ST_ACDS
|
);
|
);
|
|
|
-- current state
|
-- current state
|
signal current_state : AH_STATE;
|
signal current_state : AH_STATE;
|
|
|
-- events
|
-- events
|
signal event1, event2, event3, event4, event5, event6, event7 : boolean;
|
signal event1, event2, event3, event4, event5, event6, event7 : boolean;
|
|
|
-- timers
|
-- timers
|
constant TIMER_T3_MAX : integer := 3;
|
constant TIMER_T3_MAX : integer := 3;
|
constant TIMER_T3_TIMEOUT : integer := 2;
|
constant TIMER_T3_TIMEOUT : integer := 2;
|
signal timerT3 : integer range 0 to TIMER_T3_MAX;
|
signal timerT3 : integer range 0 to TIMER_T3_MAX;
|
signal timerT3Expired : boolean;
|
signal timerT3Expired : boolean;
|
|
|
begin
|
begin
|
|
|
-- state machine process
|
-- state machine process
|
process(pon, clk) begin
|
process(pon, clk) begin
|
if pon = '1' then
|
if pon = '1' then
|
current_state <= ST_AIDS;
|
current_state <= ST_AIDS;
|
elsif rising_edge(clk) then
|
elsif rising_edge(clk) then
|
case current_state is
|
case current_state is
|
------------------
|
------------------
|
when ST_AIDS =>
|
when ST_AIDS =>
|
if event2 then
|
if event2 then
|
-- no state change
|
-- no state change
|
elsif event1 then
|
elsif event1 then
|
current_state <= ST_ANRS;
|
current_state <= ST_ANRS;
|
end if;
|
end if;
|
------------------
|
------------------
|
when ST_ANRS =>
|
when ST_ANRS =>
|
if event2 then
|
if event2 then
|
current_state <= ST_AIDS;
|
current_state <= ST_AIDS;
|
elsif event4 then
|
elsif event4 then
|
current_state <= ST_ACRS;
|
current_state <= ST_ACRS;
|
end if;
|
end if;
|
------------------
|
------------------
|
when ST_ACRS =>
|
when ST_ACRS =>
|
if event2 then
|
if event2 then
|
current_state <= ST_AIDS;
|
current_state <= ST_AIDS;
|
elsif event5 then
|
elsif event5 then
|
current_state <= ST_ANRS;
|
current_state <= ST_ANRS;
|
elsif event6 then
|
elsif event6 then
|
timerT3 <= 0;
|
timerT3 <= 0;
|
current_state <= ST_ACDS;
|
current_state <= ST_ACDS;
|
end if;
|
end if;
|
------------------
|
------------------
|
when ST_ACDS =>
|
when ST_ACDS =>
|
if event2 then
|
if event2 then
|
current_state <= ST_AIDS;
|
current_state <= ST_AIDS;
|
elsif event3 then
|
elsif event3 then
|
current_state <= ST_AWNS;
|
current_state <= ST_AWNS;
|
end if;
|
end if;
|
|
|
if timerT3 < TIMER_T3_MAX then
|
if timerT3 < TIMER_T3_MAX then
|
timerT3 <= timerT3 + 1;
|
timerT3 <= timerT3 + 1;
|
end if;
|
end if;
|
------------------
|
------------------
|
when ST_AWNS =>
|
when ST_AWNS =>
|
if event2 then
|
if event2 then
|
current_state <= ST_AIDS;
|
current_state <= ST_AIDS;
|
elsif event7 then
|
elsif event7 then
|
current_state <= ST_ANRS;
|
current_state <= ST_ANRS;
|
end if;
|
end if;
|
------------------
|
------------------
|
when others =>
|
when others =>
|
current_state <= ST_AIDS;
|
current_state <= ST_AIDS;
|
end case;
|
end case;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
|
|
-- events
|
-- events
|
event1 <= ATN='1' or LACS='1' or LADS='1';
|
event1 <= ATN='1' or LACS='1' or LADS='1';
|
event2 <= not(ATN='1' or LACS='1' or LADS='1');
|
event2 <= not(ATN='1' or LACS='1' or LADS='1');
|
event3 <= (rdy='0' and ATN='0') or (timerT3Expired and ATN='1');
|
event3 <= (rdy='0' and ATN='0') or (timerT3Expired and ATN='1');
|
event4 <= (ATN='1' or rdy='1') and tcs='0';
|
event4 <= (ATN='1' or rdy='1') and tcs='0';
|
event5 <= not (ATN='1' or rdy='1');
|
event5 <= not (ATN='1' or rdy='1');
|
event6 <= DAV = '1';
|
event6 <= DAV = '1';
|
event7 <= DAV = '0';
|
event7 <= DAV = '0';
|
|
|
-- timers
|
-- timers
|
timerT3Expired <= timerT3 >= TIMER_T3_TIMEOUT;
|
timerT3Expired <= timerT3 >= TIMER_T3_TIMEOUT;
|
|
|
RFD <= to_stdl(
|
RFD <= to_stdl(
|
current_state = ST_AIDS or
|
current_state = ST_AIDS or
|
current_state = ST_ACRS
|
current_state = ST_ACRS
|
);
|
);
|
|
|
DAC <= to_stdl(
|
DAC <= to_stdl(
|
current_state = ST_AIDS or
|
current_state = ST_AIDS or
|
current_state = ST_AWNS
|
current_state = ST_AWNS
|
);
|
);
|
|
|
ACDS <= to_stdl(current_state = ST_ACDS);
|
ACDS <= to_stdl(current_state = ST_ACDS);
|
ANRS <= to_stdl(current_state = ST_ANRS);
|
ANRS <= to_stdl(current_state = ST_ANRS);
|
|
|
end Behavioral;
|
end Behavioral;
|
|
|
|
|