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 242

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

Line No. Rev Author Line
1 194 jshamlet
-- Copyright (c)2006, 2016, 2019, 2020 Jeremy Seth Henry
2 167 jshamlet
-- 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 194 jshamlet
-- (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 167 jshamlet
--
24 184 jshamlet
-- VHDL Units :  o8_sys_timer
25 167 jshamlet
-- Description:  Provides an 8-bit microsecond resolution timer for generating
26
--            :   periodic interrupts for the Open8 CPU.
27
--
28 242 jshamlet
-- Notes      :  It is possible to set the value to zero, resulting in the
29
--            :   output staying high indefinitely. This may cause an issue if
30
--            :   the output is connected to an interrupt input.
31
--            :  Also provides uSec_Tick as an output
32 180 jshamlet
--
33
-- Revision History
34
-- Author          Date     Change
35
------------------ -------- ---------------------------------------------------
36
-- Seth Henry      07/28/11 Design Start
37
-- Seth Henry      12/19/19 Renamed Tmr_Out to Interrupt
38 210 jshamlet
-- Seth Henry      04/09/20 Modified timer update logic to reset the timer on
39
--                           interval write.
40 224 jshamlet
-- Seth Henry      04/16/20 Modified to use Open8 bus record
41 167 jshamlet
 
42
library ieee;
43
use ieee.std_logic_1164.all;
44
  use ieee.std_logic_unsigned.all;
45
  use ieee.std_logic_arith.all;
46
  use ieee.std_logic_misc.all;
47
 
48
library work;
49
  use work.open8_pkg.all;
50
 
51 184 jshamlet
entity o8_sys_timer is
52 167 jshamlet
generic(
53 242 jshamlet
  Write_Protect              : boolean := FALSE;
54 210 jshamlet
  Address                    : ADDRESS_TYPE
55 167 jshamlet
);
56
port(
57 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
58 210 jshamlet
  Rd_Data                    : out DATA_TYPE;
59
  Interrupt                  : out std_logic
60 167 jshamlet
);
61
end entity;
62
 
63 184 jshamlet
architecture behave of o8_sys_timer is
64 167 jshamlet
 
65 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
66
  alias Reset                is Open8_Bus.Reset;
67
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
68 242 jshamlet
  alias ISR_En               is Open8_Bus.GP_Flags(EXT_ISR);
69 224 jshamlet
 
70 242 jshamlet
  signal Wr_En_d             : std_logic;
71
  signal Rd_En_d             : std_logic;
72
 
73
  alias Wr_Data              is Open8_Bus.Wr_Data;
74
 
75 210 jshamlet
  constant User_Addr         : ADDRESS_TYPE := Address;
76 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 0);
77 210 jshamlet
  signal Addr_Match          : std_logic := '0';
78
  signal Wr_En               : std_logic := '0';
79 223 jshamlet
  signal Wr_Data_q           : DATA_TYPE := x"00";
80 210 jshamlet
  signal Rd_En               : std_logic := '0';
81
  signal Rd_En_q             : std_logic := '0';
82 167 jshamlet
 
83 210 jshamlet
  signal Interval            : DATA_TYPE := x"00";
84
  signal Update_Interval     : std_logic;
85
  signal Timer_Cnt           : DATA_TYPE := x"00";
86 167 jshamlet
 
87
begin
88
 
89 210 jshamlet
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
90 167 jshamlet
 
91 242 jshamlet
  -- If the Write_Protect generic is set only allow the memory to be written
92
  --  if the ISR bit is set. Otherwise, the memory should be read-only
93
 
94
Write_Protect_On : if( Write_Protect )generate
95
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En and ISR_En;
96
end generate;
97
 
98
Write_Protect_Off : if( not Write_Protect )generate
99
  Wr_En_d                    <= Addr_Match and Open8_Bus.Wr_En;
100
end generate;
101
 
102
  Rd_En_d                    <= Addr_Match and Open8_Bus.Rd_En;
103
 
104 167 jshamlet
  io_reg: process( Clock, Reset )
105
  begin
106
    if( Reset = Reset_Level )then
107 210 jshamlet
      Wr_En                  <= '0';
108
      Wr_Data_q              <= x"00";
109
      Rd_En                  <= '0';
110
      Rd_Data                <= OPEN8_NULLBUS;
111
      Interval               <= x"00";
112
      Update_Interval        <= '0';
113 167 jshamlet
    elsif( rising_edge( Clock ) )then
114 242 jshamlet
      Wr_En                  <= Wr_En_d;
115
      Wr_Data_q              <= Wr_Data;
116
 
117
      Update_Interval        <= Wr_En;
118 167 jshamlet
      if( Wr_En = '1' )then
119 211 jshamlet
        Interval             <= Wr_Data_q;
120 167 jshamlet
      end if;
121
 
122 242 jshamlet
      Rd_Data                <= (others => '0');
123
      Rd_En                  <= Rd_En_d;
124 167 jshamlet
      if( Rd_En = '1' )then
125 210 jshamlet
        Rd_Data              <= Interval;
126 167 jshamlet
      end if;
127
    end if;
128
  end process;
129
 
130
  Interval_proc: process( Clock, Reset )
131
  begin
132
    if( Reset = Reset_Level )then
133 210 jshamlet
      Timer_Cnt              <= x"00";
134
      Interrupt              <= '0';
135 167 jshamlet
    elsif( rising_edge(Clock) )then
136 210 jshamlet
      Interrupt              <= '0';
137 224 jshamlet
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
138 211 jshamlet
      if( Update_Interval = '1' )then
139 210 jshamlet
        Timer_Cnt            <= Interval;
140 211 jshamlet
      elsif( or_reduce(Timer_Cnt) = '0' )then
141
        Timer_Cnt            <= Interval;
142 210 jshamlet
        Interrupt            <= or_reduce(Interval); -- Only trigger on Int > 0
143 167 jshamlet
      end if;
144
    end if;
145
  end process;
146
 
147
end architecture;

powered by: WebSVN 2.1.0

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