--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
|
--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/>.
|
|
--------------------------------------------------------------------------------
|
-- Entity: gpibReader
|
-- Entity: gpibReader
|
-- Date: 2011-10-30
|
-- Date: 2011-10-30
|
-- Author: apaluch
|
-- Author: Andrzej Paluch
|
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_unsigned.all;
|
use ieee.std_logic_arith.all;
|
use ieee.std_logic_arith.all;
|
|
|
use work.utilPkg.all;
|
use work.utilPkg.all;
|
|
|
|
|
entity gpibReader is
|
entity gpibReader is
|
port (
|
port (
|
-- clock
|
-- clock
|
clk : in std_logic;
|
clk : in std_logic;
|
-- reset
|
-- reset
|
reset : std_logic;
|
reset : std_logic;
|
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
------ GPIB interface --------------------------------------------------
|
------ GPIB interface --------------------------------------------------
|
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
-- input data
|
-- input data
|
data_in : in std_logic_vector (7 downto 0);
|
data_in : in std_logic_vector (7 downto 0);
|
-- data valid
|
-- data valid
|
dvd : in std_logic;
|
dvd : in std_logic;
|
-- listener active
|
-- listener active
|
lac : in std_logic;
|
lac : in std_logic;
|
-- last byte
|
-- last byte
|
lsb : in std_logic;
|
lsb : in std_logic;
|
-- ready to next byte
|
-- ready to next byte
|
rdy : out std_logic;
|
rdy : out std_logic;
|
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
------ external interface ----------------------------------------------
|
------ external interface ----------------------------------------------
|
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
-- is LE function active
|
-- is LE function active
|
isLE : in std_logic;
|
isLE : in std_logic;
|
-- current secondary address
|
-- current secondary address
|
secAddr : in std_logic_vector (4 downto 0);
|
secAddr : in std_logic_vector (4 downto 0);
|
-- secondary address of data
|
-- secondary address of data
|
dataSecAddr : out std_logic_vector (4 downto 0);
|
dataSecAddr : out std_logic_vector (4 downto 0);
|
-- buffer ready interrupt
|
-- buffer ready interrupt
|
buf_interrupt : out std_logic;
|
buf_interrupt : out std_logic;
|
-- indicates end of stream
|
-- indicates end of stream
|
end_of_stream : out std_logic;
|
end_of_stream : out std_logic;
|
-- resets reader
|
-- resets reader
|
reset_reader : in std_logic;
|
reset_reader : in std_logic;
|
------------------ fifo --------------------------------------
|
------------------ fifo --------------------------------------
|
-- indicates fifo full
|
-- indicates fifo full
|
fifo_full : in std_logic;
|
fifo_full : in std_logic;
|
-- indicates fifo ready to write
|
-- indicates fifo ready to write
|
fifo_ready_to_write : in std_logic;
|
fifo_ready_to_write : in std_logic;
|
-- indicates at least one byte in fifo
|
-- indicates at least one byte in fifo
|
at_least_one_byte_in_fifo : in std_logic;
|
at_least_one_byte_in_fifo : in std_logic;
|
-- output data
|
-- output data
|
data_out : out std_logic_vector (7 downto 0);
|
data_out : out std_logic_vector (7 downto 0);
|
-- fifo strobe
|
-- fifo strobe
|
fifo_strobe : out std_logic
|
fifo_strobe : out std_logic
|
);
|
);
|
end gpibReader;
|
end gpibReader;
|
|
|
architecture arch of gpibReader is
|
architecture arch of gpibReader is
|
|
|
-- reader states
|
-- reader states
|
type READER_STATE is (
|
type READER_STATE is (
|
ST_IDLE,
|
ST_IDLE,
|
ST_WAIT_DVD_1,
|
ST_WAIT_DVD_1,
|
ST_WAIT_DVD_0
|
ST_WAIT_DVD_0
|
);
|
);
|
|
|
signal current_state : READER_STATE;
|
signal current_state : READER_STATE;
|
signal buf_ready_to_write : boolean;
|
signal buf_ready_to_write : boolean;
|
|
|
begin
|
begin
|
|
|
buf_interrupt <= not to_stdl(buf_ready_to_write);
|
buf_interrupt <= not to_stdl(buf_ready_to_write);
|
|
|
|
|
process (clk, reset, reset_reader) begin
|
process (clk, reset, reset_reader) begin
|
if reset = '1' then
|
if reset = '1' then
|
current_state <= ST_IDLE;
|
current_state <= ST_IDLE;
|
rdy <= '1';
|
rdy <= '1';
|
buf_ready_to_write <= TRUE;
|
buf_ready_to_write <= TRUE;
|
end_of_stream <= '0';
|
end_of_stream <= '0';
|
fifo_strobe <= '0';
|
fifo_strobe <= '0';
|
dataSecAddr <= "00000";
|
dataSecAddr <= "00000";
|
elsif reset_reader='1' then
|
elsif reset_reader='1' then
|
buf_ready_to_write <= TRUE;
|
buf_ready_to_write <= TRUE;
|
end_of_stream <= '0';
|
end_of_stream <= '0';
|
fifo_strobe <= '0';
|
fifo_strobe <= '0';
|
dataSecAddr <= "00000";
|
dataSecAddr <= "00000";
|
elsif rising_edge(clk) then
|
elsif rising_edge(clk) then
|
case current_state is
|
case current_state is
|
when ST_IDLE =>
|
when ST_IDLE =>
|
if lac='1' and buf_ready_to_write then
|
if lac='1' and buf_ready_to_write then
|
|
|
if isLE = '1' then
|
if isLE = '1' then
|
dataSecAddr <= secAddr;
|
dataSecAddr <= secAddr;
|
end if;
|
end if;
|
|
|
rdy <= '1';
|
rdy <= '1';
|
current_state <= ST_WAIT_DVD_1;
|
current_state <= ST_WAIT_DVD_1;
|
elsif lac='0' and at_least_one_byte_in_fifo='1' then
|
elsif lac='0' and at_least_one_byte_in_fifo='1' then
|
buf_ready_to_write <= FALSE;
|
buf_ready_to_write <= FALSE;
|
end if;
|
end if;
|
when ST_WAIT_DVD_1 =>
|
when ST_WAIT_DVD_1 =>
|
if dvd='1' and fifo_ready_to_write='1' then
|
if dvd='1' and fifo_ready_to_write='1' then
|
fifo_strobe <= '1';
|
fifo_strobe <= '1';
|
|
|
data_out <= data_in;
|
data_out <= data_in;
|
|
|
if lsb='1'or fifo_full='1' then
|
if lsb='1'or fifo_full='1' then
|
buf_ready_to_write <= FALSE;
|
buf_ready_to_write <= FALSE;
|
end_of_stream <= lsb;
|
end_of_stream <= lsb;
|
end if;
|
end if;
|
|
|
rdy <= '0';
|
rdy <= '0';
|
current_state <= ST_WAIT_DVD_0;
|
current_state <= ST_WAIT_DVD_0;
|
elsif lac='0' then
|
elsif lac='0' then
|
current_state <= ST_IDLE;
|
current_state <= ST_IDLE;
|
end if;
|
end if;
|
when ST_WAIT_DVD_0 =>
|
when ST_WAIT_DVD_0 =>
|
if dvd='0' then
|
if dvd='0' then
|
fifo_strobe <= '0';
|
fifo_strobe <= '0';
|
current_state <= ST_IDLE;
|
current_state <= ST_IDLE;
|
end if;
|
end if;
|
when others =>
|
when others =>
|
current_state <= ST_IDLE;
|
current_state <= ST_IDLE;
|
end case;
|
end case;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
end arch;
|
end arch;
|
|
|
|
|