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 229

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 229 jshamlet
-- Notes      :  Setting the output to 0x00 will disable the timer
29 180 jshamlet
--
30
-- Revision History
31
-- Author          Date     Change
32
------------------ -------- ---------------------------------------------------
33
-- Seth Henry      07/28/11 Design Start
34
-- Seth Henry      12/19/19 Renamed Tmr_Out to Interrupt
35 210 jshamlet
-- Seth Henry      04/09/20 Modified timer update logic to reset the timer on
36
--                           interval write.
37 224 jshamlet
-- Seth Henry      04/16/20 Modified to use Open8 bus record
38 167 jshamlet
 
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 184 jshamlet
entity o8_sys_timer is
49 167 jshamlet
generic(
50 210 jshamlet
  Address                    : ADDRESS_TYPE
51 167 jshamlet
);
52
port(
53 223 jshamlet
  Open8_Bus                  : in  OPEN8_BUS_TYPE;
54 210 jshamlet
  Rd_Data                    : out DATA_TYPE;
55
  Interrupt                  : out std_logic
56 167 jshamlet
);
57
end entity;
58
 
59 184 jshamlet
architecture behave of o8_sys_timer is
60 167 jshamlet
 
61 224 jshamlet
  alias Clock                is Open8_Bus.Clock;
62
  alias Reset                is Open8_Bus.Reset;
63
  alias uSec_Tick            is Open8_Bus.uSec_Tick;
64
 
65 210 jshamlet
  constant User_Addr         : ADDRESS_TYPE := Address;
66 223 jshamlet
  alias  Comp_Addr           is Open8_Bus.Address(15 downto 0);
67 210 jshamlet
  signal Addr_Match          : std_logic := '0';
68
  signal Wr_En               : std_logic := '0';
69 223 jshamlet
  signal Wr_Data_q           : DATA_TYPE := x"00";
70 210 jshamlet
  signal Rd_En               : std_logic := '0';
71
  signal Rd_En_q             : std_logic := '0';
72 167 jshamlet
 
73 210 jshamlet
  signal Interval            : DATA_TYPE := x"00";
74
  signal Update_Interval     : std_logic;
75
  signal Timer_Cnt           : DATA_TYPE := x"00";
76 167 jshamlet
 
77
begin
78
 
79 210 jshamlet
  Addr_Match                 <= '1' when Comp_Addr = User_Addr else '0';
80 167 jshamlet
 
81
  io_reg: process( Clock, Reset )
82
  begin
83
    if( Reset = Reset_Level )then
84 210 jshamlet
      Wr_En                  <= '0';
85
      Wr_Data_q              <= x"00";
86
      Rd_En                  <= '0';
87
      Rd_Data                <= OPEN8_NULLBUS;
88
      Interval               <= x"00";
89
      Update_Interval        <= '0';
90 167 jshamlet
    elsif( rising_edge( Clock ) )then
91 223 jshamlet
      Wr_En                  <= Addr_Match and Open8_Bus.Wr_En;
92
      Wr_Data_q              <= Open8_Bus.Wr_Data;
93 210 jshamlet
      Update_Interval        <= '0';
94 167 jshamlet
      if( Wr_En = '1' )then
95 211 jshamlet
        Interval             <= Wr_Data_q;
96 210 jshamlet
        Update_Interval      <= '1';
97 167 jshamlet
      end if;
98
 
99 229 jshamlet
      Rd_Data                <= OPEN8_NULLBUS;
100 223 jshamlet
      Rd_En                  <= Addr_Match and Open8_Bus.Rd_En;
101 167 jshamlet
      if( Rd_En = '1' )then
102 210 jshamlet
        Rd_Data              <= Interval;
103 167 jshamlet
      end if;
104
    end if;
105
  end process;
106
 
107
  Interval_proc: process( Clock, Reset )
108
  begin
109
    if( Reset = Reset_Level )then
110 210 jshamlet
      Timer_Cnt              <= x"00";
111
      Interrupt              <= '0';
112 167 jshamlet
    elsif( rising_edge(Clock) )then
113 210 jshamlet
      Interrupt              <= '0';
114 224 jshamlet
      Timer_Cnt              <= Timer_Cnt - uSec_Tick;
115 211 jshamlet
      if( Update_Interval = '1' )then
116 210 jshamlet
        Timer_Cnt            <= Interval;
117 211 jshamlet
      elsif( or_reduce(Timer_Cnt) = '0' )then
118
        Timer_Cnt            <= Interval;
119 210 jshamlet
        Interrupt            <= or_reduce(Interval); -- Only trigger on Int > 0
120 167 jshamlet
      end if;
121
    end if;
122
  end process;
123
 
124
end architecture;

powered by: WebSVN 2.1.0

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