1 |
2 |
hasw |
--
|
2 |
|
|
-- UART interrupt control
|
3 |
|
|
--
|
4 |
|
|
-- Author: Sebastian Witt
|
5 |
|
|
-- Date: 27.01.2008
|
6 |
13 |
hasw |
-- Version: 1.1
|
7 |
2 |
hasw |
--
|
8 |
13 |
hasw |
-- History: 1.0 - Initial version
|
9 |
|
|
-- 1.1 - Automatic flow control
|
10 |
|
|
--
|
11 |
|
|
--
|
12 |
2 |
hasw |
-- This code is free software; you can redistribute it and/or
|
13 |
|
|
-- modify it under the terms of the GNU Lesser General Public
|
14 |
|
|
-- License as published by the Free Software Foundation; either
|
15 |
|
|
-- version 2.1 of the License, or (at your option) any later version.
|
16 |
|
|
--
|
17 |
|
|
-- This code is distributed in the hope that it will be useful,
|
18 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
20 |
|
|
-- Lesser General Public License for more details.
|
21 |
|
|
--
|
22 |
|
|
-- You should have received a copy of the GNU Lesser General Public
|
23 |
|
|
-- License along with this library; if not, write to the
|
24 |
|
|
-- Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
25 |
|
|
-- Boston, MA 02111-1307 USA
|
26 |
|
|
--
|
27 |
|
|
|
28 |
|
|
LIBRARY IEEE;
|
29 |
|
|
USE IEEE.std_logic_1164.all;
|
30 |
|
|
USE IEEE.numeric_std.all;
|
31 |
|
|
|
32 |
|
|
-- Serial UART interrupt control
|
33 |
|
|
entity uart_interrupt is
|
34 |
|
|
port (
|
35 |
|
|
CLK : in std_logic; -- Clock
|
36 |
|
|
RST : in std_logic; -- Reset
|
37 |
|
|
IER : in std_logic_vector(3 downto 0); -- IER 3:0
|
38 |
|
|
LSR : in std_logic_vector(4 downto 0); -- LSR 4:0
|
39 |
|
|
THI : in std_logic; -- Transmitter holding register empty interrupt
|
40 |
|
|
RDA : in std_logic; -- Receiver data available
|
41 |
|
|
CTI : in std_logic; -- Character timeout indication
|
42 |
13 |
hasw |
AFE : in std_logic; -- Automatic flow control enable
|
43 |
2 |
hasw |
MSR : in std_logic_vector(3 downto 0); -- MSR 3:0
|
44 |
|
|
IIR : out std_logic_vector(3 downto 0); -- IIR 3:0
|
45 |
|
|
INT : out std_logic -- Interrupt
|
46 |
|
|
);
|
47 |
|
|
end uart_interrupt;
|
48 |
|
|
|
49 |
|
|
architecture rtl of uart_interrupt is
|
50 |
|
|
-- Signals
|
51 |
|
|
signal iRLSInterrupt : std_logic; -- Receiver line status interrupt
|
52 |
|
|
signal iRDAInterrupt : std_logic; -- Received data available interrupt
|
53 |
|
|
signal iCTIInterrupt : std_logic; -- Character timeout indication interrupt
|
54 |
|
|
signal iTHRInterrupt : std_logic; -- Transmitter holding register empty interrupt
|
55 |
|
|
signal iMSRInterrupt : std_logic; -- Modem status interrupt
|
56 |
|
|
signal iIIR : std_logic_vector(3 downto 0); -- IIR register
|
57 |
|
|
begin
|
58 |
|
|
|
59 |
|
|
-- Priority 1: Receiver line status interrupt on: Overrun error, parity error, framing error or break interrupt
|
60 |
|
|
iRLSInterrupt <= IER(2) and (LSR(1) or LSR(2) or LSR(3) or LSR(4));
|
61 |
|
|
|
62 |
|
|
-- Priority 2: Received data available or trigger level reached in FIFO mode
|
63 |
|
|
iRDAInterrupt <= IER(0) and RDA;
|
64 |
|
|
|
65 |
|
|
-- Priority 2: Character timeout indication
|
66 |
|
|
iCTIInterrupt <= IER(0) and CTI;
|
67 |
|
|
|
68 |
|
|
-- Priority 3: Transmitter holding register empty
|
69 |
|
|
iTHRInterrupt <= IER(1) and THI;
|
70 |
|
|
|
71 |
13 |
hasw |
-- Priority 4: Modem status interrupt: dCTS (when AFC is disabled), dDSR, TERI, dDCD
|
72 |
|
|
iMSRInterrupt <= IER(3) and ((MSR(0) and not AFE) or MSR(1) or MSR(2) or MSR(3));
|
73 |
2 |
hasw |
|
74 |
|
|
-- IIR
|
75 |
|
|
IC_IIR: process (CLK, RST)
|
76 |
|
|
begin
|
77 |
|
|
if (RST = '1') then
|
78 |
|
|
iIIR <= "0001"; -- TODO: Invert later
|
79 |
|
|
elsif (CLK'event and CLK = '1') then
|
80 |
|
|
-- IIR register
|
81 |
|
|
if (iRLSInterrupt = '1') then
|
82 |
|
|
iIIR <= "0110";
|
83 |
|
|
elsif (iCTIInterrupt = '1') then
|
84 |
|
|
iIIR <= "1100";
|
85 |
|
|
elsif (iRDAInterrupt = '1') then
|
86 |
|
|
iIIR <= "0100";
|
87 |
|
|
elsif (iTHRInterrupt = '1') then
|
88 |
|
|
iIIR <= "0010";
|
89 |
|
|
elsif (iMSRInterrupt = '1') then
|
90 |
|
|
iIIR <= "0000";
|
91 |
|
|
else
|
92 |
|
|
iIIR <= "0001";
|
93 |
|
|
end if;
|
94 |
|
|
end if;
|
95 |
|
|
end process;
|
96 |
|
|
|
97 |
|
|
-- Outputs
|
98 |
|
|
IIR <= iIIR;
|
99 |
|
|
INT <= not iIIR(0);
|
100 |
|
|
|
101 |
|
|
end rtl;
|
102 |
|
|
|