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

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [VHDL/] [sys_tick.vhd] - Blame information for rev 271

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

Line No. Rev Author Line
1 258 jshamlet
-- Copyright (c)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 THIS
22
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
--
24
-- VHDL Entity: sys_tick
25
-- Description: Provides a single clock tick every microsecond and millisecond.
26
--               Requires that the system clock frequency be passed as a real.
27
--
28
-- Revision History
29
-- Author          Date     Change
30
------------------ -------- ---------------------------------------------------
31
-- Seth Henry      04/16/20 Code cleanup and revision section added
32
 
33
library ieee;
34
  use ieee.std_logic_1164.all;
35
  use ieee.std_logic_unsigned.all;
36
  use ieee.std_logic_arith.all;
37
  use ieee.std_logic_misc.all;
38
 
39
entity sys_tick is
40
generic(
41
  Reset_Level           : std_logic;
42
  Sys_Freq              : real := 50000000.0
43
);
44
port(
45
  Clock                 : in  std_logic;
46
  Reset                 : in  std_logic;
47
  uSec_Tick             : out std_logic;
48
  mSec_Tick             : out std_logic
49
);
50
end entity;
51
 
52
architecture behave of sys_tick is
53
 
54
  -- The ceil_log2 function returns the minimum register width required to
55
  --  hold the supplied integer.
56
  function ceil_log2 (x : in natural) return natural is
57
    variable retval          : natural;
58
  begin
59
    retval                   := 1;
60
    while ((2**retval) - 1) < x loop
61
      retval                 := retval + 1;
62
    end loop;
63
    return retval;
64
  end ceil_log2;
65
 
66
  constant DLY_1USEC_VAL     : integer := integer(Sys_Freq / 1000000.0);
67
  constant DLY_1USEC_WDT     : integer := ceil_log2(DLY_1USEC_VAL - 1);
68
  constant DLY_1USEC         : std_logic_vector :=
69
                                conv_std_logic_vector( DLY_1USEC_VAL - 1, DLY_1USEC_WDT);
70
  signal uSec_Cntr           : std_logic_vector( DLY_1USEC_WDT - 1 downto 0 );
71
 
72
  constant MSEC_DELAY        : std_logic_vector(9 downto 0) :=
73
                                conv_std_logic_vector(1000,10);
74
 
75
  signal mSec_Timer          : std_logic_vector(9 downto 0) := (others => '0');
76
 
77
begin
78
 
79
  Tick_proc: process( Clock, Reset )
80
  begin
81
    if( Reset = Reset_Level )then
82
      uSec_Cntr              <= DLY_1USEC;
83
      uSec_Tick              <= '0';
84
 
85
      mSec_Timer             <= (others => '0');
86
      mSec_Tick              <= '0';
87
    elsif( rising_edge( Clock ) )then
88
      uSec_Cntr              <= uSec_Cntr - 1;
89
      uSec_Tick              <= '0';
90
      if( or_reduce(uSec_Cntr) = '0' )then
91
        uSec_Cntr            <= DLY_1USEC;
92
        uSec_Tick            <= '1';
93
        mSec_Timer           <= mSec_Timer - 1;
94
      end if;
95
 
96
      mSec_Tick              <= '0';
97
      if( mSec_Timer = 0 )then
98
        mSec_Timer           <= MSEC_DELAY;
99
        mSec_Tick            <= '1';
100
      end if;
101
    end if;
102
  end process;
103
 
104
end architecture;

powered by: WebSVN 2.1.0

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