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

Subversion Repositories gpib_controller

[/] [gpib_controller/] [trunk/] [vhdl/] [src/] [gpib_helper/] [gpibReader.vhd] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 Andrewski
--------------------------------------------------------------------------------
2 13 Andrewski
--This file is part of fpga_gpib_controller.
3
--
4
-- Fpga_gpib_controller is free software: you can redistribute it and/or modify
5
-- it under the terms of the GNU General Public License as published by
6
-- the Free Software Foundation, either version 3 of the License, or
7
-- (at your option) any later version.
8
--
9
-- Fpga_gpib_controller is distributed in the hope that it will be useful,
10
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
-- GNU General Public License for more details.
13
 
14
-- You should have received a copy of the GNU General Public License
15
-- along with Fpga_gpib_controller.  If not, see <http://www.gnu.org/licenses/>.
16
--------------------------------------------------------------------------------
17 3 Andrewski
-- Entity: gpibReader
18
-- Date: 2011-10-30  
19 13 Andrewski
-- Author: Andrzej Paluch
20 3 Andrewski
--------------------------------------------------------------------------------
21
library ieee;
22
use ieee.std_logic_1164.all;
23
use ieee.std_logic_unsigned.all;
24
use ieee.std_logic_arith.all;
25
 
26
use work.utilPkg.all;
27
 
28
 
29
entity gpibReader is
30
        port (
31
                -- clock
32
                clk : in std_logic;
33
                -- reset
34
                reset : std_logic;
35
                ------------------------------------------------------------------------
36
                ------ GPIB interface --------------------------------------------------
37
                ------------------------------------------------------------------------
38
                -- input data
39
                data_in : in std_logic_vector (7 downto 0);
40
                -- data valid
41
                dvd : in std_logic;
42
                -- listener active
43
                lac : in std_logic;
44
                -- last byte
45
                lsb : in std_logic;
46
                -- ready to next byte
47
                rdy : out std_logic;
48
                ------------------------------------------------------------------------
49
                ------ external interface ----------------------------------------------
50
                ------------------------------------------------------------------------
51
                -- is LE function active
52
                isLE : in std_logic;
53
                -- current secondary address
54
                secAddr : in std_logic_vector (4 downto 0);
55
                -- secondary address of data
56
                dataSecAddr : out std_logic_vector (4 downto 0);
57
                -- buffer ready interrupt
58
                buf_interrupt : out std_logic;
59
                -- indicates end of stream
60
                end_of_stream : out std_logic;
61
                -- resets reader
62
                reset_reader : in std_logic;
63
                ------------------ fifo --------------------------------------
64
                -- indicates fifo full
65
                fifo_full : in std_logic;
66
                -- indicates fifo ready to write
67
                fifo_ready_to_write : in std_logic;
68
                -- indicates at least one byte in fifo
69
                at_least_one_byte_in_fifo : in std_logic;
70
                -- output data
71
                data_out : out std_logic_vector (7 downto 0);
72
                -- fifo strobe
73
                fifo_strobe : out std_logic
74
        );
75
end gpibReader;
76
 
77
architecture arch of gpibReader is
78
 
79
        -- reader states
80
        type READER_STATE is (
81
                ST_IDLE,
82
                ST_WAIT_DVD_1,
83
                ST_WAIT_DVD_0
84
        );
85
 
86
        signal current_state : READER_STATE;
87
        signal buf_ready_to_write : boolean;
88
 
89
begin
90
 
91
        buf_interrupt <= not to_stdl(buf_ready_to_write);
92
 
93
 
94
        process (clk, reset, reset_reader) begin
95
                if reset = '1' then
96
                        current_state <= ST_IDLE;
97
                        rdy <= '1';
98
                        buf_ready_to_write <= TRUE;
99
                        end_of_stream <= '0';
100
                        fifo_strobe <= '0';
101
                        dataSecAddr <= "00000";
102
                elsif reset_reader='1' then
103
                        buf_ready_to_write <= TRUE;
104
                        end_of_stream <= '0';
105
                        fifo_strobe <= '0';
106
                        dataSecAddr <= "00000";
107
                elsif rising_edge(clk) then
108
                        case current_state is
109
                                when ST_IDLE =>
110
                                        if lac='1' and buf_ready_to_write then
111
 
112
                                                if isLE = '1' then
113
                                                        dataSecAddr <= secAddr;
114
                                                end if;
115
 
116
                                                rdy <= '1';
117
                                                current_state <= ST_WAIT_DVD_1;
118
                                        elsif lac='0' and at_least_one_byte_in_fifo='1' then
119
                                                buf_ready_to_write <= FALSE;
120
                                        end if;
121
                                when ST_WAIT_DVD_1 =>
122
                                        if dvd='1' and fifo_ready_to_write='1' then
123
                                                fifo_strobe <= '1';
124
 
125
                                                data_out <= data_in;
126
 
127
                                                if lsb='1'or fifo_full='1' then
128
                                                        buf_ready_to_write <= FALSE;
129
                                                        end_of_stream <= lsb;
130
                                                end if;
131
 
132
                                                rdy <= '0';
133
                                                current_state <= ST_WAIT_DVD_0;
134
                                        elsif lac='0' then
135
                                                current_state <= ST_IDLE;
136
                                        end if;
137
                                when ST_WAIT_DVD_0 =>
138
                                        if dvd='0' then
139
                                                fifo_strobe <= '0';
140
                                                current_state <= ST_IDLE;
141
                                        end if;
142
                                when others =>
143
                                        current_state <= ST_IDLE;
144
                        end case;
145
                end if;
146
        end process;
147
 
148
end arch;
149
 

powered by: WebSVN 2.1.0

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