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 240

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
 
50
library ieee;
51
use ieee.std_logic_1164.all;
52
  use ieee.std_logic_unsigned.all;
53
  use ieee.std_logic_arith.all;
54
  use ieee.std_logic_misc.all;
55
 
56
library work;
57
  use work.open8_pkg.all;
58
 
59
entity o8_sys_timer_ii is
60
generic(
61
  Address                    : ADDRESS_TYPE
62
);
63
port(
64
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
65
  Rd_Data                    : out DATA_TYPE;
66
  Interrupt                  : out std_logic
67
);
68
end entity;
69
 
70
architecture behave of o8_sys_timer_ii is
71
 
72
  alias Clock                is Open8_Bus.Clock;
73
  alias Reset                is Open8_Bus.Reset;
74
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
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
  alias  Reg_Addr            is Open8_Bus.Address(1 downto 0);
80
 
81
  signal Addr_Match          : std_logic := '0';
82
  signal Reg_Sel             : std_logic_vector(1 downto 0) := "00";
83
  signal Wr_En               : std_logic := '0';
84
  signal Wr_Data_q           : DATA_TYPE := x"00";
85
  signal Rd_En               : std_logic := '0';
86
  signal Rd_En_q             : std_logic := '0';
87
 
88
  signal Req_Interval        : std_logic_vector(23 downto 0) := x"000000";
89
  alias  Req_Interval_B0     is Req_Interval( 7 downto  0);
90
  alias  Req_Interval_B1     is Req_Interval(15 downto  8);
91
  alias  Req_Interval_B2     is Req_Interval(23 downto 16);
92
 
93
  signal Int_Interval        : std_logic_vector(23 downto 0) := x"000000";
94
 
95
  signal Update_Interval     : std_logic := '0';
96
  signal Update_Pending      : std_logic := '0';
97
  signal Output_Enable       : std_logic := '0';
98
  signal Timer_Cnt           : std_logic_vector(23 downto 0) := x"000000";
99
 
100
begin
101
 
102
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
103
 
104
  io_reg: process( Clock, Reset )
105
  begin
106
    if( Reset = Reset_Level )then
107
      Reg_Sel                <= "00";
108
      Wr_En                  <= '0';
109
      Wr_Data_q              <= x"00";
110
      Rd_En                  <= '0';
111
      Rd_Data                <= OPEN8_NULLBUS;
112
      Req_Interval           <= x"000000";
113
      Update_Interval        <= '0';
114
      Update_Pending         <= '0';
115
      Output_Enable          <= '0';
116
    elsif( rising_edge( Clock ) )then
117
      Reg_Sel                <= Reg_Addr;
118
 
119
      Wr_En                  <= Addr_Match and Open8_Bus.Wr_En;
120
      Wr_Data_q              <= Open8_Bus.Wr_Data;
121
      Update_Interval        <= '0';
122
      if( Wr_En = '1' )then
123
        case( Reg_Sel )is
124
          when "00" =>
125
            Req_Interval_B0  <= Wr_Data_q;
126
            Update_Pending   <= '1';
127
          when "01" =>
128
            Req_Interval_B1  <= Wr_Data_q;
129
            Update_Pending   <= '1';
130
          when "10" =>
131
            Req_Interval_B2  <= Wr_Data_q;
132
            Update_Pending   <= '1';
133
          when "11" =>
134
            Output_Enable    <= Wr_Data_q(7);
135
            Update_Interval  <= Wr_Data_q(6);
136
          when others => null;
137
        end case;
138
      end if;
139
 
140
      if( Update_Interval = '1' )then
141
        Update_Pending       <= '0';
142
      end if;
143
 
144
      Rd_Data                <= OPEN8_NULLBUS;
145
      Rd_En                  <= Addr_Match and Open8_Bus.Rd_En;
146
      if( Rd_En = '1' )then
147
        case( Reg_Sel )is
148
          when "00" =>
149
            Rd_Data          <= Req_Interval_B0;
150
          when "01" =>
151
            Rd_Data          <= Req_Interval_B1;
152
          when "10" =>
153
            Rd_Data          <= Req_Interval_B2;
154
          when "11" =>
155
            Rd_Data          <= Output_Enable & Update_Pending & "000000";
156
          when others => null;
157
        end case;
158
      end if;
159
    end if;
160
  end process;
161
 
162
  Interval_proc: process( Clock, Reset )
163
  begin
164
    if( Reset = Reset_Level )then
165
      Int_Interval           <= x"000000";
166
      Timer_Cnt              <= x"000000";
167
      Interrupt              <= '0';
168
    elsif( rising_edge(Clock) )then
169
      Interrupt              <= '0';
170
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
171
      if( Update_Interval = '1' )then
172
        Int_Interval         <= Req_Interval;
173
        Timer_Cnt            <= Req_Interval;
174
      elsif( or_reduce(Timer_Cnt) = '0' )then
175
        Timer_Cnt            <= Int_Interval;
176
        Interrupt            <= Output_Enable;
177
      end if;
178
    end if;
179
  end process;
180
 
181
end architecture;

powered by: WebSVN 2.1.0

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