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 186

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

Line No. Rev Author Line
1 180 jshamlet
-- Copyright (c)2006, 2016, 2019 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
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
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
-- 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 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
  Sys_Freq              : real;
51
  Reset_Level           : std_logic;
52
  Address               : ADDRESS_TYPE
53
);
54
port(
55
  Clock                 : in  std_logic;
56
  Reset                 : in  std_logic;
57
  uSec_Tick             : out std_logic;
58
  --
59
  Bus_Address           : in  ADDRESS_TYPE;
60
  Wr_Enable             : in  std_logic;
61
  Wr_Data               : in  DATA_TYPE;
62
  Rd_Enable             : in  std_logic;
63
  Rd_Data               : out DATA_TYPE;
64 180 jshamlet
  Interrupt             : out std_logic
65 167 jshamlet
);
66
end entity;
67
 
68 184 jshamlet
architecture behave of o8_sys_timer is
69 167 jshamlet
 
70
  constant User_Addr    : ADDRESS_TYPE := Address;
71
  alias  Comp_Addr      is Bus_Address(15 downto 0);
72
  signal Addr_Match     : std_logic;
73
  signal Wr_En          : std_logic;
74
  signal Wr_Data_q      : DATA_TYPE;
75
  signal Rd_En          : std_logic;
76
  signal Rd_En_q        : std_logic;
77
 
78
  signal Interval       : DATA_TYPE;
79
  signal Timer_Cnt      : DATA_TYPE;
80
 
81
  -- The ceil_log2 function returns the minimum register width required to
82
  --  hold the supplied integer.
83
  function ceil_log2 (x : in natural) return natural is
84
    variable retval          : natural;
85
  begin
86
    retval                   := 1;
87
    while ((2**retval) - 1) < x loop
88
      retval                 := retval + 1;
89
    end loop;
90
    return retval;
91
  end ceil_log2;
92
 
93
  constant DLY_1USEC_VAL: integer := integer(Sys_Freq / 1000000.0);
94
  constant DLY_1USEC_WDT: integer := ceil_log2(DLY_1USEC_VAL - 1);
95
  constant DLY_1USEC    : std_logic_vector :=
96 180 jshamlet
                      conv_std_logic_vector(DLY_1USEC_VAL - 1, DLY_1USEC_WDT);
97 167 jshamlet
 
98
  signal uSec_Cntr      : std_logic_vector( DLY_1USEC_WDT - 1 downto 0 )
99
                          := (others => '0');
100
  signal uSec_Tick_i      : std_logic;
101
begin
102
 
103
  uSec_Tick             <= uSec_Tick_i;
104
  Addr_Match            <= '1' when Comp_Addr = User_Addr else '0';
105
 
106
  io_reg: process( Clock, Reset )
107
  begin
108
    if( Reset = Reset_Level )then
109
      Wr_En             <= '0';
110
      Wr_Data_q         <= x"00";
111
      Rd_En             <= '0';
112
      Rd_Data           <= x"00";
113
      Interval          <= x"00";
114
    elsif( rising_edge( Clock ) )then
115
      Wr_En             <= Addr_Match and Wr_Enable;
116
      Wr_Data_q         <= Wr_Data;
117
      if( Wr_En = '1' )then
118
        Interval        <= Wr_Data_q;
119
      end if;
120
 
121
      Rd_Data           <= (others => '0');
122
      Rd_En             <= Addr_Match and Rd_Enable;
123
      if( Rd_En = '1' )then
124
        Rd_Data         <= Interval;
125
      end if;
126
    end if;
127
  end process;
128
 
129
  uSec_Tick_i_proc: process( Clock, Reset )
130
  begin
131
    if( Reset = Reset_Level )then
132
      uSec_Cntr         <= (others => '0');
133
      uSec_Tick_i       <= '0';
134
    elsif( rising_edge( Clock ) )then
135
      uSec_Cntr         <= uSec_Cntr - 1;
136
      uSec_Tick_i       <= '0';
137
      if( uSec_Cntr = 0 )then
138
        uSec_Cntr       <= DLY_1USEC;
139 180 jshamlet
        uSec_Tick_i     <= '1';
140 167 jshamlet
      end if;
141
    end if;
142
  end process;
143
 
144
  Interval_proc: process( Clock, Reset )
145
  begin
146
    if( Reset = Reset_Level )then
147
      Timer_Cnt         <= x"00";
148 180 jshamlet
      Interrupt         <= '0';
149 167 jshamlet
    elsif( rising_edge(Clock) )then
150 180 jshamlet
      Interrupt         <= '0';
151 167 jshamlet
      Timer_Cnt         <= Timer_Cnt - uSec_Tick_i;
152
      if( or_reduce(Timer_Cnt) = '0' )then
153
        Timer_Cnt       <= Interval;
154 180 jshamlet
        Interrupt       <= or_reduce(Interval); -- Only trigger on Int > 0
155 167 jshamlet
      end if;
156
    end if;
157
  end process;
158
 
159
end architecture;

powered by: WebSVN 2.1.0

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