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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_int_mgr.vhd] - Blame information for rev 329

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

Line No. Rev Author Line
1 245 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_mgr
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  AAAAAAAA External Interrupt Mask              (RW)
33
--   0x02  AAAAAAAA Pending External Interrupts*         (RW)
34
--   0x03  A------- Interrupt Requested (write to clear) (RW)
35
--
36
-- Note: Each bit in the pending register is individually clearable by writing
37
--        a '1' to it, allowing interrupts to be cleared individually
38
--
39
-- Revision History
40
-- Author          Date     Change
41
------------------ -------- ---------------------------------------------------
42
-- Seth Henry      05/21/20 Design Start
43
 
44
library ieee;
45
use ieee.std_logic_1164.all;
46
  use ieee.std_logic_unsigned.all;
47
  use ieee.std_logic_arith.all;
48
  use ieee.std_logic_misc.all;
49
 
50
library work;
51
  use work.open8_pkg.all;
52
 
53
entity o8_int_mgr is
54
generic(
55
  Default_Int_Mask           : DATA_TYPE := x"00";
56
  Address                    : ADDRESS_TYPE
57
);
58
port(
59
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
60
  Interrupts                 : in  INTERRUPT_BUNDLE := x"00";
61
  Rd_Data                    : out DATA_TYPE;
62
  PIT_Interrupt              : out std_logic;
63
  EXT_Interrupt              : out std_logic
64
);
65
end entity;
66
 
67
architecture behave of o8_int_mgr is
68
 
69
  alias  Clock               is Open8_Bus.Clock;
70
  alias  Reset               is Open8_Bus.Reset;
71
  alias  uSec_Tick           is Open8_Bus.uSec_Tick;
72
  alias  CPU_ISR_En          is Open8_Bus.GP_Flags(EXT_ISR);
73
  alias  CPU_Wr_En           is Open8_Bus.Wr_En;
74
  alias  CPU_Rd_En           is Open8_Bus.Rd_En;
75
 
76
  constant User_Addr         : std_logic_vector(15 downto 2) :=
77
                                Address(15 downto 2);
78
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
79
  signal Addr_Match          : std_logic := '0';
80
 
81
  alias  Reg_Sel_d           is Open8_Bus.Address(1 downto 0);
82
  signal Reg_Sel_q           : std_logic_vector(1 downto 0);
83
  signal Wr_En_d             : std_logic;
84
  signal Wr_En_q             : std_logic := '0';
85
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
86
  signal Wr_Data_q           : DATA_TYPE := x"00";
87
  signal Rd_En_d               : std_logic := '0';
88
  signal Rd_En_q             : std_logic := '0';
89
 
90
  signal Interval            : DATA_TYPE := x"00";
91
  signal Update_Interval     : std_logic;
92
  signal Timer_Cnt           : DATA_TYPE := x"00";
93
 
94
  signal Int_Mask            : DATA_TYPE := x"00";
95
  signal Clear_Pending       : DATA_TYPE := x"00";
96
  signal Ack_IO_Ints         : std_logic;
97
 
98
  signal Pending             : DATA_TYPE := x"00";
99
  signal Pending_q           : DATA_TYPE := x"00";
100
  signal Pending_RE          : DATA_TYPE := x"00";
101
 
102
  signal IO_Int_Pending      : std_logic;
103
 
104
begin
105
 
106
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
107
  Wr_En_d                    <= Addr_Match and CPU_Wr_En and CPU_ISR_En;
108
  Rd_En_d                    <= Addr_Match and CPU_Rd_En;
109
 
110
  io_reg: process( Clock, Reset )
111
  begin
112
    if( Reset = Reset_Level )then
113
      Reg_Sel_q              <= (others => '0');
114
      Wr_En_q                <= '0';
115
      Wr_Data_q              <= x"00";
116
      Rd_En_q                <= '0';
117
      Rd_Data                <= OPEN8_NULLBUS;
118
      Interval               <= x"00";
119
      Update_Interval        <= '0';
120
      Int_Mask               <= Default_Int_Mask;
121
      Clear_Pending          <= x"00";
122
      Ack_IO_Ints            <= '0';
123
    elsif( rising_edge( Clock ) )then
124
      Reg_Sel_q              <= Reg_Sel_d;
125
      Wr_En_q                <= Wr_En_d;
126
      Wr_Data_q              <= Wr_Data_d;
127
 
128
      Update_Interval        <= Wr_En_q;
129
      Clear_Pending          <= x"00";
130
      Ack_IO_Ints            <= '0';
131
      if( Wr_En_q = '1' )then
132
        case( Reg_Sel_q )is
133
          when "00" =>
134
            Interval         <= Wr_Data_q;
135
          when "01" =>
136
            Int_Mask         <= Wr_Data_q;
137
          when "10" =>
138
            Clear_Pending    <= Wr_Data_q;
139
          when "11" =>
140
            Ack_IO_Ints      <= '1';
141
          when others =>
142
            null;
143
        end case;
144
      end if;
145
 
146
      Rd_Data                <= (others => '0');
147
      Rd_En_q                <= Rd_En_d;
148
      if( Rd_En_q = '1' )then
149
        case( Reg_Sel_q )is
150
          when "00" =>
151
            Rd_Data          <= Interval;
152
          when "01" =>
153
            Rd_Data          <= Int_Mask;
154
          when "10" =>
155
            Rd_Data          <= Pending;
156
          when "11" =>
157
            Rd_Data          <= IO_Int_Pending & "0000000";
158
          when others =>
159
            null;
160
        end case;
161
      end if;
162
    end if;
163
  end process;
164
 
165
  Interval_proc: process( Clock, Reset )
166
  begin
167
    if( Reset = Reset_Level )then
168
      Timer_Cnt              <= x"00";
169
      PIT_Interrupt          <= '0';
170
    elsif( rising_edge(Clock) )then
171
      PIT_Interrupt              <= '0';
172
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
173
      if( Update_Interval = '1' )then
174
        Timer_Cnt            <= Interval;
175
      elsif( or_reduce(Timer_Cnt) = '0' )then
176
        Timer_Cnt            <= Interval;
177
        PIT_Interrupt        <= or_reduce(Interval); -- Only trigger on Int > 0
178
      end if;
179
    end if;
180
  end process;
181
 
182
  Interrupt_proc: process( Clock, Reset )
183
    variable i               : integer := 0;
184
  begin
185
    if( Reset = Reset_Level )then
186
      Pending                <= x"00";
187
      Pending_q              <= x"00";
188
      Pending_RE             <= x"00";
189
      IO_Int_Pending         <= '0';
190
      EXT_Interrupt          <= '0';
191
    elsif( rising_edge(Clock) )then
192
      for i in 0 to 7 loop
193
        if( Interrupts(i) = '1' and Int_Mask(i) = '1' )then
194
          Pending(i)         <= '1';
195
        elsif( Clear_Pending(i) = '1' )then
196
          Pending(i)         <= '0';
197
        end if;
198
        Pending_q(i)         <= Pending(i);
199
        Pending_RE(i)        <= Pending(i) and not Pending_q(i);
200
      end loop;
201
 
202
      EXT_Interrupt          <= '0';
203
      if( or_reduce(Pending_RE) = '1' and IO_Int_Pending = '0' )then
204
        IO_Int_Pending       <= '1';
205
        EXT_Interrupt        <= '1';
206
      elsif( Ack_IO_Ints = '1' )then
207
        IO_Int_Pending       <= '0';
208
      end if;
209
 
210
    end if;
211
  end process;
212
 
213
end architecture;

powered by: WebSVN 2.1.0

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