cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
small_timer.vhd
Go to the documentation of this file.
1 -- /*******************************************************************************
2 -- * Copyright 2016 -- 2021 IBM Corporation
3 -- *
4 -- * Licensed under the Apache License, Version 2.0 (the "License");
5 -- * you may not use this file except in compliance with the License.
6 -- * You may obtain a copy of the License at
7 -- *
8 -- * http://www.apache.org/licenses/LICENSE-2.0
9 -- *
10 -- * Unless required by applicable law or agreed to in writing, software
11 -- * distributed under the License is distributed on an "AS IS" BASIS,
12 -- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 -- * See the License for the specific language governing permissions and
14 -- * limitations under the License.
15 -- *******************************************************************************/
16 
17 -- ************************************************
18 -- Copyright (c) 2015, Xilinx, Inc.
19 --
20 -- All rights reserved.
21 -- Redistribution and use in source and binary forms, with or without modification,
22 -- are permitted provided that the following conditions are met:
23 -- 1. Redistributions of source code must retain the above copyright notice,
24 -- this list of conditions and the following disclaimer.
25 -- 2. Redistributions in binary form must reproduce the above copyright notice,
26 -- this list of conditions and the following disclaimer in the documentation
27 -- and/or other materials provided with the distribution.
28 -- 3. Neither the name of the copyright holder nor the names of its contributors
29 -- may be used to endorse or promote products derived from this software
30 -- without specific prior written permission.
31 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32 -- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33 -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34 -- IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35 -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 -- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 -- INTERRUPT-- ION)
38 -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
39 -- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40 -- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 -- ************************************************
42 
43 -- *
44 -- * cloudFPGA
45 -- * =============================================
46 -- * Created: Feb 2020
47 -- * Authors: FAB, WEI, NGL
48 -- *
49 -- * Description:
50 -- * Small vhdl module to generate counters for minutes and hours of uptime
51 -- *
52 
53 library IEEE;
54 use IEEE.STD_LOGIC_1164.ALL;
55 use IEEE.NUMERIC_STD.ALL;
56 
57 
58 entity smallTimer is
59  generic(clockFrequencyHz : integer);
60  port(
61  piClk : in std_ulogic;
62  piSyncRst : in std_ulogic;
63  poSeconds : out std_ulogic_vector(31 downto 0);
64  poMinutes : out std_ulogic_vector(31 downto 0);
65  poHours : out std_ulogic_vector(31 downto 0));
66 end entity;
67 
68 architecture RTL of smallTimer is
69 
70  -- Signal for counting clock periods
71  signal ticks : std_ulogic_vector(63 downto 0);
72  signal seconds : std_ulogic_vector(31 downto 0);
73  signal minutes : std_ulogic_vector(31 downto 0);
74  signal hours : std_ulogic_vector(31 downto 0);
75 
76 begin
77 
78  process(piClk) is
79  begin
80  if rising_edge(piClk) then
81 
82  if piSyncRst = '1' then
83  ticks <= (others => '0');
84  seconds <= (others => '0');
85  minutes <= (others => '0');
86  hours <= (others => '0');
87  else
88  -- True once every second
89  if unsigned(ticks) = ClockFrequencyHz - 1 then
90  ticks <= (others => '0');
91 
92  if unsigned(seconds) = 59 then
93  seconds <= (others => '0');
94 
95  if unsigned(minutes) = 59 then
96  minutes <= (others => '0');
97 
98  if unsigned(hours) = 23 then
99  hours <= (others => '0');
100  else
101  hours <= std_ulogic_vector(unsigned(hours) + 1);
102  end if;
103 
104  else
105  minutes <= std_ulogic_vector(unsigned(minutes) + 1);
106  end if;
107 
108  else
109  seconds <= std_ulogic_vector(unsigned(seconds) + 1);
110  end if;
111 
112  else
113  ticks <= std_ulogic_vector(unsigned(ticks) + 1);
114  end if;
115 
116  end if;
117  end if;
118  end process;
119 
120  poSeconds <= seconds;
121  poMinutes <= minutes;
122  poHours <= hours;
123 
124 end architecture;
125 
126 
clockFrequencyHzinteger
Definition: small_timer.vhd:59
in piClkstd_ulogic
Definition: small_timer.vhd:61
out poHoursstd_ulogic_vector(31 downto 0)
Definition: small_timer.vhd:65
out poMinutesstd_ulogic_vector(31 downto 0)
Definition: small_timer.vhd:64
in piSyncRststd_ulogic
Definition: small_timer.vhd:62
out poSecondsstd_ulogic_vector(31 downto 0)
Definition: small_timer.vhd:63