OpenCores
URL https://opencores.org/ocsvn/gpib_controller/gpib_controller/trunk

Subversion Repositories gpib_controller

[/] [gpib_controller/] [trunk/] [vhdl/] [src/] [gpib_helper/] [gpibWriter.vhd] - Diff between revs 3 and 13

Only display areas with differences | Details | Blame | View Log

Rev 3 Rev 13
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 
--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: gpibWriter
-- Entity: gpibWriter
-- Date: 2011-11-01
-- Date: 2011-11-01
-- 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 gpibWriter is
entity gpibWriter 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 --------------------------------------------------
                ------------------------------------------------------------------------
                ------------------------------------------------------------------------
                -- output data
                -- output data
                data_out : out std_logic_vector (7 downto 0);
                data_out : out std_logic_vector (7 downto 0);
                -- wait for new cycle
                -- wait for new cycle
                wnc : in std_logic;
                wnc : in std_logic;
                -- seriall poll active
                -- seriall poll active
                spa : in std_logic;
                spa : in std_logic;
                -- new byte available
                -- new byte available
                nba : out std_logic;
                nba : out std_logic;
                -- end of string
                -- end of string
                endOf : out std_logic;
                endOf : out std_logic;
                -- talker active
                -- talker active
                tac : in std_logic;
                tac : in std_logic;
                -- controller write command
                -- controller write command
                cwrc : in std_logic;
                cwrc : in std_logic;
                ------------------------------------------------------------------------
                ------------------------------------------------------------------------
                ------ external interface ----------------------------------------------
                ------ external interface ----------------------------------------------
                ------------------------------------------------------------------------
                ------------------------------------------------------------------------
                -- TE is extended
                -- TE is extended
                isTE : in std_logic;
                isTE : 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 : in std_logic_vector (4 downto 0);
                dataSecAddr : in std_logic_vector (4 downto 0);
                -- buffer consumed
                -- buffer consumed
                buf_interrupt : out std_logic;
                buf_interrupt : out std_logic;
                -- indicates end of stream
                -- indicates end of stream
                end_of_stream : in std_logic;
                end_of_stream : in std_logic;
                -- resets writer
                -- resets writer
                reset_writer : in std_logic;
                reset_writer : in std_logic;
                -- enables writer
                -- enables writer
                writer_enable : in std_logic;
                writer_enable : in std_logic;
                ---------------- fifo ---------------------------
                ---------------- fifo ---------------------------
                availableFifoBytesCount : in std_logic_vector(10 downto 0);
                availableFifoBytesCount : in std_logic_vector(10 downto 0);
                -- fifo read strobe
                -- fifo read strobe
                fifo_read_strobe : out std_logic;
                fifo_read_strobe : out std_logic;
                -- indicates fifo ready to read
                -- indicates fifo ready to read
                fifo_ready_to_read : in std_logic;
                fifo_ready_to_read : in std_logic;
                -- input data
                -- input data
                fifo_data_in : in std_logic_vector (7 downto 0)
                fifo_data_in : in std_logic_vector (7 downto 0)
        );
        );
end gpibWriter;
end gpibWriter;
 
 
architecture arch of gpibWriter is
architecture arch of gpibWriter is
 
 
        -- writer states
        -- writer states
        type WRITER_STATE is (
        type WRITER_STATE is (
                ST_IDLE,
                ST_IDLE,
                ST_WAIT_WNC_1,
                ST_WAIT_WNC_1,
                ST_WAIT_WNC_0
                ST_WAIT_WNC_0
        );
        );
 
 
 
 
        signal current_state : WRITER_STATE;
        signal current_state : WRITER_STATE;
        -- triggered by spa
        -- triggered by spa
        signal tr_by_spa : std_logic;
        signal tr_by_spa : std_logic;
        signal readyToSend : boolean;
        signal readyToSend : boolean;
        signal at_least_one_byte_in_fifo : boolean;
        signal at_least_one_byte_in_fifo : boolean;
 
 
begin
begin
 
 
        buf_interrupt <= to_stdl(not at_least_one_byte_in_fifo);
        buf_interrupt <= to_stdl(not at_least_one_byte_in_fifo);
        data_out <= fifo_data_in;
        data_out <= fifo_data_in;
        at_least_one_byte_in_fifo <= availableFifoBytesCount /= "000000000000";
        at_least_one_byte_in_fifo <= availableFifoBytesCount /= "000000000000";
 
 
        readyToSend <=
        readyToSend <=
                (
                (
                                writer_enable = '1'
                                writer_enable = '1'
                        and
                        and
                                at_least_one_byte_in_fifo
                                at_least_one_byte_in_fifo
                        and
                        and
                        (
                        (
                                (
                                (
                                        tac='1'
                                        tac='1'
                                        and
                                        and
                                        (
                                        (
                                                (isTE='1' and dataSecAddr=secAddr)
                                                (isTE='1' and dataSecAddr=secAddr)
                                                or
                                                or
                                                isTE='0'
                                                isTE='0'
                                        )
                                        )
                                )
                                )
                                or
                                or
                                cwrc='1'
                                cwrc='1'
                        )
                        )
                        and
                        and
                        fifo_ready_to_read='1'
                        fifo_ready_to_read='1'
                )
                )
                or
                or
                spa='1';
                spa='1';
 
 
        process (clk, reset, reset_writer) begin
        process (clk, reset, reset_writer) begin
                if reset = '1' or reset_writer = '1' then
                if reset = '1' or reset_writer = '1' then
                        nba <= '0';
                        nba <= '0';
                        endOf <= '0';
                        endOf <= '0';
                        fifo_read_strobe <= '0';
                        fifo_read_strobe <= '0';
                        tr_by_spa <= '0';
                        tr_by_spa <= '0';
                        current_state <= ST_IDLE;
                        current_state <= ST_IDLE;
                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 readyToSend then
                                        if readyToSend then
                                                nba <= '1';
                                                nba <= '1';
 
 
                                                tr_by_spa <= spa;
                                                tr_by_spa <= spa;
 
 
                                                if availableFifoBytesCount="000000000001" and
                                                if availableFifoBytesCount="000000000001" and
                                                                end_of_stream='1' and spa='0' and tac='1' and
                                                                end_of_stream='1' and spa='0' and tac='1' and
                                                                cwrc='0' then
                                                                cwrc='0' then
                                                        endOf <= '1';
                                                        endOf <= '1';
                                                end if;
                                                end if;
 
 
                                                current_state <= ST_WAIT_WNC_1;
                                                current_state <= ST_WAIT_WNC_1;
                                        end if;
                                        end if;
                                when ST_WAIT_WNC_1 =>
                                when ST_WAIT_WNC_1 =>
                                        if wnc='1' then
                                        if wnc='1' then
                                                nba <= '0';
                                                nba <= '0';
 
 
                                                if tr_by_spa='0' then
                                                if tr_by_spa='0' then
                                                        endOf <= '0';
                                                        endOf <= '0';
                                                        fifo_read_strobe <= '1';
                                                        fifo_read_strobe <= '1';
                                                end if;
                                                end if;
 
 
                                                current_state <= ST_WAIT_WNC_0;
                                                current_state <= ST_WAIT_WNC_0;
                                        end if;
                                        end if;
                                when ST_WAIT_WNC_0 =>
                                when ST_WAIT_WNC_0 =>
                                        if wnc='0' then
                                        if wnc='0' then
                                                if tr_by_spa='0' then
                                                if tr_by_spa='0' then
                                                        fifo_read_strobe <= '0';
                                                        fifo_read_strobe <= '0';
                                                end if;
                                                end if;
 
 
                                                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;
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.