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 330

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
  Address                    : ADDRESS_TYPE
61
);
62
port(
63
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
64
  Rd_Data                    : out DATA_TYPE;
65
  --
66 330 jshamlet
  CPU_Interrupts             : out DATA_TYPE;
67 329 jshamlet
  --
68 330 jshamlet
  RAM_Write_Fault            : in  std_logic;
69 329 jshamlet
  IO_Interrupts_In           : in  ADDRESS_TYPE := x"0000";
70 330 jshamlet
  IO_Write_Qual_Out          : out ADDRESS_TYPE
71 329 jshamlet
);
72
end entity;
73
 
74
architecture behave of o8_ts_ioctl is
75
 
76
  alias  Clock               is Open8_Bus.Clock;
77
  alias  Reset               is Open8_Bus.Reset;
78
  alias  uSec_Tick           is Open8_Bus.uSec_Tick;
79
  alias  CPU_ISR_En          is Open8_Bus.GP_Flags(EXT_ISR);
80
  alias  CPU_Wr_En           is Open8_Bus.Wr_En;
81
  alias  CPU_Rd_En           is Open8_Bus.Rd_En;
82
 
83
  constant User_Addr         : std_logic_vector(15 downto 3) :=
84
                                Address(15 downto 3);
85
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 3);
86
  signal Addr_Match          : std_logic := '0';
87
 
88
  alias  Reg_Sel_d           is Open8_Bus.Address(2 downto 0);
89
  signal Reg_Sel_q           : std_logic_vector(2 downto 0);
90 330 jshamlet
  signal Wr_En_d             : std_logic := '0';
91 329 jshamlet
  signal Wr_En_q             : std_logic := '0';
92
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
93
  signal Wr_Data_q           : DATA_TYPE := x"00";
94
  signal Rd_En_d               : std_logic := '0';
95
  signal Rd_En_q             : std_logic := '0';
96
 
97
  signal Interval            : DATA_TYPE := x"00";
98
  signal Update_Interval     : std_logic;
99
  signal Timer_Cnt           : DATA_TYPE := x"00";
100
 
101 330 jshamlet
  signal PIT_Interrupt       : std_logic := '0';
102
 
103 329 jshamlet
  signal Int_Mask            : ADDRESS_TYPE := x"0000";
104
  alias  Int_Mask_l          is Int_Mask(7 downto 0);
105
  alias  Int_Mask_h          is Int_Mask(15 downto 8);
106
 
107
  signal Clear_Pending       : ADDRESS_TYPE := x"0000";
108
  alias  Clear_Pending_l     is Clear_Pending(7 downto 0);
109
  alias  Clear_Pending_h     is Clear_Pending(15 downto 8);
110
 
111 330 jshamlet
  signal Ack_IO_Ints         : std_logic := '0';
112 329 jshamlet
 
113
  signal Pending             : ADDRESS_TYPE := x"0000";
114
  alias  Pending_l           is Pending(7 downto 0);
115
  alias  Pending_h           is Pending(15 downto 8);
116
  signal Pending_q           : ADDRESS_TYPE := x"0000";
117
  signal Pending_RE          : ADDRESS_TYPE := x"0000";
118
 
119 330 jshamlet
  signal IO_Int_Pending      : std_logic := '0';
120 329 jshamlet
 
121 330 jshamlet
  signal IO_Interrupt        : std_logic := '0';
122
 
123 329 jshamlet
  signal IO_Qual_Reg         : ADDRESS_TYPE := x"0000";
124
  alias  IO_Qual_l           is IO_Qual_Reg(7 downto 0);
125
  alias  IO_Qual_h           is IO_Qual_Reg(15 downto 8);
126
 
127
begin
128
 
129 330 jshamlet
  -- The task switcher assumes the following CPU interrupt configuration
130
  CPU_Interrupts(0)          <= RAM_Write_Fault; -- WPR fault interrupt
131
  CPU_Interrupts(1)          <= PIT_Interrupt;   -- Pre-emption timer interrupt
132
  CPU_Interrupts(2)          <= IO_Interrupt;    -- Cascaded I/O interrupt
133
  CPU_Interrupts(7 downto 3) <= (others => '0'); -- Supervisor functions
134 329 jshamlet
 
135 330 jshamlet
  IO_Write_Qual_Out          <= IO_Qual_Reg;
136
 
137 329 jshamlet
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
138
  Wr_En_d                    <= Addr_Match and CPU_Wr_En and CPU_ISR_En;
139
  Rd_En_d                    <= Addr_Match and CPU_Rd_En;
140
 
141
  io_reg: process( Clock, Reset )
142
  begin
143
    if( Reset = Reset_Level )then
144
      Reg_Sel_q              <= (others => '0');
