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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_int_mgr16.vhd] - Blame information for rev 317

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 268 jshamlet
-- Copyright (c)2020 Jeremy Seth Henry
2
-- All rights reserved.
3
--
4
-- Redistribution and use in source and binary forms, with or without
5
-- modification, are permitted provided that the following conditions are met:
6
--     * Redistributions of source code must retain the above copyright
7
--       notice, this list of conditions and the following disclaimer.
8
--     * Redistributions in binary form must reproduce the above copyright
9
--       notice, this list of conditions and the following disclaimer in the
10
--       documentation and/or other materials provided with the distribution,
11
--       where applicable (as part of a user interface, debugging port, etc.)
12
--
13
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
14
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
17
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Units :  o8_int_mgr16
25
-- Description:  Provides an 8-bit microsecond resolution timer for generating
26
--            :   periodic interrupts for the Open8 CPU as well as providing a
27
--            :   second level interrupt manager for I/O interrupts
28
--
29
-- Register Map:
30
-- Offset  Bitfield Description                        Read/Write
31
--   0x00  AAAAAAAA PIT Timer Interval (0 = disabled)    (RW)
32
--   0x01  -------- (unused)
33
--   0x02  AAAAAAAA External Interrupt Mask (lower)      (RW)
34
--   0x03  AAAAAAAA External Interrupt Mask (upper)      (RW)
35
--   0x04  AAAAAAAA Pending External Ints* (lower)       (RW)
36
--   0x05  AAAAAAAA Pending External Ints* (upper)       (RW)
37
--   0x06  -------- (unused)
38
--   0x07  A------- Interrupt Requested (write to clear) (RW)
39
--
40
-- Note: Each bit in the pending register is individually clearable by writing
41
--        a '1' to it, allowing interrupts to be cleared individually
42
--
43
-- Revision History
44
-- Author          Date     Change
45
------------------ -------- ---------------------------------------------------
46
-- Seth Henry      05/21/20 Design Start
47
 
48
library ieee;
49
use ieee.std_logic_1164.all;
50
  use ieee.std_logic_unsigned.all;
51
  use ieee.std_logic_arith.all;
52
  use ieee.std_logic_misc.all;
53
 
54
library work;
55
  use work.open8_pkg.all;
56
 
57
entity o8_int_mgr16 is
58
generic(
59
  Default_Int_Mask           : ADDRESS_TYPE := x"0000";
60
  Address                    : ADDRESS_TYPE
61
);
62
port(
63
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
64
  Interrupts                 : in  ADDRESS_TYPE := x"0000";
65
  Rd_Data                    : out DATA_TYPE;
66
  PIT_Interrupt              : out std_logic;
67
  EXT_Interrupt              : out std_logic
68
);
69
end entity;
70
 
71
architecture behave of o8_int_mgr16 is
72
 
73
  alias  Clock               is Open8_Bus.Clock;
74
  alias  Reset               is Open8_Bus.Reset;
75
  alias  uSec_Tick           is Open8_Bus.uSec_Tick;
76
  alias  CPU_ISR_En          is Open8_Bus.GP_Flags(EXT_ISR);
77
  alias  CPU_Wr_En           is Open8_Bus.Wr_En;
78
  alias  CPU_Rd_En           is Open8_Bus.Rd_En;
79
 
80
  constant User_Addr         : std_logic_vector(15 downto 3) :=
81
                                Address(15 downto 3);
82
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 3);
83
  signal Addr_Match          : std_logic := '0';
84
 
85
  alias  Reg_Sel_d           is Open8_Bus.Address(2 downto 0);
86
  signal Reg_Sel_q           : std_logic_vector(2 downto 0);
87
  signal Wr_En_d             : std_logic;
88
  signal Wr_En_q             : std_logic := '0';
89
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
90
  signal Wr_Data_q           : DATA_TYPE := x"00";
91
  signal Rd_En_d               : std_logic := '0';
92
  signal Rd_En_q             : std_logic := '0';
93
 
94
  signal Interval            : DATA_TYPE := x"00";
95
  signal Update_Interval     : std_logic;
96
  signal Timer_Cnt           : DATA_TYPE := x"00";
97
 
98
  signal Int_Mask            : ADDRESS_TYPE := x"0000";
99
  alias  Int_Mask_l          is Int_Mask(7 downto 0);
100
  alias  Int_Mask_h          is Int_Mask(15 downto 8);
101
 
102
  signal Clear_Pending       : ADDRESS_TYPE := x"0000";
103
  alias  Clear_Pending_l     is Clear_Pending(7 downto 0);
104
  alias  Clear_Pending_h     is Clear_Pending(15 downto 8);
105
 
106
  signal Ack_IO_Ints         : std_logic;
107
 
108
  signal Pending             : ADDRESS_TYPE := x"0000";
109
  alias  Pending_l           is Pending(7 downto 0);
110
  alias  Pending_h           is Pending(15 downto 8);
