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

Subversion Repositories light8080

[/] [light8080/] [trunk/] [vhdl/] [soc/] [l80irq.vhdl] - Blame information for rev 70

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 70 ja_rd
--##############################################################################
2
-- l80irq : light8080 interrupt controller for l80soc 
3
--##############################################################################
4
--
5
-- This is a basic interrupt controller for the light8080 core. It is meant for
6
-- demonstration purposes only (demonstration of the light8080 core) and has 
7
-- not passed any serious verification test bench.
8
-- It has been built on the same principles as the rest of the modules in this
9
-- project: no more functionality than strictly needed, minimized area.
10
--
11
-- The interrupt controller operates under these rules:
12
--
13
-- -# All interrupt inputs are active at rising edge.
14
-- -# No logic is included for input sinchronization. You must take care to 
15
--    prevent metastability issues yourself by the usual means.
16
-- -# If a new edge is detected before the first is serviced, it is lost.
17
-- -# As soon as a rising edge in enabled irq input K is detected, bit K in the
18
--    interrupt pending register 'irq_pending_reg' will be asserted.
19
--    Than is, disabled interrupts never get detected at all.
20
-- -# Output cpu_intr_o will be asserted as long as there's a bit asserted in
21
--    the interrupt pending register.
22
-- -# For each interrupt there is a predefined priority level and a predefined 
23
--    interrupt vector -- see comments below. 
24
-- -# As soon as an INTA cycle is done by the CPU (inta=1 and fetch=1) the 
25
--    following will happen:
26
--    * The module will supply the interrupt vector of the highes priority
27
--      pending interrupt.
28
--    * The highest priority pending interrupt bit in the pending interrupt 
29
--      register will be deasserted -- UNLESS the interrupts happens to trigger
30
--      again at the same time, in which case the pending bit will remain
31
--      asserted.
32
--    * If there are no more interrupts pending, the cpu_intr_o output will
33
--      be deasserted.
34
-- -# The CPU will have its interrupts disabled from the INTA cycle to the 
35
--    execution of instruction EI. 
36
-- -# The cpu_intr_o will be asserted for a single cycle.
37
-- -# The irq vectors are hardcoded to RST instructions (single byte calls).
38
-- 
39
-- The priorities and vectors are hardcoded to the following values:
40
--
41
--    irq_i(3)    Priority 3    Vector RST 7
42
--    irq_i(2)    Priority 2    Vector RST 5
43
--    irq_i(1)    Priority 1    Vector RST 3
44
--    irq_i(0)    Priority 0    Vector RST 1
45
--
46
-- (Priority order: 3 > 2 > 1 > 0).
47
--
48
-- This module is used in the l80soc module, for which a basic test bench 
49
-- exists. Both can be used as usage example.
50
-- The module and its application is so simple than no documentation other than 
51
-- these comments should be necessary.
52
--
53
-- This file and all the light8080 project files are freeware (See COPYING.TXT)
54
--##############################################################################
55
-- (See timing diagrams at bottom of file. More comprehensive explainations can 
56
-- be found in the design notes)
57
--##############################################################################
58
 
59
library ieee;
60
use ieee.std_logic_1164.all;
61
use ieee.std_logic_arith.all;
62
use ieee.std_logic_unsigned.all;
63
 
64
--##############################################################################
65
--
66
--##############################################################################
67
 
68
entity L80irq is
69
  port (
70
    cpu_inta_i :    in std_logic;
71
    cpu_intr_o :    out std_logic;
72
    cpu_fetch_i :   in std_logic;
73
 
74
    data_we_i :     in std_logic;
75
    addr_i :        in std_logic;
76
    data_i :        in std_logic_vector(7 downto 0);
77
    data_o :        out std_logic_vector(7 downto 0);
78
 
79
    irq_i :         in std_logic_vector(3 downto 0);
80
 
81
    clk :           in std_logic;
82
    reset :         in std_logic );
83
end L80irq;
84
 
