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

Subversion Repositories open8_urisc

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

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

Line No. Rev Author Line
1 329 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_ts_ioctl
25
-- Description:  Provides an 8-bit microsecond resolution timer for generating
26
--            :   periodic interrupts for the Open8 task switcher, a second-
27
--            :   level cascaded interrupt manager, and 16-bit I/O write
28
--            :   qualification register.
29
--
30
-- Register Map:
31
-- Offset  Bitfield Description                        Read/Write
32
--   0x00  AAAAAAAA PIT Timer Interval (0 = disabled)    (RW)
33
--   0x01  AAAAAAAA External Interrupt Mask (lower)      (RW)
34
--   0x02  AAAAAAAA External Interrupt Mask (upper)      (RW)
35
--   0x03  AAAAAAAA Pending External Ints* (lower)       (RW)
36
--   0x04  AAAAAAAA Pending External Ints* (upper)       (RW)
37
--   0x05  A------- Interrupt Requested (write to clear) (RW)
38
--   0x06  AAAAAAAA IO Write Qualification Register LB   (RW)
39
--   0x07  AAAAAAAA IO Write Qualification Register UB   (RW)
40
--
41
-- Note: Each bit in the pending register is individually clearable by writing
42
--        a '1' to it, allowing interrupts to be cleared individually
43
--
44
-- Revision History
45
-- Author          Date     Change
46
------------------ -------- ---------------------------------------------------
47
-- Seth Henry      09/28/23 Initial creation
48
 
49
library ieee;
50
use ieee.std_logic_1164.all;
51
  use ieee.std_logic_unsigned.all;
52
  use ieee.std_logic_arith.all;
53
  use ieee.std_logic_misc.all;
54
 
55
library work;
56
  use work.open8_pkg.all;
57
 
58
entity o8_ts_ioctl is
59
generic(
60
  Default_Int_Mask           : ADDRESS_TYPE := x"0000";
61
  Address                    : ADDRESS_TYPE
62
);
63
port(
64
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
65
  Rd_Data                    : out DATA_TYPE;
66
  --
67
  PIT_Interrupt              : out std_logic;
68
  --
69
  IO_Interrupts_In           : in  ADDRESS_TYPE := x"0000";
70
  IO_Interrupt               : out std_logic;
71
  IO_Write_Qual              : out ADDRESS_TYPE
72
);
73
end entity;
74
 
75
architecture behave of o8_ts_ioctl is
76
 
77
  alias  Clock               is Open8_Bus.Clock;
78
  alias  Reset               is Open8_Bus.Reset;
79
  alias  uSec_Tick           is Open8_Bus.uSec_Tick;
80
  alias  CPU_ISR_En          is Open8_Bus.GP_Flags(EXT_ISR);
81
  alias  CPU_Wr_En           is Open8_Bus.Wr_En;
82
  alias  CPU_Rd_En           is Open8_Bus.Rd_En;
83
 
84
  constant User_Addr         : std_logic_vector(15 downto 3) :=
85
                                Address(15 downto 3);
86
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 3);
87
  signal Addr_Match          : std_logic := '0';
88
 
89
  alias  Reg_Sel_d           is Open8_Bus.Address(2 downto 0);
90
  signal Reg_Sel_q           : std_logic_vector(2 downto 0);
91
  signal Wr_En_d             : std_logic;
92
  signal Wr_En_q             : std_logic := '0';
93
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
94
  signal Wr_Data_q           : DATA_TYPE := x"00";
95
  signal Rd_En_d               : std_logic := '0';
96
  signal Rd_En_q             : std_logic := '0';
97
 
98
  signal Interval            : DATA_TYPE := x"00";
99
  signal Update_Interval     : std_logic;
100
  signal Timer_Cnt           : DATA_TYPE := x"00";
101
 
102
  signal Int_Mask            : ADDRESS_TYPE := x"0000";
103
  alias  Int_Mask_l          is Int_Mask(7 downto 0);
104
  alias  Int_Mask_h          is Int_Mask(15 downto 8);
105
 
106
  signal Clear_Pending       : ADDRESS_TYPE := x"0000";
107
  alias  Clear_Pending_l     is Clear_Pending(7 downto 0);
108
  alias  Clear_Pending_h     is Clear_Pending(15 downto 8);
109
 
110
  signal Ack_IO_Ints         : std_logic;
111
 
112
  signal Pending             : ADDRESS_TYPE := x"0000";
113
  alias  Pending_l           is Pending(7 downto 0);
114
  alias  Pending_h           is Pending(15 downto 8);
115
  signal Pending_q           : ADDRESS_TYPE := x"0000";
116
  signal Pending_RE          : ADDRESS_TYPE := x"0000";
117
 
118
  signal IO_Int_Pending      : std_logic;
119
 
120
  signal IO_Qual_Reg         : ADDRESS_TYPE := x"0000";
121
  alias  IO_Qual_l           is IO_Qual_Reg(7 downto 0);
122
  alias  IO_Qual_h           is IO_Qual_Reg(15 downto 8);
123
 
124
begin
125
 
