1 |
212 |
jshamlet |
-- Copyright (c)2011, 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_epoch_timer
|
25 |
|
|
-- Description: Provides a 24-bit, 4uS resolution elapsed timer with
|
26 |
|
|
-- : alarm and interrupt for the Open8 CPU.
|
27 |
|
|
--
|
28 |
|
|
-- Notes : Requires an externally provided uSec tick input - one clock
|
29 |
|
|
-- : per microsecond.
|
30 |
|
|
--
|
31 |
|
|
-- Register Map:
|
32 |
|
|
-- Offset Bitfield Description Read/Write
|
33 |
|
|
-- 0x0 AAAAAAAA B0 of Buffered Setpoint (W) or Current Setpoint(R)
|
34 |
|
|
-- 0x1 AAAAAAAA B1 of Buffered Setpoint (W) or Current Setpoint(R)
|
35 |
222 |
jshamlet |
-- 0x2 AAAAAAAA B2 of Buffered Setpoint (W) or Current Setpoint(R)
|
36 |
212 |
jshamlet |
-- 0x3 BA------ Status of buffer/alarm (1 = pending, 0 = current)
|
37 |
222 |
jshamlet |
-- A = Pending status (R)
|
38 |
|
|
-- B = Alarm status (R)
|
39 |
|
|
-- Note that any write will update the internal set point
|
40 |
|
|
-- and clear the alarm
|
41 |
|
|
-- 0x4 AAAAAAAA B0 of Current Epoch Time(RO)
|
42 |
|
|
-- 0x5 AAAAAAAA B1 of Current Epoch Time(RO)
|
43 |
|
|
-- 0x6 AAAAAAAA B2 of Current Epoch Time(RO)
|
44 |
|
|
-- Note that any write to 0x04,0x05, or 0x06 will copy the
|
45 |
|
|
-- current epoch time to a readable output buffer
|
46 |
|
|
-- 0x7 -------- Epoch Time Latch/Clear Control Register
|
47 |
|
|
-- Any write to 0x7 will clear/reset the all timer regs
|
48 |
212 |
jshamlet |
--
|
49 |
|
|
-- Revision History
|
50 |
|
|
-- Author Date Change
|
51 |
|
|
------------------ -------- ---------------------------------------------------
|
52 |
|
|
-- Seth Henry 07/28/11 Design Start
|
53 |
|
|
-- Seth Henry 12/19/19 Renamed to "o8_epoch_timer" to fit "theme"
|
54 |
213 |
jshamlet |
-- Seth Henry 04/10/20 Overhauled the register interface of the timer to
|
55 |
|
|
-- make the interface more sensible to software.
|
56 |
224 |
jshamlet |
-- Seth Henry 04/160/20 Modified to make use of Open8 bus record
|
57 |
244 |
jshamlet |
-- Seth Henry 05/18/20 Added write qualification input
|
58 |
212 |
jshamlet |
|
59 |
|
|
library ieee;
|
60 |
|
|
use ieee.std_logic_1164.all;
|
61 |
|
|
use ieee.std_logic_unsigned.all;
|
62 |
|
|
use ieee.std_logic_arith.all;
|
63 |
|
|
use ieee.std_logic_misc.all;
|
64 |
|
|
|
65 |
|
|
library work;
|
66 |
|
|
use work.open8_pkg.all;
|
67 |
|
|
|
68 |
|
|
entity o8_epoch_timer is
|
69 |
|
|
generic(
|
70 |
217 |
jshamlet |
Address : ADDRESS_TYPE
|
71 |
212 |
jshamlet |
);
|
72 |
|
|
port(
|
73 |
223 |
jshamlet |
Open8_Bus : in OPEN8_BUS_TYPE;
|
74 |
244 |
jshamlet |
Write_Qual : in std_logic := '1';
|
75 |
217 |
jshamlet |
Rd_Data : out DATA_TYPE;
|
76 |
|
|
Interrupt : out std_logic
|
77 |
212 |
jshamlet |
);
|
78 |
|
|
end entity;
|
79 |
|
|
|
80 |
|
|
architecture behave of o8_epoch_timer is
|
81 |
|
|
|
82 |
224 |
jshamlet |
alias Clock is Open8_Bus.Clock;
|
83 |
|
|
alias Reset is Open8_Bus.Reset;
|
84 |
|
|
alias uSec_Tick is Open8_Bus.uSec_Tick;
|
85 |
|
|
|
86 |
212 |
jshamlet |
constant User_Addr : std_logic_vector(15 downto 3)
|
87 |
|
|
:= Address(15 downto 3);
|
88 |
222 |
jshamlet |
|
89 |
223 |
jshamlet |
alias Comp_Addr is Open8_Bus.Address(15 downto 3);
|
90 |
212 |
jshamlet |
signal Addr_Match : std_logic := '0';
|
91 |
|
|
|
92 |
244 |
jshamlet |
alias Reg_Sel_d is Open8_Bus.Address(2 downto 0);
|
93 |
|
|
signal Reg_Sel_q : std_logic_vector(2 downto 0) := "000";
|
94 |
|
|
signal Wr_En_d : std_logic := '0';
|
95 |
|
|
signal Wr_En_q : std_logic := '0';
|
96 |
|
|
alias Wr_Data_d is Open8_Bus.Wr_Data;
|
97 |
212 |
jshamlet |
signal Wr_Data_q : DATA_TYPE := x"00";
|
98 |
244 |
jshamlet |
signal Rd_En_d : std_logic := '0';
|
99 |
|
|
signal Rd_En_q : std_logic := '0';
|
100 |
212 |
jshamlet |
|
101 |
222 |
jshamlet |
signal setpt_buffer : std_logic_vector(23 downto 0) :=
|
102 |
|
|
(others => '0');
|
103 |
|
|
|
104 |
|
|
alias setpt_buffer_b0 is setpt_buffer(7 downto 0);
|
105 |
|
|
alias setpt_buffer_b1 is setpt_buffer(15 downto 8);
|
106 |
|
|
alias setpt_buffer_b2 is setpt_buffer(23 downto 16);
|
107 |
|
|
|
108 |
|
|
signal buffer_pending : std_logic := '0';
|
109 |
|
|
signal buffer_update : std_logic := '0';
|
110 |
|
|
|
111 |
|
|
signal epoch_buffer : std_logic_vector(23 downto 0) :=
|
112 |
|
|
(others => '0');
|
113 |
212 |
jshamlet |
alias epoch_buffer_b0 is epoch_buffer(7 downto 0);
|
114 |
|
|
alias epoch_buffer_b1 is epoch_buffer(15 downto 8);
|
115 |
|
|
alias epoch_buffer_b2 is epoch_buffer(23 downto 16);
|
116 |
222 |
jshamlet |
|
117 |
|
|
signal capture_epoch : std_logic;
|
118 |
212 |
jshamlet |
signal timer_clear : std_logic := '0';
|
119 |
|
|
|
120 |
222 |
jshamlet |
signal epoch_tmr : std_logic_vector(25 downto 0) :=
|
121 |
|
|
(others => '0');
|
122 |
|
|
|
123 |
|
|
alias epoch_tmrcmp is epoch_tmr(25 downto 2);
|
124 |
|
|
|
125 |
|
|
signal epoch_setpt : std_logic_vector(25 downto 0) :=
|
126 |
|
|
(others => '0');
|
127 |
|
|
|
128 |
|
|
alias epoch_setpt_b0 is epoch_setpt(7 downto 0);
|
129 |
|
|
alias epoch_setpt_b1 is epoch_setpt(15 downto 8);
|
130 |
|
|
alias epoch_setpt_b2 is epoch_setpt(23 downto 16);
|
131 |
212 |
jshamlet |
alias epoch_setpt_u is epoch_setpt(25 downto 2);
|
132 |
|
|
alias epoch_setpt_l is epoch_setpt(1 downto 0);
|
133 |
222 |
jshamlet |
|
134 |
212 |
jshamlet |
signal epoch_alarm : std_logic := '0';
|
135 |
|
|
signal epoch_alarm_q : std_logic := '0';
|
136 |
|
|
|
137 |
|
|
begin
|
138 |
|
|
|
139 |
|
|
Addr_Match <= '1' when Comp_Addr = User_Addr else '0';
|
140 |
244 |
jshamlet |
Wr_En_d <= Addr_Match and Open8_Bus.Wr_En and Write_Qual;
|
141 |
|
|
Rd_En_d <= Addr_Match and Open8_Bus.Rd_En;
|
142 |
212 |
jshamlet |
|
143 |
|
|
io_reg: process( Clock, Reset )
|
144 |
|
|
begin
|
145 |
|
|
if( Reset = Reset_Level )then
|
146 |
244 |
jshamlet |
Reg_Sel_q <= "000";
|
147 |
|
|
Wr_En_q <= '0';
|
148 |
|
|
Wr_Data_q <= x"00";
|
149 |
|
|
Rd_En_q <= '0';
|
150 |
212 |
jshamlet |
Rd_Data <= OPEN8_NULLBUS;
|
151 |
244 |
jshamlet |
|
152 |
212 |
jshamlet |
setpt_buffer <= (others => '0');
|
153 |
|
|
buffer_pending <= '0';
|
154 |
|
|
buffer_update <= '0';
|
155 |
222 |
jshamlet |
capture_epoch <= '0';
|
156 |
212 |
jshamlet |
timer_clear <= '0';
|
157 |
|
|
elsif( rising_edge( Clock ) )then
|
158 |
244 |
jshamlet |
Reg_Sel_q <= Reg_Sel_d;
|
159 |
212 |
jshamlet |
|
160 |
244 |
jshamlet |
Wr_En_q <= Wr_En_d;
|
161 |
|
|
Wr_Data_q <= Wr_Data_d;
|
162 |
212 |
jshamlet |
|
163 |
|
|
buffer_update <= '0';
|
164 |
222 |
jshamlet |
capture_epoch <= '0';
|
165 |
212 |
jshamlet |
timer_clear <= '0';
|
166 |
222 |
jshamlet |
|
167 |
244 |
jshamlet |
if( Wr_En_q = '1' )then
|
168 |
|
|
case( Reg_Sel_q )is
|
169 |
212 |
jshamlet |
when "000" =>
|
170 |
|
|
setpt_buffer_b0 <= Wr_Data_q;
|
171 |
222 |
jshamlet |
buffer_pending <= '1';
|
172 |
212 |
jshamlet |
|
173 |
|
|
when "001" =>
|
174 |
|
|
setpt_buffer_b1 <= Wr_Data_q;
|
175 |
222 |
jshamlet |
buffer_pending <= '1';
|
176 |
212 |
jshamlet |
|
177 |
|
|
when "010" =>
|
178 |
|
|
setpt_buffer_b2 <= Wr_Data_q;
|
179 |
222 |
jshamlet |
buffer_pending <= '1';
|
180 |
212 |
jshamlet |
|
181 |
222 |
jshamlet |
when "011" =>
|
182 |
|
|
buffer_update <= '1';
|
183 |
|
|
buffer_pending <= '0';
|
184 |
|
|
|
185 |
|
|
when "100" | "101" | "110" =>
|
186 |
|
|
capture_epoch <= '1';
|
187 |
|
|
|
188 |
212 |
jshamlet |
when "111" =>
|
189 |
|
|
timer_clear <= '1';
|
190 |
|
|
when others => null;
|
191 |
|
|
end case;
|
192 |
|
|
end if;
|
193 |
|
|
|
194 |
244 |
jshamlet |
Rd_En_q <= Rd_En_d;
|
195 |
212 |
jshamlet |
Rd_Data <= OPEN8_NULLBUS;
|
196 |
244 |
jshamlet |
if( Rd_En_q = '1' )then
|
197 |
|
|
case( Reg_Sel_q )is
|
198 |
212 |
jshamlet |
when "000" =>
|
199 |
|
|
Rd_Data <= epoch_setpt_b0;
|
200 |
|
|
when "001" =>
|
201 |
|
|
Rd_Data <= epoch_setpt_b1;
|
202 |
|
|
when "010" =>
|
203 |
|
|
Rd_Data <= epoch_setpt_b2;
|
204 |
|
|
when "011" =>
|
205 |
|
|
Rd_Data <= epoch_alarm & buffer_pending & "000000";
|
206 |
222 |
jshamlet |
when "100" =>
|
207 |
|
|
Rd_Data <= epoch_buffer_b0(7 downto 0);
|
208 |
|
|
when "101" =>
|
209 |
|
|
Rd_Data <= epoch_buffer_b1(15 downto 8);
|
210 |
|
|
when "110" =>
|
211 |
|
|
Rd_Data <= epoch_buffer_b2(23 downto 16);
|
212 |
212 |
jshamlet |
when others => null;
|
213 |
|
|
end case;
|
214 |
|
|
end if;
|
215 |
|
|
end if;
|
216 |
|
|
end process;
|
217 |
|
|
|
218 |
|
|
timer_proc: process( Clock, Reset )
|
219 |
|
|
begin
|
220 |
|
|
if( Reset = Reset_Level )then
|
221 |
|
|
epoch_setpt <= (others => '0');
|
222 |
222 |
jshamlet |
epoch_buffer <= (others => '0');
|
223 |
212 |
jshamlet |
epoch_tmr <= (others => '0');
|
224 |
|
|
epoch_alarm <= '0';
|
225 |
|
|
epoch_alarm_q <= '0';
|
226 |
|
|
Interrupt <= '0';
|
227 |
|
|
|
228 |
|
|
elsif( rising_edge(Clock) )then
|
229 |
|
|
|
230 |
|
|
epoch_tmr <= epoch_tmr + uSec_Tick;
|
231 |
|
|
|
232 |
222 |
jshamlet |
if( epoch_tmr > epoch_setpt )then
|
233 |
|
|
epoch_alarm <= or_reduce(epoch_setpt);
|
234 |
212 |
jshamlet |
end if;
|
235 |
|
|
|
236 |
|
|
if( buffer_update = '1' )then
|
237 |
|
|
epoch_setpt_u <= setpt_buffer;
|
238 |
|
|
-- Force the lower bits of the setpoint to "11" so that the offset is
|
239 |
222 |
jshamlet |
-- reduced to 1uS (reproducing the original behavior). Software
|
240 |
|
|
-- should always subtract 4uS (-1) from the desired time to compensate
|
241 |
212 |
jshamlet |
epoch_setpt_l <= (others => or_reduce(setpt_buffer));
|
242 |
|
|
epoch_alarm <= '0';
|
243 |
|
|
end if;
|
244 |
|
|
|
245 |
222 |
jshamlet |
if( timer_clear = '1' )then
|
246 |
|
|
epoch_setpt <= (others => '0');
|
247 |
|
|
epoch_tmr <= (others => '0');
|
248 |
|
|
epoch_alarm <= '0';
|
249 |
|
|
end if;
|
250 |
212 |
jshamlet |
|
251 |
|
|
epoch_alarm_q <= epoch_alarm;
|
252 |
|
|
Interrupt <= epoch_alarm and not epoch_alarm_q;
|
253 |
|
|
|
254 |
222 |
jshamlet |
if( capture_epoch = '1' )then
|
255 |
|
|
epoch_buffer <= epoch_tmrcmp;
|
256 |
|
|
end if;
|
257 |
|
|
|
258 |
212 |
jshamlet |
end if;
|
259 |
|
|
end process;
|
260 |
|
|
|
261 |
|
|
end architecture;
|