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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [o8_sys_timer.vhd] - Blame information for rev 247

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

Line No. Rev Author Line
1 246 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
--
29
-- Revision History
30
-- Author          Date     Change
31
------------------ -------- ---------------------------------------------------
32
-- Seth Henry      07/28/11 Design Start
33
-- Seth Henry      12/19/19 Renamed Tmr_Out to Interrupt
34
-- Seth Henry      04/09/20 Modified timer update logic to reset the timer on
35
--                           interval write.
36
-- Seth Henry      04/16/20 Modified to use Open8 bus record
37
-- Seth Henry      05/18/20 Added write qualification input
38
 
39
library ieee;
40
use ieee.std_logic_1164.all;
41
  use ieee.std_logic_unsigned.all;
42
  use ieee.std_logic_arith.all;
43
  use ieee.std_logic_misc.all;
44
 
45
library work;
46
  use work.open8_pkg.all;
47
 
48
entity o8_sys_timer is
49
generic(
50
  mSec_Resolution            : boolean := FALSE;
51
  Address                    : ADDRESS_TYPE
52
);
53
port(
54
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
55
  Write_Qual                 : in  std_logic := '1';
56
  Rd_Data                    : out DATA_TYPE;
57
  Interrupt                  : out std_logic
58
);
59
end entity;
60
 
61
architecture behave of o8_sys_timer is
62
 
63
  alias Clock                is Open8_Bus.Clock;
64
  alias Reset                is Open8_Bus.Reset;
65
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
66
 
67
  constant User_Addr         : ADDRESS_TYPE := Address;
68
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 0);
69
  signal Addr_Match          : std_logic := '0';
70
 
71
  signal Wr_En_d             : std_logic;
72
  signal Wr_En_q             : std_logic := '0';
73
  alias  Wr_Data_d           is Open8_Bus.Wr_Data;
74
  signal Wr_Data_q           : DATA_TYPE := x"00";
75
  signal Rd_En_d               : std_logic := '0';
76
  signal Rd_En_q             : std_logic := '0';
77
 
78
  signal Interval            : DATA_TYPE := x"00";
79
  signal Update_Interval     : std_logic;
80
  signal Timer_Cnt           : DATA_TYPE := x"00";
81
 
82
  constant MSEC_DELAY        : std_logic_vector(9 downto 0) :=
83
                                conv_std_logic_vector(1000,10);
84
 
85
  signal mSec_Timer          : std_logic_vector(9 downto 0) := (others => '0');
86
 
87
  signal Timer_Tick          : std_logic := '0';
88
 
89
begin
90
 
91
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
92
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En;
93
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
94
 
95
mSec_Resolution_enabled : if( mSec_Resolution )generate
96
 
97
  mSec_Tick_proc: process( Clock, Reset )
98
  begin
99
    if( Reset = Reset_Level )then
100
      mSec_Timer             <= (others => '0');
101
      Timer_Tick             <= '0';
102
    elsif( rising_edge(Clock) )then
103
      mSec_Timer             <= mSec_Timer - uSec_Tick;
104
      Timer_Tick             <= '0';
105
      if( mSec_Timer = 0 )then
106
        mSec_Timer           <= MSEC_DELAY;
107
        Timer_Tick           <= '1';
108
      end if;
109
    end if;
110
  end process;
111
 
112
end generate;
113
 
114
uSec_Resolution_enabled : if( not mSec_Resolution )generate
115
 
116
  Timer_Tick                 <= uSec_Tick;
117
 
118
end generate;
119
 
120
  io_reg: process( Clock, Reset )
121
  begin
122
    if( Reset = Reset_Level )then
123
      Wr_En_q                <= '0';
124
      Wr_Data_q              <= x"00";
125
      Rd_En_q                <= '0';
126
      Rd_Data                <= OPEN8_NULLBUS;
127
      Interval               <= x"00";
128
      Update_Interval        <= '0';
129
    elsif( rising_edge( Clock ) )then
130
      Wr_En_q                <= Wr_En_d;
131
      Wr_Data_q              <= Wr_Data_d;
132
 
133
      Update_Interval        <= Wr_En_q and Write_Qual;
134
      if( Wr_En_q = '1' and Write_Qual = '1' )then
135
        Interval             <= Wr_Data_q;
136
      end if;
137
 
138
      Rd_Data                <= (others => '0');
139
      Rd_En_q                <= Rd_En_d;
140
      if( Rd_En_q = '1' )then
141
        Rd_Data              <= Interval;
142
      end if;
143
    end if;
144
  end process;
145
 
146
  Interval_proc: process( Clock, Reset )
147
  begin
148
    if( Reset = Reset_Level )then
149
      Timer_Cnt              <= x"00";
150
      Interrupt              <= '0';
151
    elsif( rising_edge(Clock) )then
152
      Interrupt              <= '0';
153
      Timer_Cnt              <= Timer_Cnt - Timer_Tick;
154
      if( Update_Interval = '1' )then
155
        Timer_Cnt            <= Interval;
156
      elsif( or_reduce(Timer_Cnt) = '0' )then
157
        Timer_Cnt            <= Interval;
158
        Interrupt            <= or_reduce(Interval); -- Only trigger on Int > 0
159
      end if;
160
    end if;
161
  end process;
162
 
163
end architecture;

powered by: WebSVN 2.1.0

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