145
      Wr_En_q                <= '0';
146
      Wr_Data_q              <= x"00";
147
      Rd_En_q                <= '0';
148
      Rd_Data                <= OPEN8_NULLBUS;
149
      Interval               <= x"00";
150
      Update_Interval        <= '0';
151 330 jshamlet
      Int_Mask               <= x"0000";
152 329 jshamlet
      Clear_Pending          <= x"0000";
153
      Ack_IO_Ints            <= '0';
154
    elsif( rising_edge( Clock ) )then
155
      Reg_Sel_q              <= Reg_Sel_d;
156
      Wr_En_q                <= Wr_En_d;
157
      Wr_Data_q              <= Wr_Data_d;
158
 
159
      Update_Interval        <= Wr_En_q;
160
      Clear_Pending          <= x"0000";
161
      Ack_IO_Ints            <= '0';
162
      if( Wr_En_q = '1' )then
163
        case( Reg_Sel_q )is
164
          when "000" =>
165
            Interval         <= Wr_Data_q;
166
          when "001" =>
167
            Int_Mask_l       <= Wr_Data_q;
168
          when "010" =>
169
            Int_Mask_h       <= Wr_Data_q;
170
          when "011" =>
171
            Clear_Pending_l  <= Wr_Data_q;
172
          when "100" =>
173
            Clear_Pending_h  <= Wr_Data_q;
174
          when "101" =>
175
            Ack_IO_Ints      <= '1';
176
          when "110" =>
177
            IO_Qual_l        <= Wr_Data_q;
178
          when "111" =>
179
            IO_Qual_h        <= Wr_Data_q;
180
          when others =>
181
            null;
182
        end case;
183
      end if;
184
 
185
      Rd_Data                <= (others => '0');
186
      Rd_En_q                <= Rd_En_d;
187
      if( Rd_En_q = '1' )then
188
        case( Reg_Sel_q )is
189
          when "000" =>
190
            Rd_Data          <= Interval;
191
          when "001" =>
192
            Rd_Data          <= Int_Mask_l;
193
          when "010" =>
194
            Rd_Data          <= Int_Mask_h;
195
          when "011" =>
196
            Rd_Data          <= Pending_l;
197
          when "100" =>
198
            Rd_Data          <= Pending_h;
199
          when "101" =>
200
            Rd_Data          <= IO_Int_Pending & "0000000";
201
          when "110" =>
202
            Rd_Data          <= IO_Qual_l;
203
          when "111" =>
204
            Rd_Data          <= IO_Qual_h;
205
          when others =>
206
            null;
207
        end case;
208
      end if;
209
    end if;
210
  end process;
211
 
212
  Interval_proc: process( Clock, Reset )
213
  begin
214
    if( Reset = Reset_Level )then
215
      Timer_Cnt              <= x"00";
216
      PIT_Interrupt          <= '0';
217
    elsif( rising_edge(Clock) )then
218
      PIT_Interrupt              <= '0';
219
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
220
      if( Update_Interval = '1' )then
221
        Timer_Cnt            <= Interval;
222
      elsif( or_reduce(Timer_Cnt) = '0' )then
223
        Timer_Cnt            <= Interval;
224
        PIT_Interrupt        <= or_reduce(Interval); -- Only trigger on Int > 0
225
      end if;
226
    end if;
227
  end process;
228
 
229
  Interrupt_proc: process( Clock, Reset )
230
    variable i               : integer := 0;
231
  begin
232
    if( Reset = Reset_Level )then
233
      Pending                <= x"0000";
234
      Pending_q              <= x"0000";
235
      Pending_RE             <= x"0000";
236
      IO_Int_Pending         <= '0';
237
      IO_Interrupt           <= '0';
238
    elsif( rising_edge(Clock) )then
239
      for i in 0 to 15 loop
240
        if( IO_Interrupts_In(i) = '1' and Int_Mask(i) = '1' )then
241
          Pending(i)         <= '1';
242
        elsif( Clear_Pending(i) = '1' )then
243
          Pending(i)         <= '0';
244
        end if;
245
        Pending_q(i)         <= Pending(i);
246
        Pending_RE(i)        <= Pending(i) and not Pending_q(i);
247
      end loop;
248
 
249
      IO_Interrupt           <= '0';
250
      if( or_reduce(Pending_RE) = '1' and IO_Int_Pending = '0' )then
251
        IO_Int_Pending       <= '1';
252
        IO_Interrupt         <= '1';
253
      elsif( Ack_IO_Ints = '1' )then
254
        IO_Int_Pending       <= '0';
255
      end if;
256
 
257
    end if;
258
  end process;
259
 
260
end architecture;

powered by: WebSVN 2.1.0

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