| 1 |
229 |
jshamlet |
-- Copyright (c)2006, 2016, 2019, 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
|
| 22 |
|
|
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
|
|
--
|
| 24 |
|
|
-- VHDL Units : o8_sys_timer
|
| 25 |
308 |
jshamlet |
-- Description: Provides an 24-bit microsecond resolution timer for generating
|
| 26 |
229 |
jshamlet |
-- : periodic interrupts for the Open8 CPU.
|
| 27 |
|
|
--
|
| 28 |
|
|
-- Register Map:
|
| 29 |
|
|
-- Offset Bitfield Description Read/Write
|
| 30 |
|
|
-- 0x00 AAAAAAAA Req Interval Byte 0 (RW)
|
| 31 |
|
|
-- 0x01 AAAAAAAA Req Interval Byte 1 (RW)
|
| 32 |
|
|
-- 0x02 AAAAAAAA Req Interval Byte 2 (RW)
|
| 33 |
|
|
-- 0x03 BA------ Control/Status Register (RW)
|
| 34 |
240 |
jshamlet |
-- A: Update timer (WR) or pending (RD) (RW)
|
| 35 |
229 |
jshamlet |
-- B: Output Enable
|
| 36 |
|
|
--
|
| 37 |
|
|
-- Notes : Setting the output to 0x000000 will disable the timer
|
| 38 |
|
|
-- : Update pending is true if bit A is 1, otherwise false
|
| 39 |
|
|
--
|
| 40 |
|
|
-- Revision History
|
| 41 |
|
|
-- Author Date Change
|
| 42 |
|
|
------------------ -------- ---------------------------------------------------
|
| 43 |
|
|
-- Seth Henry 07/28/11 Design Start
|
| 44 |
|
|
-- Seth Henry 12/19/19 Renamed Tmr_Out to Interrupt
|
| 45 |
|
|
-- Seth Henry 04/09/20 Modified timer update logic to reset the timer on
|
| 46 |
|
|
-- interval write.
|
| 47 |
|
|
-- Seth Henry 04/16/20 Modified to use Open8 bus record
|
| 48 |
|
|
-- Seth Henry 04/17/20 Altered interval to be a 24-bit counter
|
| 49 |
244 |
jshamlet |
-- Seth Henry 05/18/20 Added write qualification input
|
| 50 |
308 |
jshamlet |
-- Seth Henry 01/18/23 Added microsecond/millisecond generic
|
| 51 |
229 |
jshamlet |
|
| 52 |
308 |
jshamlet |
|
| 53 |
229 |
jshamlet |
library ieee;
|
| 54 |
|
|
use ieee.std_logic_1164.all;
|
| 55 |
|
|
use ieee.std_logic_unsigned.all;
|
| 56 |
|
|
use ieee.std_logic_arith.all;
|
| 57 |
|
|
use ieee.std_logic_misc.all;
|
| 58 |
|
|
|
| 59 |
|
|
library work;
|
| 60 |
|
|
use work.open8_pkg.all;
|
| 61 |
|
|
|
| 62 |
|
|
entity o8_sys_timer_ii is
|
| 63 |
|
|
generic(
|
| 64 |
308 |
jshamlet |
mSec_Resolution : boolean := FALSE;
|
| 65 |
229 |
jshamlet |
Address : ADDRESS_TYPE
|
| 66 |
|
|
);
|
| 67 |
|
|
port(
|
| 68 |
|
|
Open8_Bus : in OPEN8_BUS_TYPE;
|
| 69 |
244 |
jshamlet |
Write_Qual : in std_logic := '1';
|
| 70 |
229 |
jshamlet |
Rd_Data : out DATA_TYPE;
|
| 71 |
|
|
Interrupt : out std_logic
|
| 72 |
|
|
);
|
| 73 |
|
|
end entity;
|
| 74 |
|
|
|
| 75 |
|
|
architecture behave of o8_sys_timer_ii is
|
| 76 |
|
|
|
| 77 |
|
|
alias Clock is Open8_Bus.Clock;
|
| 78 |
|
|
alias Reset is Open8_Bus.Reset;
|
| 79 |
|
|
alias uSec_Tick is Open8_Bus.uSec_Tick;
|
| 80 |
|
|
|
| 81 |
|
|
constant User_Addr : std_logic_vector(15 downto 2) :=
|
| 82 |
|
|
Address(15 downto 2);
|
| 83 |
|
|
alias Comp_Addr is Open8_Bus.Address(15 downto 2);
|
| 84 |
244 |
jshamlet |
signal Addr_Match : std_logic := '0';
|
| 85 |
229 |
jshamlet |
|
| 86 |
244 |
jshamlet |
alias Reg_Sel_d is Open8_Bus.Address(1 downto 0);
|
| 87 |
|
|
signal Reg_Sel_q : std_logic_vector(1 downto 0) := "00";
|
| 88 |
|
|
signal Wr_En_d : std_logic;
|
| 89 |
|
|
signal Wr_En_q : std_logic := '0';
|
| 90 |
|
|
alias Wr_Data_d is Open8_Bus.Wr_Data;
|
| 91 |
229 |
jshamlet |
signal Wr_Data_q : DATA_TYPE := x"00";
|
| 92 |
244 |
jshamlet |
signal Rd_En_d : std_logic := '0';
|
| 93 |
229 |
jshamlet |
signal Rd_En_q : std_logic := '0';
|
| 94 |
|
|
|
| 95 |
|
|
signal Req_Interval : std_logic_vector(23 downto 0) := x"000000";
|
| 96 |
|
|
alias Req_Interval_B0 is Req_Interval( 7 downto 0);
|
| 97 |
|
|
alias Req_Interval_B1 is Req_Interval(15 downto 8);
|
| 98 |
|
|
alias Req_Interval_B2 is Req_Interval(23 downto 16);
|
| 99 |
|
|
|
| 100 |
|
|
signal Int_Interval : std_logic_vector(23 downto 0) := x"000000";
|
| 101 |
|
|
|
| 102 |
|
|
signal Update_Interval : std_logic := '0';
|
| 103 |
|
|
signal Update_Pending : std_logic := '0';
|
| 104 |
|
|
signal Output_Enable : std_logic := '0';
|
| 105 |
|
|
signal Timer_Cnt : std_logic_vector(23 downto 0) := x"000000";
|
| 106 |
|
|
|
| 107 |
308 |
jshamlet |
constant MSEC_DELAY : std_logic_vector(9 downto 0) :=
|
| 108 |
|
|
conv_std_logic_vector(1000,10);
|
| 109 |
|
|
|
| 110 |
|
|
signal mSec_Timer : std_logic_vector(9 downto 0) := (others => '0');
|
| 111 |
|
|
|
| 112 |
|
|
signal Timer_Tick : std_logic := '0';
|
| 113 |
|
|
|
| 114 |
229 |
jshamlet |
begin
|
| 115 |
|
|
|
| 116 |
|
|
Addr_Match <= '1' when Comp_Addr = User_Addr else '0';
|
| 117 |
244 |
jshamlet |
Wr_En_d <= Addr_Match and Open8_Bus.Wr_En;
|
| 118 |
|
|
Rd_En_d <= Addr_Match and Open8_Bus.Rd_En;
|
| 119 |
229 |
jshamlet |
|
| 120 |
308 |
jshamlet |
mSec_Resolution_enabled : if( mSec_Resolution )generate
|
| 121 |
|
|
|
| 122 |
|
|
mSec_Tick_proc: process( Clock, Reset )
|
| 123 |
|
|
begin
|
| 124 |
|
|
if( Reset = Reset_Level )then
|
| 125 |
|
|
mSec_Timer <= (others => '0');
|
| 126 |
|
|
Timer_Tick <= '0';
|
| 127 |
|
|
elsif( rising_edge(Clock) )then
|
| 128 |
|
|
mSec_Timer <= mSec_Timer - uSec_Tick;
|
| 129 |
|
|
Timer_Tick <= '0';
|
| 130 |
|
|
if( mSec_Timer = 0 )then
|
| 131 |
|
|
mSec_Timer <= MSEC_DELAY;
|
| 132 |
|
|
Timer_Tick <= '1';
|
| 133 |
|
|
end if;
|
| 134 |
|
|
end if;
|
| 135 |
|
|
end process;
|
| 136 |
|
|
|
| 137 |
|
|
end generate;
|
| 138 |
|
|
|
| 139 |
|
|
uSec_Resolution_enabled : if( not mSec_Resolution )generate
|
| 140 |
|
|
|
| 141 |
|
|
Timer_Tick <= uSec_Tick;
|
| 142 |
|
|
|
| 143 |
|
|
end generate;
|
| 144 |
|
|
|
| 145 |
229 |
jshamlet |
io_reg: process( Clock, Reset )
|
| 146 |
|
|
begin
|
| 147 |
|
|
if( Reset = Reset_Level )then
|
| 148 |
244 |
jshamlet |
Reg_Sel_q <= "00";
|
| 149 |
|
|
Wr_En_q <= '0';
|
| 150 |
229 |
jshamlet |
Wr_Data_q <= x"00";
|
| 151 |
244 |
jshamlet |
Rd_En_q <= '0';
|
| 152 |
229 |
jshamlet |
Rd_Data <= OPEN8_NULLBUS;
|
| 153 |
|
|
Req_Interval <= x"000000";
|
| 154 |
|
|
Update_Interval <= '0';
|
| 155 |
|
|
Update_Pending <= '0';
|
| 156 |
|
|
Output_Enable <= '0';
|
| 157 |
|
|
elsif( rising_edge( Clock ) )then
|
| 158 |
244 |
jshamlet |
Reg_Sel_q <= Reg_Sel_d;
|
| 159 |
229 |
jshamlet |
|
| 160 |
244 |
jshamlet |
Wr_En_q <= Wr_En_d;
|
| 161 |
|
|
Wr_Data_q <= Wr_Data_d;
|
| 162 |
229 |
jshamlet |
Update_Interval <= '0';
|
| 163 |
244 |
jshamlet |
if( Wr_En_q = '1' and Write_Qual = '1' )then
|
| 164 |
|
|
case( Reg_Sel_q )is
|
| 165 |
229 |
jshamlet |
when "00" =>
|
| 166 |
|
|
Req_Interval_B0 <= Wr_Data_q;
|
| 167 |
|
|
Update_Pending <= '1';
|
| 168 |
|
|
when "01" =>
|
| 169 |
|
|
Req_Interval_B1 <= Wr_Data_q;
|
| 170 |
|
|
Update_Pending <= '1';
|
| 171 |
|
|
when "10" =>
|
| 172 |
|
|
Req_Interval_B2 <= Wr_Data_q;
|
| 173 |
|
|
Update_Pending <= '1';
|
| 174 |
|
|
when "11" =>
|
| 175 |
|
|
Output_Enable <= Wr_Data_q(7);
|
| 176 |
|
|
Update_Interval <= Wr_Data_q(6);
|
| 177 |
|
|
when others => null;
|
| 178 |
|
|
end case;
|
| 179 |
|
|
end if;
|
| 180 |
|
|
|
| 181 |
|
|
if( Update_Interval = '1' )then
|
| 182 |
|
|
Update_Pending <= '0';
|
| 183 |
|
|
end if;
|
| 184 |
|
|
|
| 185 |
|
|
Rd_Data <= OPEN8_NULLBUS;
|
| 186 |
244 |
jshamlet |
Rd_En_q <= Rd_En_d;
|
| 187 |
|
|
if( Rd_En_q = '1' )then
|
| 188 |
|
|
case( Reg_Sel_q )is
|
| 189 |
229 |
jshamlet |
when "00" =>
|
| 190 |
|
|
Rd_Data <= Req_Interval_B0;
|
| 191 |
|
|
when "01" =>
|
| 192 |
|
|
Rd_Data <= Req_Interval_B1;
|
| 193 |
|
|
when "10" =>
|
| 194 |
|
|
Rd_Data <= Req_Interval_B2;
|
| 195 |
|
|
when "11" =>
|
| 196 |
|
|
Rd_Data <= Output_Enable & Update_Pending & "000000";
|
| 197 |
|
|
when others => null;
|
| 198 |
|
|
end case;
|
| 199 |
|
|
end if;
|
| 200 |
|
|
end if;
|
| 201 |
|
|
end process;
|
| 202 |
|
|
|
| 203 |
|
|
Interval_proc: process( Clock, Reset )
|
| 204 |
|
|
begin
|
| 205 |
|
|
if( Reset = Reset_Level )then
|
| 206 |
|
|
Int_Interval <= x"000000";
|
| 207 |
|
|
Timer_Cnt <= x"000000";
|
| 208 |
|
|
Interrupt <= '0';
|
| 209 |
|
|
elsif( rising_edge(Clock) )then
|
| 210 |
|
|
Interrupt <= '0';
|
| 211 |
308 |
jshamlet |
Timer_Cnt <= Timer_Cnt - Timer_Tick;
|
| 212 |
229 |
jshamlet |
if( Update_Interval = '1' )then
|
| 213 |
|
|
Int_Interval <= Req_Interval;
|
| 214 |
|
|
Timer_Cnt <= Req_Interval;
|
| 215 |
|
|
elsif( or_reduce(Timer_Cnt) = '0' )then
|
| 216 |
|
|
Timer_Cnt <= Int_Interval;
|
| 217 |
|
|
Interrupt <= Output_Enable;
|
| 218 |
|
|
end if;
|
| 219 |
|
|
end if;
|
| 220 |
|
|
end process;
|
| 221 |
|
|
|
| 222 |
|
|
end architecture;
|