85
--##############################################################################
86
--
87
--##############################################################################
88
 
89
architecture hardwired of L80irq is
90
 
91
-- irq_pending: 1 when irq[i] is pending service
92
signal irq_pending_reg :  std_logic_vector(3 downto 0);
93
-- irq_enable: 1 when irq[i] is enabled 
94
signal irq_enable_reg :   std_logic_vector(3 downto 0);
95
-- irq_q: registered irq input used to catch rising edges
96
signal irq_q :        std_logic_vector(3 downto 0);
97
-- irq_trigger: asserted to 1 when a rising edge is detected
98
signal irq_trigger :  std_logic_vector(3 downto 0);
99
signal irq_clear :    std_logic_vector(3 downto 0);
100
signal irq_clear_mask:std_logic_vector(3 downto 0);
101
 
102
signal data_rd :      std_logic_vector(7 downto 0);
103
signal vector :       std_logic_vector(7 downto 0);
104
signal irq_level :    std_logic_vector(2 downto 0);
105
 
106
 
107
begin
108
 
109
edge_detection:
110
for i in 0 to 3 generate
111
begin
112
  irq_trigger(i) <= '1' when  -- IRQ(i) is triggered when...
113
      irq_q(i)='0' and        -- ...we see a rising edge...
114
      irq_i(i)='1' and
115
      irq_enable_reg(i)='1'   -- ...and the irq input us enabled.
116
      else '0';
117
end generate edge_detection;
118
 
119
interrupt_pending_reg:
120
process(clk)
121
begin
122
  if clk'event and clk='1' then
123
    if reset = '1' then
124
      irq_pending_reg <= (others => '0');
125
      irq_q <= (others => '0');
126
    else
127
      irq_pending_reg <= (irq_pending_reg and (not irq_clear)) or irq_trigger;
128
      irq_q <= irq_i;
129
    end if;
130
  end if;
131
end process interrupt_pending_reg;
132
 
133
with irq_level select irq_clear_mask <=
134
  "1000" when "111",
135
  "0100" when "101",
136
  "0010" when "011",
137
  "0001" when others;
138
 
139
irq_clear <= irq_clear_mask when cpu_inta_i='1' and cpu_fetch_i='1' else "0000";
140
 
141
 
142
interrupt_enable_reg:
143
process(clk)
144
begin
145
  if clk'event and clk='1' then
146
    if reset = '1' then
147
      -- All interrupts disabled at reset
148
      irq_enable_reg <= (others => '0');
149
    else
150
      if data_we_i = '1' and addr_i = '0' then
151
        irq_enable_reg <= data_i(3 downto 0);
152
      end if;
153
    end if;
154
  end if;
155
end process interrupt_enable_reg;
156
 
157
-- Interrupt priority & vector decoding
158
irq_level <=
159
  "001" when irq_pending_reg(0) = '1' else
160
  "011" when irq_pending_reg(1) = '1' else
161
  "110" when irq_pending_reg(2) = '1' else
162
  "111";
163
 
164
-- Raise interrupt request when there's any irq pending
165
cpu_intr_o <= '1' when irq_pending_reg /= "0000" else '0';
166
 
167
-- The IRQ vector is hardcoded to a RST instruction, whose opcode is 
168
-- RST <n> ---> 11nnn111
169
process(clk)
170
begin
171
  if clk'event and clk='1' then
172
    if cpu_inta_i='1' and cpu_fetch_i='1' then
173
      vector <= "11" & irq_level & "111";
174
    end if;
175
  end if;
176
end process;
177
 
178
-- There's only an internal register, the irq enable register, so we
179
-- don't need an output register mux.
180
data_rd <= "0000" & irq_enable_reg;
181
 
182
-- The mdule will output the register being read, if any, OR the irq vector.
183
data_o <= vector when cpu_inta_i = '1' else data_rd;
184
 
185
 
186
 
187
 
188
end hardwired;
189
 

powered by: WebSVN 2.1.0

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