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

Subversion Repositories gpib_controller

[/] [gpib_controller/] [trunk/] [vhdl/] [src/] [gpib_helper/] [gpibWriter.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: gpibWriter
18
-- Date: 2011-11-01
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 gpibWriter is
30
        port (
31
                -- clock
32
                clk : in std_logic;
33
                -- reset
34
                reset : std_logic;
35
                ------------------------------------------------------------------------
36
                ------ GPIB interface --------------------------------------------------
37
                ------------------------------------------------------------------------
38
                -- output data
39
                data_out : out std_logic_vector (7 downto 0);
40
                -- wait for new cycle
41
                wnc : in std_logic;
42
                -- seriall poll active
43
                spa : in std_logic;
44
                -- new byte available
45
                nba : out std_logic;
46
                -- end of string
47
                endOf : out std_logic;
48
                -- talker active
49
                tac : in std_logic;
50
                -- controller write command
51
                cwrc : in std_logic;
52
                ------------------------------------------------------------------------
53
                ------ external interface ----------------------------------------------
54
                ------------------------------------------------------------------------
55
                -- TE is extended
56
                isTE : in std_logic;
57
                -- current secondary address
58
                secAddr : in std_logic_vector (4 downto 0);
59
                -- secondary address of data
60
                dataSecAddr : in std_logic_vector (4 downto 0);
61
                -- buffer consumed
62
                buf_interrupt : out std_logic;
63
                -- indicates end of stream
64
                end_of_stream : in std_logic;
65
                -- resets writer
66
                reset_writer : in std_logic;
67
                -- enables writer
68
                writer_enable : in std_logic;
69
                ---------------- fifo ---------------------------
70
                availableFifoBytesCount : in std_logic_vector(10 downto 0);
71
                -- fifo read strobe
72
                fifo_read_strobe : out std_logic;
73
                -- indicates fifo ready to read
74
                fifo_ready_to_read : in std_logic;
75
                -- input data
76
                fifo_data_in : in std_logic_vector (7 downto 0)
77
        );
78
end gpibWriter;
79
 
80
architecture arch of gpibWriter is
81
 
82
        -- writer states
83
        type WRITER_STATE is (
84
                ST_IDLE,
85
                ST_WAIT_WNC_1,
86
                ST_WAIT_WNC_0
87
        );
88
 
89
 
90
        signal current_state : WRITER_STATE;
91
        -- triggered by spa
92
        signal tr_by_spa : std_logic;
93
        signal readyToSend : boolean;
94
        signal at_least_one_byte_in_fifo : boolean;
95
 
96
begin
97
 
98
        buf_interrupt <= to_stdl(not at_least_one_byte_in_fifo);
99
        data_out <= fifo_data_in;
100
        at_least_one_byte_in_fifo <= availableFifoBytesCount /= "000000000000";
101
 
102
        readyToSend <=
103
                (
104
                                writer_enable = '1'
105
                        and
106
                                at_least_one_byte_in_fifo
107
                        and
108
                        (
109
                                (
110
                                        tac='1'
111
                                        and
112
                                        (
113
                                                (isTE='1' and dataSecAddr=secAddr)
114
                                                or
115
                                                isTE='0'
116
                                        )
117
                                )
118
                                or
119
                                cwrc='1'
120
                        )
121
                        and
122
                        fifo_ready_to_read='1'
123
                )
124
                or
125
                spa='1';
126
 
127
        process (clk, reset, reset_writer) begin
128
                if reset = '1' or reset_writer = '1' then
129
                        nba <= '0';
130
                        endOf <= '0';
131
                        fifo_read_strobe <= '0';
132
                        tr_by_spa <= '0';
133
                        current_state <= ST_IDLE;
134
                elsif rising_edge(clk) then
135
                        case current_state is
136
                                when ST_IDLE =>
137
                                        if readyToSend then
138
                                                nba <= '1';
139
 
140
                                                tr_by_spa <= spa;
141
 
142
                                                if availableFifoBytesCount="000000000001" and
143
                                                                end_of_stream='1' and spa='0' and tac='1' and
144
                                                                cwrc='0' then
145
                                                        endOf <= '1';
146
                                                end if;
147
 
148
                                                current_state <= ST_WAIT_WNC_1;
149
                                        end if;
150
                                when ST_WAIT_WNC_1 =>
151
                                        if wnc='1' then
152
                                                nba <= '0';
153
 
154
                                                if tr_by_spa='0' then
155
                                                        endOf <= '0';
156
                                                        fifo_read_strobe <= '1';
157
                                                end if;
158
 
159
                                                current_state <= ST_WAIT_WNC_0;
160
                                        end if;
161
                                when ST_WAIT_WNC_0 =>
162
                                        if wnc='0' then
163
                                                if tr_by_spa='0' then
164
                                                        fifo_read_strobe <= '0';
165
                                                end if;
166
 
167
                                                current_state <= ST_IDLE;
168
                                        end if;
169
                                when others =>
170
                                        current_state <= ST_IDLE;
171
                        end case;
172
                end if;
173
        end process;
174
 
175
end arch;
176
 

powered by: WebSVN 2.1.0

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