Line 23... |
Line 23... |
--
|
--
|
-- VHDL Units : o8_sys_timer
|
-- VHDL Units : o8_sys_timer
|
-- Description: Provides an 8-bit microsecond resolution timer for generating
|
-- Description: Provides an 8-bit microsecond resolution timer for generating
|
-- : periodic interrupts for the Open8 CPU.
|
-- : periodic interrupts for the Open8 CPU.
|
--
|
--
|
-- Notes : It is possible to set the value to zero, resulting in the
|
|
-- : output staying high indefinitely. This may cause an issue if
|
|
-- : the output is connected to an interrupt input.
|
|
-- : Also provides uSec_Tick as an output
|
|
--
|
--
|
-- Revision History
|
-- Revision History
|
-- Author Date Change
|
-- Author Date Change
|
------------------ -------- ---------------------------------------------------
|
------------------ -------- ---------------------------------------------------
|
-- Seth Henry 07/28/11 Design Start
|
-- Seth Henry 07/28/11 Design Start
|
Line 49... |
Line 45... |
library work;
|
library work;
|
use work.open8_pkg.all;
|
use work.open8_pkg.all;
|
|
|
entity o8_sys_timer is
|
entity o8_sys_timer is
|
generic(
|
generic(
|
|
mSec_Resolution : boolean := FALSE;
|
Address : ADDRESS_TYPE
|
Address : ADDRESS_TYPE
|
);
|
);
|
port(
|
port(
|
Open8_Bus : in OPEN8_BUS_TYPE;
|
Open8_Bus : in OPEN8_BUS_TYPE;
|
Write_Qual : in std_logic := '1';
|
Write_Qual : in std_logic := '1';
|
Line 80... |
Line 77... |
|
|
signal Interval : DATA_TYPE := x"00";
|
signal Interval : DATA_TYPE := x"00";
|
signal Update_Interval : std_logic;
|
signal Update_Interval : std_logic;
|
signal Timer_Cnt : DATA_TYPE := x"00";
|
signal Timer_Cnt : DATA_TYPE := x"00";
|
|
|
|
constant MSEC_DELAY : std_logic_vector(9 downto 0) :=
|
|
conv_std_logic_vector(1000,10);
|
|
|
|
signal mSec_Timer : std_logic_vector(9 downto 0) := (others => '0');
|
|
|
|
signal Timer_Tick : std_logic := '0';
|
|
|
begin
|
begin
|
|
|
Addr_Match <= '1' when Comp_Addr = User_Addr else '0';
|
Addr_Match <= '1' when Comp_Addr = User_Addr else '0';
|
Wr_En_d <= Addr_Match and Open8_Bus.Wr_En;
|
Wr_En_d <= Addr_Match and Open8_Bus.Wr_En;
|
Rd_En_d <= Addr_Match and Open8_Bus.Rd_En;
|
Rd_En_d <= Addr_Match and Open8_Bus.Rd_En;
|
|
|
|
mSec_Resolution_enabled : if( mSec_Resolution )generate
|
|
|
|
mSec_Tick_proc: process( Clock, Reset )
|
|
begin
|
|
if( Reset = Reset_Level )then
|
|
mSec_Timer <= (others => '0');
|
|
Timer_Tick <= '0';
|
|
elsif( rising_edge(Clock) )then
|
|
mSec_Timer <= mSec_Timer - uSec_Tick;
|
|
Timer_Tick <= '0';
|
|
if( mSec_Timer = 0 )then
|
|
mSec_Timer <= MSEC_DELAY;
|
|
Timer_Tick <= '1';
|
|
end if;
|
|
end if;
|
|
end process;
|
|
|
|
end generate;
|
|
|
|
uSec_Resolution_enabled : if( not mSec_Resolution )generate
|
|
|
|
Timer_Tick <= uSec_Tick;
|
|
|
|
end generate;
|
|
|
io_reg: process( Clock, Reset )
|
io_reg: process( Clock, Reset )
|
begin
|
begin
|
if( Reset = Reset_Level )then
|
if( Reset = Reset_Level )then
|
Wr_En_q <= '0';
|
Wr_En_q <= '0';
|
Wr_Data_q <= x"00";
|
Wr_Data_q <= x"00";
|
Line 119... |
Line 148... |
if( Reset = Reset_Level )then
|
if( Reset = Reset_Level )then
|
Timer_Cnt <= x"00";
|
Timer_Cnt <= x"00";
|
Interrupt <= '0';
|
Interrupt <= '0';
|
elsif( rising_edge(Clock) )then
|
elsif( rising_edge(Clock) )then
|
Interrupt <= '0';
|
Interrupt <= '0';
|
Timer_Cnt <= Timer_Cnt - uSec_Tick;
|
Timer_Cnt <= Timer_Cnt - Timer_Tick;
|
if( Update_Interval = '1' )then
|
if( Update_Interval = '1' )then
|
Timer_Cnt <= Interval;
|
Timer_Cnt <= Interval;
|
elsif( or_reduce(Timer_Cnt) = '0' )then
|
elsif( or_reduce(Timer_Cnt) = '0' )then
|
Timer_Cnt <= Interval;
|
Timer_Cnt <= Interval;
|
Interrupt <= or_reduce(Interval); -- Only trigger on Int > 0
|
Interrupt <= or_reduce(Interval); -- Only trigger on Int > 0
|