111
  signal Pending_q           : ADDRESS_TYPE := x"0000";
112
  signal Pending_RE          : ADDRESS_TYPE := x"0000";
113
 
114
  signal IO_Int_Pending      : std_logic;
115
 
116
begin
117
 
118
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
119
  Wr_En_d                    <= Addr_Match and CPU_Wr_En and CPU_ISR_En;
120
  Rd_En_d                    <= Addr_Match and CPU_Rd_En;
121
 
122
  io_reg: process( Clock, Reset )
123
  begin
124
    if( Reset = Reset_Level )then
125
      Reg_Sel_q              <= (others => '0');
126
      Wr_En_q                <= '0';
127
      Wr_Data_q              <= x"00";
128
      Rd_En_q                <= '0';
129
      Rd_Data                <= OPEN8_NULLBUS;
130
      Interval               <= x"00";
131
      Update_Interval        <= '0';
132
      Int_Mask               <= Default_Int_Mask;
133
      Clear_Pending          <= x"0000";
134
      Ack_IO_Ints            <= '0';
135
    elsif( rising_edge( Clock ) )then
136
      Reg_Sel_q              <= Reg_Sel_d;
137
      Wr_En_q                <= Wr_En_d;
138
      Wr_Data_q              <= Wr_Data_d;
139
 
140
      Update_Interval        <= Wr_En_q;
141
      Clear_Pending          <= x"0000";
142
      Ack_IO_Ints            <= '0';
143
      if( Wr_En_q = '1' )then
144
        case( Reg_Sel_q )is
145
          when "000" =>
146
            Interval         <= Wr_Data_q;
147
          when "010" =>
148
            Int_Mask_l       <= Wr_Data_q;
149
          when "011" =>
150
            Int_Mask_h       <= Wr_Data_q;
151
 
152
          when "100" =>
153
            Clear_Pending_l  <= Wr_Data_q;
154
          when "101" =>
155
            Clear_Pending_h  <= Wr_Data_q;
156
 
157
          when "111" =>
158
            Ack_IO_Ints      <= '1';
159
          when others =>
160
            null;
161
        end case;
162
      end if;
163
 
164
      Rd_Data                <= (others => '0');
165
      Rd_En_q                <= Rd_En_d;
166
      if( Rd_En_q = '1' )then
167
        case( Reg_Sel_q )is
168
          when "000" =>
169
            Rd_Data          <= Interval;
170
          when "010" =>
171
            Rd_Data          <= Int_Mask_l;
172
          when "011" =>
173
            Rd_Data          <= Int_Mask_h;
174
          when "100" =>
175
            Rd_Data          <= Pending_l;
176
          when "101" =>
177
            Rd_Data          <= Pending_h;
178
          when "111" =>
179
            Rd_Data          <= IO_Int_Pending & "0000000";
180
          when others =>
181
            null;
182
        end case;
183
      end if;
184
    end if;
185
  end process;
186
 
187
  Interval_proc: process( Clock, Reset )
188
  begin
189
    if( Reset = Reset_Level )then
190
      Timer_Cnt              <= x"00";
191
      PIT_Interrupt          <= '0';
192
    elsif( rising_edge(Clock) )then
193
      PIT_Interrupt              <= '0';
194
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
195
      if( Update_Interval = '1' )then
196
        Timer_Cnt            <= Interval;
197
      elsif( or_reduce(Timer_Cnt) = '0' )then
198
        Timer_Cnt            <= Interval;
199
        PIT_Interrupt        <= or_reduce(Interval); -- Only trigger on Int > 0
200
      end if;
201
    end if;
202
  end process;
203
 
204
  Interrupt_proc: process( Clock, Reset )
205
    variable i               : integer := 0;
206
  begin
207
    if( Reset = Reset_Level )then
208
      Pending                <= x"0000";
209
      Pending_q              <= x"0000";
210
      Pending_RE             <= x"0000";
211
      IO_Int_Pending         <= '0';
212
      EXT_Interrupt          <= '0';
213
    elsif( rising_edge(Clock) )then
214
      for i in 0 to 15 loop
215
        if( Interrupts(i) = '1' and Int_Mask(i) = '1' )then
216
          Pending(i)         <= '1';
217
        elsif( Clear_Pending(i) = '1' )then
218
          Pending(i)         <= '0';
219
        end if;
220
        Pending_q(i)         <= Pending(i);
221
        Pending_RE(i)        <= Pending(i) and not Pending_q(i);
222
      end loop;
223
 
224
      EXT_Interrupt          <= '0';
225
      if( or_reduce(Pending_RE) = '1' and IO_Int_Pending = '0' )then
226
        IO_Int_Pending       <= '1';
227
        EXT_Interrupt        <= '1';
228
      elsif( Ack_IO_Ints = '1' )then
229
        IO_Int_Pending       <= '0';
230
      end if;
231
 
232
    end if;
233
  end process;
234
 
235
end architecture;

powered by: WebSVN 2.1.0

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