126
  IO_Write_Qual              <= IO_Qual_Reg;
127
 
128
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
129
  Wr_En_d                    <= Addr_Match and CPU_Wr_En and CPU_ISR_En;
130
  Rd_En_d                    <= Addr_Match and CPU_Rd_En;
131
 
132
  io_reg: process( Clock, Reset )
133
  begin
134
    if( Reset = Reset_Level )then
135
      Reg_Sel_q              <= (others => '0');
136
      Wr_En_q                <= '0';
137
      Wr_Data_q              <= x"00";
138
      Rd_En_q                <= '0';
139
      Rd_Data                <= OPEN8_NULLBUS;
140
      Interval               <= x"00";
141
      Update_Interval        <= '0';
142
      Int_Mask               <= Default_Int_Mask;
143
      Clear_Pending          <= x"0000";
144
      Ack_IO_Ints            <= '0';
145
    elsif( rising_edge( Clock ) )then
146
      Reg_Sel_q              <= Reg_Sel_d;
147
      Wr_En_q                <= Wr_En_d;
148
      Wr_Data_q              <= Wr_Data_d;
149
 
150
      Update_Interval        <= Wr_En_q;
151
      Clear_Pending          <= x"0000";
152
      Ack_IO_Ints            <= '0';
153
      if( Wr_En_q = '1' )then
154
        case( Reg_Sel_q )is
155
          when "000" =>
156
            Interval         <= Wr_Data_q;
157
          when "001" =>
158
            Int_Mask_l       <= Wr_Data_q;
159
          when "010" =>
160
            Int_Mask_h       <= Wr_Data_q;
161
          when "011" =>
162
            Clear_Pending_l  <= Wr_Data_q;
163
          when "100" =>
164
            Clear_Pending_h  <= Wr_Data_q;
165
          when "101" =>
166
            Ack_IO_Ints      <= '1';
167
          when "110" =>
168
            IO_Qual_l        <= Wr_Data_q;
169
          when "111" =>
170
            IO_Qual_h        <= Wr_Data_q;
171
          when others =>
172
            null;
173
        end case;
174
      end if;
175
 
176
      Rd_Data                <= (others => '0');
177
      Rd_En_q                <= Rd_En_d;
178
      if( Rd_En_q = '1' )then
179
        case( Reg_Sel_q )is
180
          when "000" =>
181
            Rd_Data          <= Interval;
182
          when "001" =>
183
            Rd_Data          <= Int_Mask_l;
184
          when "010" =>
185
            Rd_Data          <= Int_Mask_h;
186
          when "011" =>
187
            Rd_Data          <= Pending_l;
188
          when "100" =>
189
            Rd_Data          <= Pending_h;
190
          when "101" =>
191
            Rd_Data          <= IO_Int_Pending & "0000000";
192
          when "110" =>
193
            Rd_Data          <= IO_Qual_l;
194
          when "111" =>
195
            Rd_Data          <= IO_Qual_h;
196
          when others =>
197
            null;
198
        end case;
199
      end if;
200
    end if;
201
  end process;
202
 
203
  Interval_proc: process( Clock, Reset )
204
  begin
205
    if( Reset = Reset_Level )then
206
      Timer_Cnt              <= x"00";
207
      PIT_Interrupt          <= '0';
208
    elsif( rising_edge(Clock) )then
209
      PIT_Interrupt              <= '0';
210
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
211
      if( Update_Interval = '1' )then
212
        Timer_Cnt            <= Interval;
213
      elsif( or_reduce(Timer_Cnt) = '0' )then
214
        Timer_Cnt            <= Interval;
215
        PIT_Interrupt        <= or_reduce(Interval); -- Only trigger on Int > 0
216
      end if;
217
    end if;
218
  end process;
219
 
220
  Interrupt_proc: process( Clock, Reset )
221
    variable i               : integer := 0;
222
  begin
223
    if( Reset = Reset_Level )then
224
      Pending                <= x"0000";
225
      Pending_q              <= x"0000";
226
      Pending_RE             <= x"0000";
227
      IO_Int_Pending         <= '0';
228
      IO_Interrupt           <= '0';
229
    elsif( rising_edge(Clock) )then
230
      for i in 0 to 15 loop
231
        if( IO_Interrupts_In(i) = '1' and Int_Mask(i) = '1' )then
232
          Pending(i)         <= '1';
233
        elsif( Clear_Pending(i) = '1' )then
234
          Pending(i)         <= '0';
235
        end if;
236
        Pending_q(i)         <= Pending(i);
237
        Pending_RE(i)        <= Pending(i) and not Pending_q(i);
238
      end loop;
239
 
240
      IO_Interrupt           <= '0';
241
      if( or_reduce(Pending_RE) = '1' and IO_Int_Pending = '0' )then
242
        IO_Int_Pending       <= '1';
243
        IO_Interrupt         <= '1';
244
      elsif( Ack_IO_Ints = '1' )then
245
        IO_Int_Pending       <= '0';
246
      end if;
247
 
248
    end if;
249
  end process;
250
 
251
end architecture;

powered by: WebSVN 2.1.0

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