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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_sys_timer_ii.vhd] - Blame information for rev 253

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

Line No. Rev Author Line
1 229 jshamlet
-- Copyright (c)2006, 2016, 2019, 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_sys_timer
25
-- Description:  Provides an 8-bit microsecond resolution timer for generating
26
--            :   periodic interrupts for the Open8 CPU.
27
--
28
-- Register Map:
29
-- Offset  Bitfield Description                        Read/Write
30
--   0x00  AAAAAAAA Req Interval Byte 0                   (RW)
31
--   0x01  AAAAAAAA Req Interval Byte 1                   (RW)
32
--   0x02  AAAAAAAA Req Interval Byte 2                   (RW)
33
--   0x03  BA------ Control/Status Register               (RW)
34 240 jshamlet
--                   A: Update timer (WR) or pending (RD) (RW)
35 229 jshamlet
--                   B: Output Enable
36
--
37
-- Notes      :  Setting the output to 0x000000 will disable the timer
38
--            :  Update pending is true if bit A is 1, otherwise false
39
--
40
-- Revision History
41
-- Author          Date     Change
42
------------------ -------- ---------------------------------------------------
43
-- Seth Henry      07/28/11 Design Start
44
-- Seth Henry      12/19/19 Renamed Tmr_Out to Interrupt
45
-- Seth Henry      04/09/20 Modified timer update logic to reset the timer on
46
--                           interval write.
47
-- Seth Henry      04/16/20 Modified to use Open8 bus record
48
-- Seth Henry      04/17/20 Altered interval to be a 24-bit counter
49 244 jshamlet
-- Seth Henry      05/18/20 Added write qualification input
50 229 jshamlet
 
51
library ieee;
52
use ieee.std_logic_1164.all;
53
  use ieee.std_logic_unsigned.all;
54
  use ieee.std_logic_arith.all;
55
  use ieee.std_logic_misc.all;
56
 
57
library work;
58
  use work.open8_pkg.all;
59
 
60
entity o8_sys_timer_ii is
61
generic(
62
  Address                    : ADDRESS_TYPE
63
);
64
port(
65
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
66 244 jshamlet
  Write_Qual                 : in  std_logic := '1';
67 229 jshamlet
  Rd_Data                    : out DATA_TYPE;
68
  Interrupt                  : out std_logic
69
);
70
end entity;
71
 
72
architecture behave of o8_sys_timer_ii is
73
 
74
  alias Clock                is Open8_Bus.Clock;
75
  alias Reset                is Open8_Bus.Reset;
76
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
77
 
78
  constant User_Addr         : std_logic_vector(15 downto 2) :=
79
                                Address(15 downto 2);
80
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 2);
81 244 jshamlet
  signal Addr_Match          : std_logic := '0';
82 229 jshamlet
 
83 244 jshamlet
  alias  Reg_Sel_d           is Open8_Bus.Address(1 downto 0);
84
  signal Reg_Sel_q           : std_logic_vector(1 downto 0) := "00";
85
  signal Wr_En_d             : std_logic;
86
  signal Wr_En_q             : std_logic := '0';
87
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
88 229 jshamlet
  signal Wr_Data_q           : DATA_TYPE := x"00";
89 244 jshamlet
  signal Rd_En_d             : std_logic := '0';
90 229 jshamlet
  signal Rd_En_q             : std_logic := '0';
91
 
92
  signal Req_Interval        : std_logic_vector(23 downto 0) := x"000000";
93
  alias  Req_Interval_B0     is Req_Interval( 7 downto  0);
94
  alias  Req_Interval_B1     is Req_Interval(15 downto  8);
95
  alias  Req_Interval_B2     is Req_Interval(23 downto 16);
96
 
97
  signal Int_Interval        : std_logic_vector(23 downto 0) := x"000000";
98
 
99
  signal Update_Interval     : std_logic := '0';
100
  signal Update_Pending      : std_logic := '0';
101
  signal Output_Enable       : std_logic := '0';
102
  signal Timer_Cnt           : std_logic_vector(23 downto 0) := x"000000";
103
 
104
begin
105
 
106
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
107 244 jshamlet
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En;
108
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
109 229 jshamlet
 
110
  io_reg: process( Clock, Reset )
111
  begin
112
    if( Reset = Reset_Level )then
113 244 jshamlet
      Reg_Sel_q              <= "00";
114
      Wr_En_q                <= '0';
115 229 jshamlet
      Wr_Data_q              <= x"00";
116 244 jshamlet
      Rd_En_q                <= '0';
117 229 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
118
      Req_Interval           <= x"000000";
119
      Update_Interval        <= '0';
120
      Update_Pending         <= '0';
121
      Output_Enable          <= '0';
122
    elsif( rising_edge( Clock ) )then
123 244 jshamlet
      Reg_Sel_q              <= Reg_Sel_d;
124 229 jshamlet
 
125 244 jshamlet
      Wr_En_q                <= Wr_En_d;
126
      Wr_Data_q              <= Wr_Data_d;
127 229 jshamlet
      Update_Interval        <= '0';
128 244 jshamlet
      if( Wr_En_q = '1' and Write_Qual = '1' )then
129
        case( Reg_Sel_q )is
130 229 jshamlet
          when "00" =>
131
            Req_Interval_B0  <= Wr_Data_q;
132
            Update_Pending   <= '1';
133
          when "01" =>
134
            Req_Interval_B1  <= Wr_Data_q;
135
            Update_Pending   <= '1';
136
          when "10" =>
137
            Req_Interval_B2  <= Wr_Data_q;
138
            Update_Pending   <= '1';
139
          when "11" =>
140
            Output_Enable    <= Wr_Data_q(7);
141
            Update_Interval  <= Wr_Data_q(6);
142
          when others => null;
143
        end case;
144
      end if;
145
 
146
      if( Update_Interval = '1' )then
147
        Update_Pending       <= '0';
148
      end if;
149
 
150
      Rd_Data                <= OPEN8_NULLBUS;
151 244 jshamlet
      Rd_En_q                <= Rd_En_d;
152
      if( Rd_En_q = '1' )then
153
        case( Reg_Sel_q )is
154 229 jshamlet
          when "00" =>
155
            Rd_Data          <= Req_Interval_B0;
156
          when "01" =>
157
            Rd_Data          <= Req_Interval_B1;
158
          when "10" =>
159
            Rd_Data          <= Req_Interval_B2;
160
          when "11" =>
161
            Rd_Data          <= Output_Enable & Update_Pending & "000000";
162
          when others => null;
163
        end case;
164
      end if;
165
    end if;
166
  end process;
167
 
168
  Interval_proc: process( Clock, Reset )
169
  begin
170
    if( Reset = Reset_Level )then
171
      Int_Interval           <= x"000000";
172
      Timer_Cnt              <= x"000000";
173
      Interrupt              <= '0';
174
    elsif( rising_edge(Clock) )then
175
      Interrupt              <= '0';
176
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
177
      if( Update_Interval = '1' )then
178
        Int_Interval         <= Req_Interval;
179
        Timer_Cnt            <= Req_Interval;
180
      elsif( or_reduce(Timer_Cnt) = '0' )then
181
        Timer_Cnt            <= Int_Interval;
182
        Interrupt            <= Output_Enable;
183
      end if;
184
    end if;
185
  end process;
186
 
187
end architecture;

powered by: WebSVN 2.1.0

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